Verified Commit 7253d645 authored by Jakob Sinclair's avatar Jakob Sinclair
Browse files

feat: add first unittests

Signed-off-by: Jakob Sinclair's avatarJakob Sinclair <>
parent bdcd28af
Pipeline #232660848 failed with stage
in 22 seconds
......@@ -45,6 +45,14 @@ By default MemberPort should be available on ``.
The Tornado server will restart automatically with debug mode on when a change to a source file is detected.
### Unit tests
You can run tests with this command:
python -m app.test.runtests
## Contribution
This section will describe how to contribute to this project.
......@@ -41,12 +41,11 @@ class Organization:
def organization_to_json(organization: Organization) -> dict:
return {
'organization': {
'description': organization.description,
'created': organization.created.isoformat(' ')
'description': organization.description,
'created': organization.created.isoformat(' ')
......@@ -99,7 +98,7 @@ class Municipality:
name: str
created: datetime
country: Country
area_id: Area
area_id: UUID
def municipality_to_json(municipality: Municipality) -> dict:
......@@ -108,5 +107,5 @@ def municipality_to_json(municipality: Municipality) -> dict:
'created': municipality.created.isoformat(' '),
'area_id': municipality.area_id
'area_id': municipality.area_id.__str__()
from tornado.testing import gen_test
from asyncpg import Connection
from unittest.mock import MagicMock
from app.database.dao.organizations import OrganizationsDao
from app.test.web_testcase import WebTestCase
class OrganizationsTest(WebTestCase):
def test_create_organization(self):
# dao = OrganizationsDao(self.db)
con = Connection()
con.execute = MagicMock(return_value=3)
con.execute.assert_called_with("TEST", 3, 4, 5, 6)
response = self.fetch('/api/scan/1', method="POST", body="{}")
body = response.body.decode()
self.assertEqual('{"success": false, "reason": "CODE UUID IS MISSING", "data": null}', body)
self.assertEqual(400, response.code)
from app.models import Country, Organization, Municipality, organization_to_json, municipality_to_json
from datetime import datetime
from unittest import TestCase
from uuid import uuid4
class ModelsTest(TestCase):
def test_organization_model(self):
id = uuid4()
created = datetime.utcnow()
org = Organization() = id = "Piratpartiet"
org.description = "Omtänksamhet istället för misstänksamhet" = True
org.created = created
json = organization_to_json(org)
self.assertEqual(id.__str__(), json["id"])
self.assertEqual(, json["name"])
self.assertEqual(org.description, json["description"])
self.assertEqual("true", json["active"])
self.assertEqual(created.isoformat(' '), json["created"])
def test_municipality_model(self):
id = uuid4()
created = datetime.utcnow()
area_id = uuid4()
sweden = Country() = "Sverige"
mun = Municipality() = id = "Lund"
mun.created = created = sweden
mun.area_id = area_id
json = municipality_to_json(mun)
self.assertEqual(id.__str__(), json["id"])
self.assertEqual(, json["name"])
self.assertEqual(created.isoformat(' '), json["created"])
self.assertEqual(, json["country"])
self.assertEqual(area_id.__str__(), json["area_id"])
#!/usr/bin/env python
from unittest import defaultTestLoader
from os import path
from tornado import testing
def all():
suite ='./app/test', 'test_*.py', path.dirname(path.abspath(__file__)))
return suite
if __name__ == '__main__':
from tornado.testing import AsyncHTTPTestCase
from app.web.web_server import WebAppOptions, configure_application
class WebTestCase(AsyncHTTPTestCase):
def get_app(self):
options = WebAppOptions()
options.debug = True
options.xsrf = False
options.cookie_secret = "ccd70ecea6d9f0833b07688e69bf2368f86f9127de17de102e17788a805afb7f"
options.db_username = "super"
options.db_password = "super"
options.db_hostname = "postgres-db"
options.dbname = "memberportdb"
return configure_application(options)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment