mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Added dao, test framework and tests for dao.
This commit is contained in:
0
tests/app/main/__init__.py
Normal file
0
tests/app/main/__init__.py
Normal file
@@ -1,8 +1,38 @@
|
||||
from app.main.dao.services_dao import (create_service, get_services)
|
||||
from tests.app.conftest import sample_service as create_sample_service
|
||||
from app.models import Service
|
||||
|
||||
|
||||
def test_create_service(notify_api):
|
||||
pass
|
||||
def test_create_service(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert Service.query.count() == 0
|
||||
service_name = 'Sample Service'
|
||||
service_id = create_service(service_name, sample_user)
|
||||
assert Service.query.count() == 1
|
||||
assert Service.query.first().name == service_name
|
||||
assert Service.query.first().id == service_id
|
||||
|
||||
|
||||
def test_get_all_services(notify_api):
|
||||
pass
|
||||
def test_get_services(notify_api, notify_db, notify_db_session, sample_user):
|
||||
sample_service = create_sample_service(notify_db,
|
||||
notify_db_session,
|
||||
user=sample_user)
|
||||
assert Service.query.count() == 1
|
||||
assert len(get_services()) == 1
|
||||
service_name = "Another service"
|
||||
sample_service = create_sample_service(notify_db,
|
||||
notify_db_session,
|
||||
service_name=service_name,
|
||||
user=sample_user)
|
||||
assert Service.query.count() == 2
|
||||
assert len(get_services()) == 2
|
||||
|
||||
|
||||
def test_get_user_service(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert Service.query.count() == 0
|
||||
service_name = "Random service"
|
||||
sample_service = create_sample_service(notify_db,
|
||||
notify_db_session,
|
||||
service_name=service_name,
|
||||
user=sample_user)
|
||||
assert get_services(service_id=sample_service.id).name == service_name
|
||||
assert Service.query.count() == 1
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from app.main.dao.users_dao import (create_user, get_users)
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from app.models import User
|
||||
|
||||
|
||||
def test_create_user(notify_api, notify_db, notify_db_session):
|
||||
email = 'notify@digital.cabinet-office.gov.uk'
|
||||
user_id = create_user(email)
|
||||
assert User.query.count() == 1
|
||||
assert User.query.first().email_address == email
|
||||
assert User.query.filter_by(id=user_id).one()
|
||||
|
||||
|
||||
def test_get_all_users(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
assert len(get_users()) == 1
|
||||
email = "another.notify@digital.cabinet-office.gov.uk"
|
||||
another_user = create_sample_user(notify_db,
|
||||
notify_db_session,
|
||||
email=email)
|
||||
assert User.query.count() == 2
|
||||
assert len(get_users()) == 2
|
||||
|
||||
|
||||
def test_get_user(notify_api, notify_db, notify_db_session):
|
||||
email = "another.notify@digital.cabinet-office.gov.uk"
|
||||
another_user = create_sample_user(notify_db,
|
||||
notify_db_session,
|
||||
email=email)
|
||||
assert get_users(user_id=another_user.id).email_address == email
|
||||
|
||||
Reference in New Issue
Block a user