def test__GgoQuery__get_total_amount__has_no_results__returns_zero( seeded_session): query = GgoQuery(seeded_session) \ .has_address('AN-ADDRESS-THAT-DOESNT-EXISTS') assert query.count() == 0 assert query.get_total_amount() == 0
def test__GgoQuery__get_distinct_begins__has_no_results__returns_empty_list( seeded_session): query = GgoQuery(seeded_session) \ .has_address('AN-ADDRESS-THAT-DOESNT-EXISTS') assert query.count() == 0 assert query.get_distinct_begins() == []
def test__GgoQuery__has_address__Ggo_does_not_exist__returs_nothing( seeded_session, ggo_address): query = GgoQuery(seeded_session) \ .has_address(ggo_address) assert query.count() == 0 assert query.one_or_none() is None
def test__GgoQuery__is_locked__returns_correct_ggos(seeded_session, ggo_locked): query = GgoQuery(seeded_session) \ .is_locked(ggo_locked) assert query.count() > 0 assert all(ggo.locked == ggo_locked for ggo in query.all())
def test__GgoQuery__has_address__Ggo_exists__returns_correct_Ggo( seeded_session, ggo_address): query = GgoQuery(seeded_session) \ .has_address(ggo_address) assert query.count() == 1 assert query.one().address == ggo_address
def test__GgoQuery__has_id__Ggo_exists__returns_correct_Ggo( seeded_session, ggo_id): query = GgoQuery(seeded_session) \ .has_id(ggo_id) assert query.count() == 1 assert query.one().id == ggo_id
def test__GgoQuery__is_NOT_retired__returns_correct_ggos(seeded_session): query = GgoQuery(seeded_session) \ .is_retired(False) assert query.count() > 0 assert all(ggo.retired is False for ggo in query.all()) assert all(ggo.retire_gsrn is None for ggo in query.all()) assert all(ggo.retire_address is None for ggo in query.all())
def test__GgoQuery__is_retired_to_gsrn__returns_correct_ggos( seeded_session, ggo_retire_gsrn): query = GgoQuery(seeded_session) \ .is_retired_to_gsrn(ggo_retire_gsrn) assert query.count() > 0 assert all(ggo.retired is True for ggo in query.all()) assert all(ggo.retire_address is not None for ggo in query.all()) assert all(ggo.retire_gsrn == ggo_retire_gsrn for ggo in query.all())
def test__GgoQuery__is_tradable__returns_correct_ggos(seeded_session): query = GgoQuery(seeded_session) \ .is_tradable() assert query.count() > 0 assert all(ggo.stored is True for ggo in query.all()) # assert all(ggo.expired is False for ggo in query.all()) assert all(ggo.retired is False for ggo in query.all()) assert all(ggo.synchronized is True for ggo in query.all()) assert all(ggo.locked is False for ggo in query.all())
def test__GgoImportController__integration(datahub_service, seeded_session): def __get_ggo_list(access_token, request): datahub_response_schema = md.class_schema(GetGgoListResponse) datahub_response = datahub_response_schema() return datahub_response.loads(IMPORT_GGO_DATA1) # Arrange datahub_service.get_ggo_list.side_effect = __get_ggo_list begin_from = datetime(2020, 9, 1, 0, 0, tzinfo=timezone.utc) begin_to = datetime(2020, 9, 30, 23, 0, tzinfo=timezone.utc) uut = GgoImportController() # Act uut.import_ggos(user, '571313180400240049', begin_from, begin_to, seeded_session) seeded_session.commit() # Assert query = GgoQuery(seeded_session).belongs_to(user) begins = query.get_distinct_begins() assert query.count() == 720 assert min(begins).astimezone(timezone.utc) == datetime( 2019, 9, 1, 0, 0, tzinfo=timezone.utc) assert max(begins).astimezone(timezone.utc) == datetime( 2019, 9, 30, 23, 0, tzinfo=timezone.utc) # Second time should not do anything uut.import_ggos(user, '571313180400240049', begin_from, begin_to, seeded_session) seeded_session.commit() # Assert query = GgoQuery(seeded_session).belongs_to(user) begins = query.get_distinct_begins() assert query.count() == 720 assert min(begins).astimezone(timezone.utc) == datetime( 2019, 9, 1, 0, 0, tzinfo=timezone.utc) assert max(begins).astimezone(timezone.utc) == datetime( 2019, 9, 30, 23, 0, tzinfo=timezone.utc)
def test__GgoQuery__get_total_amount__has_results__returns_correct_amount( seeded_session): query = GgoQuery(seeded_session) assert query.count() > 0 assert query.get_total_amount() == query.count() * GGO_AMOUNT
def test__GgoQuery__begins_at__Ggo_does_not_exist__returs_nothing( seeded_session, ggo_begin): query = GgoQuery(seeded_session) \ .begins_at(ggo_begin) assert query.count() == 0
def test__GgoQuery__begins_at__returns_correct_ggos(seeded_session, ggo_begin): query = GgoQuery(seeded_session) \ .begins_at(ggo_begin) assert query.count() > 0 assert all(ggo.begin == ggo_begin for ggo in query.all())
def test__GgoQuery__belongs_to__returns_correct_ggos(seeded_session): query = GgoQuery(seeded_session) \ .belongs_to(user1) assert query.count() > 0 assert all(ggo.user_id == 1 for ggo in query.all())
def test__Ggo__technology__Technology_does_not_exist__returns_None( seeded_session): query = GgoQuery(seeded_session).has_id(3) assert query.count() == 1 assert query.one().technology is None
def test__Ggo__technology__Technology_exists__returns_correct_Technology( seeded_session, ggo_id, technology): query = GgoQuery(seeded_session).has_id(ggo_id) assert query.count() == 1 assert query.one().technology.technology == technology