def test_is_district_id_valid_when_invalid_district_id_raises_exception(): # Arrange district_id = 1 storage = DistrictStorageImplementation() # Act with pytest.raises(InvalidDistrictId): storage.is_district_id_valid(district_id=district_id)
def test_is_district_id_valid_when_valid_district_id(states, districts): # Arrange district_id = 1 storage = DistrictStorageImplementation() # Act result = storage.is_district_id_valid(district_id=district_id) # Assert assert result == None
def test_get_day_wise_districts_cumulative_statistics_returns_day_wise_( daily_statistics, districts_day_wise_dtos): # Arrange storage = DistrictStorageImplementation() # Act districts_day_wise_cumulative_dto = \ storage.get_day_wise_districts_cumulative_statistics() # Assert assert districts_day_wise_cumulative_dto == districts_day_wise_dtos
def test_get_day_wise_district_statistics_returns_state_day_wise_dtos( daily_statistics, district_day_wise_statistics_dtos): # Arrange district_id = 1 storage = DistrictStorageImplementation() # Act district_statistics_dtos = \ storage.get_day_wise_district_statistics(district_id=district_id) # Assert assert district_statistics_dtos == district_day_wise_statistics_dtos
def api_wrapper(*args, **kwargs): storage = DistrictStorageImplementation() presenter = PresenterImplementation() interactor = DistrictsDayWiseCumulativeStatisticsInteractor( storage=storage, presenter=presenter ) response = interactor.get_day_wise_districts_cumulative_statistics() json_data = json.dumps(response) return HttpResponse(json_data, status=200)
def test_get_district_cumulative_statistics_returns_district_cumulative_dtos( daily_statistics, district_cumulative_statistics_dto): # Arrange till_date = '27/05/2020' district_id = 1 storage = DistrictStorageImplementation() # Act district_cumulative_dto = \ storage.get_district_cumulative_statistics( till_date=till_date, district_id=district_id ) # Assert assert district_cumulative_dto == district_cumulative_statistics_dto
def api_wrapper(*args, **kwargs): request_data = kwargs['request_data'] till_date = request_data['till_date'] district_id = kwargs['district_id'] storage = DistrictStorageImplementation() presenter = PresenterImplementation() interactor = DistrictCumulativeStatisticsInteractor(storage=storage, presenter=presenter) response = interactor.get_district_cumulative_statistics( till_date=till_date, district_id=district_id) json_data = json.dumps(response) return HttpResponse(json_data, status=200)
def api_wrapper(*args, **kwargs): # ---------MOCK IMPLEMENTATION--------- storage = DistrictStorageImplementation() presenter = PresenterImplementation() interactor = GetDayWiseMandalDetails(storage=storage, presenter=presenter) request_data = kwargs['request_data'] district_id = kwargs['district_id'] try: response = interactor.get_day_wise_mandal_details( district_id=district_id) except InvalidDistrictId: raise NotFound(*INVALID_DISTRICT_ID) data = json.dumps(response) response = HttpResponse(data, status=200) return response
def api_wrapper(*args, **kwargs): district_id = kwargs['district_id'] storage = DistrictStorageImplementation() presenter = PresenterImplementation() interactor = DistrictDayWiseStatisticsInteractor( storage=storage, presenter=presenter ) response = interactor.get_day_wise_district_statistics( district_id=district_id ) json_data = json.dumps(response) return HttpResponse(json_data, status=200)
def test_get_daily_cumulative_report_for_district_storage( all_states, all_districts, all_mandals, all_stats): # Arrange district_id = 1 storage = DistrictStorageImplementation() expected_result = DailyCumulativeReport(report=[ CumulativeReportOnSpecificDay(date=datetime.date(2020, 5, 20), total_cases=0, total_deaths=0, total_recovered_cases=0, active_cases=0), CumulativeReportOnSpecificDay(date=datetime.date(2020, 5, 21), total_cases=0, total_deaths=0, total_recovered_cases=0, active_cases=0), CumulativeReportOnSpecificDay(date=datetime.date(2020, 5, 22), total_cases=6, total_deaths=3, total_recovered_cases=5, active_cases=-2), CumulativeReportOnSpecificDay(date=datetime.date(2020, 5, 23), total_cases=28, total_deaths=8, total_recovered_cases=13, active_cases=7), CumulativeReportOnSpecificDay(date=datetime.date(2020, 5, 24), total_cases=57, total_deaths=27, total_recovered_cases=17, active_cases=13), CumulativeReportOnSpecificDay(date=datetime.date(2020, 5, 25), total_cases=87, total_deaths=32, total_recovered_cases=27, active_cases=28) ]) # Act result = storage.get_daily_cumulative_report_for_district(district_id) # Assert assert result == expected_result
def api_wrapper(*args, **kwargs): # ---------MOCK IMPLEMENTATION--------- storage = DistrictStorageImplementation() presenter = PresenterImplementation() interactor = GetDistrictCumulativeReport(storage=storage, presenter=presenter) request_data = kwargs['request_data'] district_id = kwargs['district_id'] query = kwargs['request_query_params'] till_date = query['till_date'] try: response = interactor.get_district_cumulative_report( till_date=till_date, district_id=district_id) except InvalidDistrictId: raise NotFound(*INVALID_DISTRICT_ID) data = json.dumps(response) return HttpResponse(data, status=200)
def test_get_daily_cumulative_report_of_mandals_for_district_when_no_cases( all_districts, all_mandals, all_states): # Arrange district_id = 1 expected_result = { "district_name":'Kurnool', "mandals":{ 1: {'mandal_id': 1, 'mandal_name': 'Kallur'}, 2: {'mandal_id': 2, 'mandal_name': 'Adoni'}, 3: {'mandal_id': 3, 'mandal_name': 'Kodumur'} }, "reports":defaultdict(list) } storage = DistrictStorageImplementation() result = storage.get_daily_cumulative_report_of_mandals_for_district( district_id=district_id) assert result == expected_result
def api_wrapper(*args, **kwargs): # ---------MOCK IMPLEMENTATION--------- storage = DistrictStorageImplementation() presenter = PresenterImplementation() interactor = GetDailyCumulativeReportOfMandalsForDistrict( storage=storage, presenter=presenter) request_data = kwargs['request_data'] district_id = kwargs['district_id'] try: response = interactor.get_daily_cumulative_report_of_mandals_for_district( district_id=district_id) except InvalidDistrictId: raise NotFound(*INVALID_DISTRICT_ID) data = json.dumps(response) response = HttpResponse(data, status=200) return response
def api_wrapper(*args, **kwargs): district_id = kwargs['district_id'] district_storage = DistrictStorageImplementation() mandal_storage = MandalStorageImplementation() presenter = PresenterImplementation() interactor = MandalsDayWiseCumulativeStatisticsInteractor( district_storage=district_storage, mandal_storage=mandal_storage, presenter=presenter) response = interactor\ .get_day_wise_mandals_cumulative_statistics_of_the_given_district( district_id=district_id ) json_data = json.dumps(response) return HttpResponse(json_data, status=200)
def test_get_district_cumulative_report(all_states, all_districts, all_mandals, all_stats): # Arrange district_id = 1 till_date = datetime.date(year=2020, month=5, day=29) expected_result = DistrictReportDto( district_name='Kurnool', mandals=[ MandalReportDto(mandal_id=1, mandal_name='Kallur', total_cases=16, total_deaths=6, total_recovered_cases=6, active_cases=4), MandalReportDto(mandal_id=2, mandal_name='Adoni', total_cases=14, total_deaths=3, total_recovered_cases=7, active_cases=4), MandalReportDto(mandal_id=3, mandal_name='Kodumur', total_cases=57, total_deaths=23, total_recovered_cases=14, active_cases=20) ], total_cases=87, total_deaths=32, total_recovered_cases=27, active_cases=28) storage = DistrictStorageImplementation() # Act result = storage.get_district_cumulative_report(district_id=district_id, till_date=till_date) # Assert assert result == expected_result
def test_get_district_cumulative_report_v2(all_states, all_districts, all_mandals, all_stats): # Arrange district_id = 2 till_date = datetime.date(year=2020, month=5, day=29) expected_result = DistrictReportDto( district_name='Nellore', mandals=[ MandalReportDto(mandal_id=4, mandal_name='Kota', total_cases=0, total_deaths=0, total_recovered_cases=0, active_cases=0), MandalReportDto(mandal_id=5, mandal_name='Kavali', total_cases=0, total_deaths=0, total_recovered_cases=0, active_cases=0), MandalReportDto(mandal_id=6, mandal_name='Kovuru', total_cases=40, total_deaths=0, total_recovered_cases=20, active_cases=20) ], total_cases=40, total_deaths=0, total_recovered_cases=20, active_cases=20) storage = DistrictStorageImplementation() # Act result = storage.get_district_cumulative_report(district_id=district_id, till_date=till_date) # Assert assert result == expected_result
def api_wrapper(*args, **kwargs): district_id = kwargs['district_id'] request_data = kwargs['request_data'] for_date = request_data['for_date'] district_storage = DistrictStorageImplementation() mandal_storage = MandalStorageImplementation() presenter = PresenterImplementation() interactor = DistrictStatisticsInteractor( district_storage=district_storage, mandal_storage=mandal_storage, presenter=presenter) response = \ interactor.get_district_statistics_on_given_date( district_id=district_id, for_date=for_date ) json_data = json.dumps(response) return HttpResponse(json_data, status=200)
def test_get_district_report_of_specific_day(all_states, all_districts, all_mandals, all_stats): # Arrange import datetime district_id = 1 date = datetime.date(year=2020, month=5, day=24) storage = DistrictStorageImplementation() expected_result = DistrictReportOfDay( district_name='Kurnool', mandals=[ MandalReportOfDay(mandal_id=1, mandal_name='Kallur', total_cases=5, total_deaths=4, total_recovered_cases=2), MandalReportOfDay(mandal_id=2, mandal_name='Adoni', total_cases=7, total_deaths=0, total_recovered_cases=0), MandalReportOfDay(mandal_id=3, mandal_name='Kodumur', total_cases=17, total_deaths=15, total_recovered_cases=2) ], total_cases=29, total_deaths=19, total_recovered_cases=4) # Act result = storage.get_district_report_of_specific_day( district_id=district_id, date=date) # Assert assert result == expected_result
def test_get_daily_cumulative_report_of_mandals_for_district( all_mandals, all_states, all_districts, all_stats): # Arrange district_id = 1 expected_result = { "district_name":'Kurnool', "mandals":{ 1: {'mandal_id': 1, 'mandal_name': 'Kallur'}, 2: {'mandal_id': 2, 'mandal_name': 'Adoni'}, 3: {'mandal_id': 3, 'mandal_name': 'Kodumur'} }, "reports":defaultdict(list, { 1: [ defaultdict(int, { 'date': datetime.date(2020, 5, 22), 'total_cases': 5, 'total_deaths': 1, 'total_recovered_cases': 2, # 'active_cases': 2 }), defaultdict(int, { 'date': datetime.date(2020, 5, 23), 'total_cases': 11, 'total_deaths': 2, 'total_recovered_cases': 4, # 'active_cases': 5 }), defaultdict(int, { 'date': datetime.date(2020, 5, 24), 'total_cases': 16, 'total_deaths': 6, 'total_recovered_cases': 6, # 'active_cases': 4 }) ], 2: [ defaultdict(int, { 'date': datetime.date(2020, 5, 22), 'total_cases': 1, 'total_deaths': 2, 'total_recovered_cases': 3, # 'active_cases': -4 }), defaultdict(int, { 'date': datetime.date(2020, 5, 23), 'total_cases': 7, 'total_deaths': 3, 'total_recovered_cases': 7, # 'active_cases': -3 }), defaultdict(int, { 'date': datetime.date(2020, 5, 24), 'total_cases': 14, 'total_deaths': 3, 'total_recovered_cases': 7, # 'active_cases': 4 }) ], 3: [ defaultdict(int, { 'date': datetime.date(2020, 5, 23), 'total_cases': 10, 'total_deaths': 3, 'total_recovered_cases': 2, # 'active_cases': 5 }), defaultdict(int, { 'date': datetime.date(2020, 5, 24), 'total_cases': 27, 'total_deaths': 18, 'total_recovered_cases': 4, # 'active_cases': 5 }), defaultdict(int, { 'date': datetime.date(2020, 5, 25), 'total_cases': 57, 'total_deaths': 23, 'total_recovered_cases': 14, # 'active_cases': 20 }) ] } ) } storage = DistrictStorageImplementation() result = storage.get_daily_cumulative_report_of_mandals_for_district( district_id=district_id) assert result == expected_result