def should_generate_the_next_action_closing_the_visit(): test_pages = generators_for_tests.generate_pages_map() visit = Visit(visit_duration_seconds=120, app_version='v1', data_anomaly=DataAnomaly.INCONSISTENT_DATA, timer=Timer(-900), keep_private=False) json.loads(visit.generate_new_action(test_pages, 130)) assert_that(visit.is_to_close).is_true()
def should_generate_invalid_log(): test_pages = generators_for_tests.generate_pages_map() visit = Visit(visit_duration_seconds=120, app_version='v1', data_anomaly=DataAnomaly.MISSING, timer=Timer(-900), keep_private=False) invalid_visit_log = json.loads( visit.generate_new_action(test_pages, 30, False)) assert_that(invalid_visit_log['visit_id']).is_none()
def should_generate_2_different_events_for_the_same_visit_without_anomaly(): test_pages = generators_for_tests.generate_pages_map() visit = Visit(visit_duration_seconds=120, app_version='v1', data_anomaly=DataAnomaly.MISSING, timer=Timer(-900), keep_private=False) action_1 = json.loads(visit.generate_new_action(test_pages, 30)) action_2 = json.loads(visit.generate_new_action(test_pages, 10)) assertions_for_test.assert_visits_consistency(action_1, action_2)
def should_create_visit_with_incomplete_data(): visit = Visit(30, 'v1', DataAnomaly.INCOMPLETE_DATA, timer=Timer(-900), keep_private=False) incomplete_fields_candidates = [visit.device, visit.network, visit.browser, visit.source] incomplete_fields = list(filter(lambda value: not value, incomplete_fields_candidates)) assert_that(incomplete_fields).is_length(2)
def should_create_visit_with_inconsistent_data(): visit = Visit(30, 'v1', DataAnomaly.INCONSISTENT_DATA, timer=Timer(-900), keep_private=False) def is_dict(field): return type(field) is dict def starts_with_www(field): return field.startswith('www.') inconsistenf_fields = list(filter(lambda result: result, [is_dict(visit.device), is_dict(visit.network), is_dict(visit.browser), starts_with_www(visit.source)])) assert_that(inconsistenf_fields).is_length(2)
def create_initial_visits(self, users_number): visits = [] for user_id in range(0, users_number): visit_duration = randrange(self.__duration_min, self.__duration_max) visits.append(Visit(visit_duration_seconds=visit_duration, app_version=self.versions_to_distribute[user_id], data_anomaly=self.data_anomalies_distribution[user_id], timer=self.timer, keep_private=self.consent_flags[user_id])) return visits
from assertpy import assert_that from data_generator.model.entities import DataAnomaly from data_generator.model.generators import generate_visit_id, generate_user_id, generate_source, \ generate_user_context, generate_technical_context, generate_event_time, generate_visited_page, \ generate_keep_private_flag from data_generator.model.timer import Timer from data_generator.model.visit import Visit complete_visit = Visit(visit_duration_seconds=120, app_version='v1', data_anomaly=DataAnomaly.MISSING, timer=Timer(-900), keep_private=False) def should_generate_consistent_id_between_2_calls(): visit_id_1 = generate_visit_id(complete_visit) visit_id_2 = generate_visit_id(complete_visit) assert_that(visit_id_1).is_equal_to(visit_id_2) def should_generate_user_id_between_2_calls(): user_id_1 = generate_user_id(complete_visit) user_id_2 = generate_user_id(complete_visit) assert_that(user_id_1).is_equal_to(user_id_2) def should_generate_valid_source():
def should_generate_event_for_a_complete_visit(): visit = Visit(30, 'v1', entities.DataAnomaly.INCOMPLETE_DATA, timer=Timer(-120), keep_private=False) event_dict = entities.generate_event(visit) assert_that(event_dict).contains_key('source', 'page', 'user', 'visit_id', 'technical', 'event_time', 'user_id')