mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Updated Organisations DAO
This commit is contained in:
@@ -14,3 +14,8 @@ def dao_get_organisation_by_id(org_id):
|
|||||||
@transactional
|
@transactional
|
||||||
def dao_create_organisation(organisation):
|
def dao_create_organisation(organisation):
|
||||||
db.session.add(organisation)
|
db.session.add(organisation)
|
||||||
|
|
||||||
|
|
||||||
|
@transactional
|
||||||
|
def dao_update_organisation(organisation):
|
||||||
|
db.session.add(organisation)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ from app.dao.invited_user_dao import save_invited_user
|
|||||||
from app.dao.provider_rates_dao import create_provider_rates
|
from app.dao.provider_rates_dao import create_provider_rates
|
||||||
from app.clients.sms.firetext import FiretextClient
|
from app.clients.sms.firetext import FiretextClient
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
from tests.app.db import create_user, create_template, create_notification
|
from tests.app.db import create_user, create_template, create_notification, create_organisation
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
@@ -974,6 +974,10 @@ def sample_provider_rate(notify_db, notify_db_session, valid_from=None, rate=Non
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def sample_organisation(notify_db, notify_db_session):
|
||||||
|
create_organisation()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def restore_provider_details(notify_db, notify_db_session):
|
def restore_provider_details(notify_db, notify_db_session):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from app.dao.organisations_dao import dao_create_organisation
|
from app.dao.organisations_dao import (
|
||||||
|
dao_create_organisation, dao_get_organisations, dao_get_organisation_by_id, dao_update_organisation
|
||||||
|
)
|
||||||
from app.models import Organisation
|
from app.models import Organisation
|
||||||
|
|
||||||
from tests.app.db import create_organisation
|
from tests.app.db import create_organisation
|
||||||
@@ -12,3 +14,35 @@ def test_create_organisation(notify_db, notify_db_session):
|
|||||||
assert Organisation.query.count() == 1
|
assert Organisation.query.count() == 1
|
||||||
organisation_from_db = Organisation.query.first()
|
organisation_from_db = Organisation.query.first()
|
||||||
assert organisation == organisation_from_db
|
assert organisation == organisation_from_db
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_organisations_gets_all_organisations(notify_db, notify_db_session):
|
||||||
|
create_organisation(name='test_org_1')
|
||||||
|
create_organisation(name='test_org_2')
|
||||||
|
|
||||||
|
organisations = dao_get_organisations()
|
||||||
|
|
||||||
|
assert len(organisations) == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_organisation_by_id_gets_correct_organisation(notify_db, notify_db_session):
|
||||||
|
organisation = create_organisation()
|
||||||
|
|
||||||
|
organisation_from_db = dao_get_organisation_by_id(organisation.id)
|
||||||
|
|
||||||
|
assert organisation_from_db == organisation
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_organisation(notify_db, notify_db_session):
|
||||||
|
updated_name = 'new name'
|
||||||
|
organisation = create_organisation()
|
||||||
|
|
||||||
|
organisation_from_db = Organisation.query.first()
|
||||||
|
assert organisation.name != updated_name
|
||||||
|
|
||||||
|
organisation.name = updated_name
|
||||||
|
|
||||||
|
dao_update_organisation(organisation)
|
||||||
|
organisation_from_db = Organisation.query.first()
|
||||||
|
|
||||||
|
assert organisation_from_db.name == updated_name
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ def create_service_inbound_api(
|
|||||||
return service_inbound_api
|
return service_inbound_api
|
||||||
|
|
||||||
|
|
||||||
def create_organisation(colour='blue', logo='test_x2.png', name='test_logo'):
|
def create_organisation(colour='blue', logo='test_x2.png', name='test_org_1'):
|
||||||
data = {
|
data = {
|
||||||
'colour': colour,
|
'colour': colour,
|
||||||
'logo': logo,
|
'logo': logo,
|
||||||
|
|||||||
@@ -37,3 +37,21 @@ def test_get_organisation_by_id(notify_api, notify_db, notify_db_session):
|
|||||||
assert organisation['logo'] == '/path/image.png'
|
assert organisation['logo'] == '/path/image.png'
|
||||||
assert organisation['name'] == 'My Org'
|
assert organisation['name'] == 'My Org'
|
||||||
assert organisation['id'] == str(org.id)
|
assert organisation['id'] == str(org.id)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_organisation(client, notify_db, notify_db_session):
|
||||||
|
data = {
|
||||||
|
'name': 'test organisation',
|
||||||
|
'colour': '#0000ff',
|
||||||
|
'logo': '/images/test_x2.png'
|
||||||
|
}
|
||||||
|
auth_header = create_authorization_header()
|
||||||
|
|
||||||
|
response = client.post(
|
||||||
|
'/organisation',
|
||||||
|
headers=[('Content-Type', 'application/json'), auth_header],
|
||||||
|
data=json.dumps(data)
|
||||||
|
)
|
||||||
|
assert response.status_code == 201
|
||||||
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
|
assert data['name'] == json_resp['data']['name']
|
||||||
|
|||||||
Reference in New Issue
Block a user