clean up dao_fetch_live_services

a bit of DRY - use the column definitions to determine what goes into
the dict, and use a `next` iterator rather than a while loop to find
the existing service row. Take advantage of dict mutability to avoid
needing to refer to the list by index.

Also change the tests so if there's an error, the diff is slightly
more readable. But not much
This commit is contained in:
Leo Hemsted
2019-05-30 17:41:25 +01:00
parent 208abfc722
commit 968d94d350
3 changed files with 68 additions and 60 deletions

View File

@@ -1,5 +1,6 @@
import uuid
from datetime import datetime
from unittest import mock
import pytest
from freezegun import freeze_time
@@ -386,11 +387,11 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user(
@freeze_time('2019-04-23T10:00:00')
def test_dao_fetch_live_services_data(sample_user, mock):
def test_dao_fetch_live_services_data(sample_user):
org = create_organisation(organisation_type='crown')
service = create_service(go_live_user=sample_user, go_live_at='2014-04-20T10:00:00')
template = create_template(service=service)
service_2 = create_service(service_name='second', go_live_user=sample_user, go_live_at='2017-04-20T10:00:00')
service_2 = create_service(service_name='second', go_live_at='2017-04-20T10:00:00', go_live_user=sample_user)
create_service(service_name='third', go_live_at='2016-04-20T10:00:00')
# below services should be filtered out:
create_service(service_name='restricted', restricted=True)