From f39d56e6d05d740f8eb1b2333a3f2bd5a6f6b110 Mon Sep 17 00:00:00 2001 From: Win Date: Sun, 17 Jun 2018 14:31:33 +0000 Subject: [PATCH] More tests --- mqueue/tests/__init__.py | 10 ++++++++-- mqueue/tests/graphql_api.py | 26 ++++++++++++++++++++++++++ mqueue/tests/runtests.py | 7 +++++++ mqueue/tests/watchers.py | 28 ++++++++++++++++++++++++++++ setup.py | 3 ++- tox.ini | 5 +++++ 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 mqueue/tests/graphql_api.py create mode 100644 mqueue/tests/watchers.py diff --git a/mqueue/tests/__init__.py b/mqueue/tests/__init__.py index 87747a4..141fb02 100644 --- a/mqueue/tests/__init__.py +++ b/mqueue/tests/__init__.py @@ -4,6 +4,8 @@ from .apps import MqueueTestApps from .utils import MqueueTestUtils from .hooks.redis import MqueueTestRedisHook +from .watchers import MqueueTestWatchers +#from .graphql_api import MqueueTestGraphqlApi class MqueueTest(MqueueTestAdmin, @@ -11,5 +13,9 @@ class MqueueTest(MqueueTestAdmin, MqueueTestManagers, MqueueTestApps, MqueueTestUtils, - MqueueTestRedisHook): - pass + MqueueTestWatchers, + # MqueueTestGraphqlApi + ): + + def test_mqueue_logging(self): + from mqueue.logging import DEV_LOGGING, LOGGING_WARNING diff --git a/mqueue/tests/graphql_api.py b/mqueue/tests/graphql_api.py new file mode 100644 index 0000000..536f63b --- /dev/null +++ b/mqueue/tests/graphql_api.py @@ -0,0 +1,26 @@ +from django.test import TestCase +from .base import MqueueBaseTest +from graphene.test import Client +from mqueue.schema import schema +from mqueue.models import MEvent + + +client = Client(schema) + + +class MqueueTestGraphqlApi(MqueueBaseTest): + + def test_graphql_query(self): + self.reset() + MEvent.objects.create(name="Test public event", scope="public") + query = '''query publicEvents(first:10) { + edges { + node { + name + event_class + } + } + } + ''' + res = [{"name": "Test public event"}] + self.assertEqual(client.execute(query), res) diff --git a/mqueue/tests/runtests.py b/mqueue/tests/runtests.py index f93b641..eb90260 100644 --- a/mqueue/tests/runtests.py +++ b/mqueue/tests/runtests.py @@ -16,6 +16,9 @@ CUSTOM_INSTALLED_APPS = ( 'mqueue', 'django.contrib.admin', + "graphene_django", + "graphql_utils", + "django_filters", ) ALWAYS_INSTALLED_APPS = ( @@ -75,6 +78,10 @@ }, }, + GRAPHENE={ + 'SCHEMA': 'mqueue.schema.schema' + }, + ) django.setup() diff --git a/mqueue/tests/watchers.py b/mqueue/tests/watchers.py new file mode 100644 index 0000000..564f0e0 --- /dev/null +++ b/mqueue/tests/watchers.py @@ -0,0 +1,28 @@ +from django.test import TestCase +from .base import MqueueBaseTest +from mqueue.models import MEvent +from mqueue.watchers import send_msg, login_action, logout_action, login_failed, init_watchers +from mqueue.conf import WATCH + + +class MqueueTestWatchers(MqueueBaseTest): + + def test_send_msg(self): + instance = self.user + send_msg("test", instance, "Event string") + + def test_login_action(self): + instance = self.user + login_action("test", instance) + + def test_logout_action(self): + instance = self.user + logout_action("test", instance) + + def test_login_failed(self): + instance = self.user + login_failed("test", "user") + + def test_init_watchers_login(self): + with self.settings(MQUEUE_WATCH=["login", "logout", "login_failed"]): + init_watchers("login") diff --git a/setup.py b/setup.py index 68089b0..ce2dffa 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,8 @@ 'django<2', 'redis', 'influxdb', - 'graphene', + 'django-graphql-utils', + "graphene-django<2.0", ], zip_safe=False ) diff --git a/tox.ini b/tox.ini index 5acc19d..b0fa1de 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,11 @@ [base] deps = django-extensions + redis + django-graphql-utils + graphene-django<2.0 + graphene<2.0 + django-filter [testenv:django11] deps =