aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2021-06-07 13:52:20 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2021-06-07 13:52:20 +0530
commit359813517e3382c527125fe673fa89f0fd0742c0 (patch)
tree5010e2427cf0d19e7365e44fac40612375c135c9
parentb752efffe410c9cc9cd53f8c50a5fb9f75069e93 (diff)
added docstrings
-rw-r--r--app/tests/__init__.py4
-rw-r--r--app/tests/conftest.py9
-rw-r--r--app/tests/test_admin.py10
-rw-r--r--app/tests/test_cli.py9
-rw-r--r--app/tests/test_fastapi.py14
-rw-r--r--app/tests/test_forms.py10
-rw-r--r--app/tests/test_models.py7
-rw-r--r--app/tests/test_views.py18
8 files changed, 81 insertions, 0 deletions
diff --git a/app/tests/__init__.py b/app/tests/__init__.py
new file mode 100644
index 0000000..3b0e682
--- /dev/null
+++ b/app/tests/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+"""
+PyTest Modules for Unit Testing
+""" \ No newline at end of file
diff --git a/app/tests/conftest.py b/app/tests/conftest.py
index 71eb677..68af9e5 100644
--- a/app/tests/conftest.py
+++ b/app/tests/conftest.py
@@ -1,3 +1,7 @@
+# -*- coding: utf-8 -*-
+"""
+Configuration with basic fixtures
+"""
import pytest
from app import app as flask_app
@@ -8,6 +12,11 @@ import os
@pytest.fixture
def app():
+ """
+ Special configurations for tests
+
+ We use a dummy database and initialise it.
+ """
flask_app.config["WTF_CSRF_ENABLED"] = False
flask_app.config["SQLALCHEMY_DATABASE_URI"] = (
"sqlite:///" + tempfile.mkstemp(suffix=".db")[-1]
diff --git a/app/tests/test_admin.py b/app/tests/test_admin.py
index ae20f2b..94e8320 100644
--- a/app/tests/test_admin.py
+++ b/app/tests/test_admin.py
@@ -1,7 +1,17 @@
+# -*- coding: utf-8 -*-
+"""
+Test(s) for Admin Portal
+"""
from app import database_cli
def test_admin(app, client):
+ """
+ Test Admin Portal
+
+ We use the cli-runner to run the admin-create command.
+ Then we check if the admin portal is accessible to the newly created superuser.
+ """
runner = app.test_cli_runner()
assert runner.invoke(database_cli, ["admin-create"]).exit_code == 0
diff --git a/app/tests/test_cli.py b/app/tests/test_cli.py
index 194dd64..bbbe53b 100644
--- a/app/tests/test_cli.py
+++ b/app/tests/test_cli.py
@@ -1,7 +1,16 @@
+# -*- coding: utf-8 -*-
+"""
+Test(s) for CLI Commands
+"""
from app import database_cli
def test_database_commands(app, client):
+ """
+ Test for Database CLI Commands
+
+ Test for initialisation, creation and admin user creation.
+ """
runner = app.test_cli_runner()
assert runner.invoke(database_cli, ["delete"]).exit_code == 0
assert runner.invoke(database_cli, ["create"]).exit_code == 0
diff --git a/app/tests/test_fastapi.py b/app/tests/test_fastapi.py
index f8c304e..2b26754 100644
--- a/app/tests/test_fastapi.py
+++ b/app/tests/test_fastapi.py
@@ -1,3 +1,7 @@
+# -*- coding: utf-8 -*-
+"""
+Test(s) for FastAPI Inegration
+"""
from starlette.testclient import TestClient
from api import app as fastapi_app
@@ -6,12 +10,22 @@ fastapi_client = TestClient(fastapi_app)
def test_fastapi(app, client):
+ """
+ Basic Version Test
+
+ Check if endpoint is accessible
+ """
res = fastapi_client.get("/version")
assert res.status_code == 200
assert res.json() == {"message": fastapi_app.version}
def test_fastapi_user_details(app, client):
+ """
+ Basic User Test
+
+ Check if DB is accessible to the FastAPI App
+ """
# TODO Investigate why this is failing
# res = fastapi_client.get("/v1/user-details?email={}".format("admin@example.com"))
# assert res.status_code == 200
diff --git a/app/tests/test_forms.py b/app/tests/test_forms.py
index 1a26635..0f772b3 100644
--- a/app/tests/test_forms.py
+++ b/app/tests/test_forms.py
@@ -1,4 +1,13 @@
+# -*- coding: utf-8 -*-
+"""
+Test(s) for Forms
+
+Tests the forms and their validations
+"""
def test_incorrect_forms(app, client):
+ """
+ Simulate Invalid Forms
+ """
res = client.post("/signin", data={"email": "123"})
assert b"This field is required." in res.data
@@ -10,6 +19,7 @@ def test_incorrect_forms(app, client):
def test_contactus(app, client):
+ """Test Valid Form Submission"""
res = client.post(
"/ContactUs",
data={
diff --git a/app/tests/test_models.py b/app/tests/test_models.py
index 0beb3b9..23c17ad 100644
--- a/app/tests/test_models.py
+++ b/app/tests/test_models.py
@@ -1,7 +1,14 @@
+# -*- coding: utf-8 -*-
+"""
+Test(s) for Database Models
+"""
from app.models import User
def test_usermodel(app, client):
+ """
+ Test User Model
+ """
user = User(first_name="John", email="test@example.com", password="pass")
assert user.full_name == "John None"
assert user.get_role() is None
diff --git a/app/tests/test_views.py b/app/tests/test_views.py
index 811815f..f3df60d 100644
--- a/app/tests/test_views.py
+++ b/app/tests/test_views.py
@@ -1,7 +1,14 @@
+# -*- coding: utf-8 -*-
+"""
+Test(s) for Flask Views
+"""
from itsdangerous.url_safe import URLSafeSerializer
from app import app as flask_app
ts = URLSafeSerializer(flask_app.config["SECRET_KEY"])
+"""
+To create confirmation tokens
+"""
data2check_visitors = {
"/index": {"code": 200, "data": b"Nice Tagline"},
@@ -20,9 +27,15 @@ data2check_visitors = {
"/confirm": {"code": 200, "data": b"Token not provided in URL Parameter"},
"/confirm?confirmation_token=123": {"code": 200, "data": b"Bad Token Provided"},
}
+"""
+Dictionary of Path, Expected Status Code and Data to Test for Visitors
+"""
def test_visitors(app, client):
+ """
+ Test if Vistors get expected endpoints and status codes
+ """
for page in data2check_visitors:
res = client.get(page)
print("Testing %s", page)
@@ -31,6 +44,11 @@ def test_visitors(app, client):
def test_user_auth_flow(app, client):
+ """
+ Test User Authentication Flow
+
+ Tests Registeration, Email-Confirmation and Log-in along with appropriate redirects.
+ """
res = client.post(
"/signup",
data=dict(