From d7448eb22599c1fa788bf0dd211209301b94174e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Mon, 18 Dec 2017 23:17:20 +0100
Subject: [PATCH] Fix tests.

---
 openlobby/core/tests.py                           |  3 ---
 .../core/tests}/__init__.py                       |  0
 {tests => openlobby/core/tests}/conftest.py       |  2 +-
 openlobby/core/tests/snapshots/__init__.py        |  0
 .../core/tests}/snapshots/snap_test_management.py |  0
 {tests => openlobby/core/tests}/test_auth.py      | 15 +++++----------
 {tests => openlobby/core/tests}/test_documents.py |  2 +-
 .../core/tests}/test_management.py                |  4 ++--
 {tests => openlobby/core/tests}/test_paginator.py |  2 +-
 .../core/tests}/test_sanitizers.py                |  2 +-
 pytest.ini                                        |  2 ++
 requirements.txt                                  |  2 +-
 12 files changed, 14 insertions(+), 20 deletions(-)
 delete mode 100644 openlobby/core/tests.py
 rename {tests/snapshots => openlobby/core/tests}/__init__.py (100%)
 rename {tests => openlobby/core/tests}/conftest.py (93%)
 create mode 100644 openlobby/core/tests/snapshots/__init__.py
 rename {tests => openlobby/core/tests}/snapshots/snap_test_management.py (100%)
 rename {tests => openlobby/core/tests}/test_auth.py (77%)
 rename {tests => openlobby/core/tests}/test_documents.py (96%)
 rename {tests => openlobby/core/tests}/test_management.py (97%)
 rename {tests => openlobby/core/tests}/test_paginator.py (97%)
 rename {tests => openlobby/core/tests}/test_sanitizers.py (92%)

diff --git a/openlobby/core/tests.py b/openlobby/core/tests.py
deleted file mode 100644
index 7ce503c..0000000
--- a/openlobby/core/tests.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from django.test import TestCase
-
-# Create your tests here.
diff --git a/tests/snapshots/__init__.py b/openlobby/core/tests/__init__.py
similarity index 100%
rename from tests/snapshots/__init__.py
rename to openlobby/core/tests/__init__.py
diff --git a/tests/conftest.py b/openlobby/core/tests/conftest.py
similarity index 93%
rename from tests/conftest.py
rename to openlobby/core/tests/conftest.py
index 111f1cf..1eec378 100644
--- a/tests/conftest.py
+++ b/openlobby/core/tests/conftest.py
@@ -5,7 +5,7 @@ import random
 import string
 
 
-from openlobby.management import init_alias
+from ..management import init_alias
 
 
 @pytest.fixture(scope='session')
diff --git a/openlobby/core/tests/snapshots/__init__.py b/openlobby/core/tests/snapshots/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/snapshots/snap_test_management.py b/openlobby/core/tests/snapshots/snap_test_management.py
similarity index 100%
rename from tests/snapshots/snap_test_management.py
rename to openlobby/core/tests/snapshots/snap_test_management.py
diff --git a/tests/test_auth.py b/openlobby/core/tests/test_auth.py
similarity index 77%
rename from tests/test_auth.py
rename to openlobby/core/tests/test_auth.py
index 51d1e97..0659a66 100644
--- a/tests/test_auth.py
+++ b/openlobby/core/tests/test_auth.py
@@ -1,14 +1,9 @@
+from django.conf import settings
 import time
 import jwt
 import pytest
 
-from openlobby.settings import (
-    SECRET_KEY,
-    JWT_ALGORITHM,
-    LOGIN_ATTEMPT_EXPIRATION,
-    SESSION_EXPIRATION,
-)
-from openlobby.auth import (
+from ..auth import (
     get_login_attempt_expiration_time,
     get_session_expiration_time,
     create_access_token,
@@ -18,13 +13,13 @@ from openlobby.auth import (
 
 def test_get_login_attempt_expiration_time():
     expiration = get_login_attempt_expiration_time()
-    expected = int(time.time() + LOGIN_ATTEMPT_EXPIRATION)
+    expected = int(time.time() + settings.LOGIN_ATTEMPT_EXPIRATION)
     assert expected <= expiration <= expected + 1
 
 
 def test_get_session_expiration_time():
     expiration = get_session_expiration_time()
-    expected = int(time.time() + SESSION_EXPIRATION)
+    expected = int(time.time() + settings.SESSION_EXPIRATION)
     assert expected <= expiration <= expected + 1
 
 
@@ -32,7 +27,7 @@ def test_create_access_token():
     session_id = 'idkfa'
     expiration = int(time.time() + 10)
     token = create_access_token(session_id, expiration)
-    payload = jwt.decode(token, SECRET_KEY, algorithms=[JWT_ALGORITHM])
+    payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.JWT_ALGORITHM])
     assert isinstance(token, str)
     assert payload['sub'] == session_id
     assert payload['exp'] == expiration
diff --git a/tests/test_documents.py b/openlobby/core/tests/test_documents.py
similarity index 96%
rename from tests/test_documents.py
rename to openlobby/core/tests/test_documents.py
index 630dd93..ff823d8 100644
--- a/tests/test_documents.py
+++ b/openlobby/core/tests/test_documents.py
@@ -1,6 +1,6 @@
 import time
 
-from openlobby.documents import SessionDoc, UserDoc
+from ..documents import SessionDoc, UserDoc
 
 
 class TestSessionDoc:
diff --git a/tests/test_management.py b/openlobby/core/tests/test_management.py
similarity index 97%
rename from tests/test_management.py
rename to openlobby/core/tests/test_management.py
index ef1c738..83c87d0 100644
--- a/tests/test_management.py
+++ b/openlobby/core/tests/test_management.py
@@ -1,6 +1,6 @@
 import pytest
 
-from openlobby.management import (
+from ..management import (
     AliasAlreadyExistsError,
     IndexAlreadyExistsError,
     create_index,
@@ -9,7 +9,7 @@ from openlobby.management import (
     init_documents,
     reindex,
 )
-from openlobby.documents import UserDoc
+from ..documents import UserDoc
 
 
 def test_create_index(es, index_name):
diff --git a/tests/test_paginator.py b/openlobby/core/tests/test_paginator.py
similarity index 97%
rename from tests/test_paginator.py
rename to openlobby/core/tests/test_paginator.py
index 590788f..2e3bac7 100644
--- a/tests/test_paginator.py
+++ b/openlobby/core/tests/test_paginator.py
@@ -1,6 +1,6 @@
 import pytest
 
-from openlobby.paginator import PER_PAGE, encode_cursor, decode_cursor, Paginator
+from ..paginator import PER_PAGE, encode_cursor, decode_cursor, Paginator
 
 
 @pytest.mark.parametrize('num, cursor', [
diff --git a/tests/test_sanitizers.py b/openlobby/core/tests/test_sanitizers.py
similarity index 92%
rename from tests/test_sanitizers.py
rename to openlobby/core/tests/test_sanitizers.py
index 7ddf1cb..12061a1 100644
--- a/tests/test_sanitizers.py
+++ b/openlobby/core/tests/test_sanitizers.py
@@ -1,6 +1,6 @@
 import pytest
 
-from openlobby.sanitizers import strip_all_tags, extract_text
+from ..sanitizers import strip_all_tags, extract_text
 
 
 @pytest.mark.parametrize('input, text', [
diff --git a/pytest.ini b/pytest.ini
index e1b7a40..854a7af 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,3 +1,5 @@
 [pytest]
+DJANGO_SETTINGS_MODULE = openlobby.settings
+python_files = tests.py test_*.py *_tests.py
 env =
     SECRET_KEY=justForTests
diff --git a/requirements.txt b/requirements.txt
index e363692..e464b92 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@ Django>=2,<2.1
 graphene>=2.0,<3.0
 graphene-django>=2.0,<3.0
 elasticsearch-dsl>=5.3.0,<6.0.0
-pytest>=3.2.3,<3.3.0
+pytest>=3.3,<4.0
 pytest-django>=3.1.2,<3.2
 pytest-env>=0.6.2,<0.7
 oic>=0.12.0,<0.13
-- 
GitLab