def test_get_statistics(all_states, all_districts, all_mandals, all_stats):
    # Arrange
    import datetime
    storage = MandalStorageImplementation()
    mandal_id = 1
    expected_result = MandalStatistics(
        mandal_id=1,
        mandal_name='Kallur',
        reports=[
            Statistics(date=datetime.date(2020, 5, 22),
                       total_cases=5,
                       total_deaths=1,
                       total_recovered_cases=2),
            Statistics(date=datetime.date(2020, 5, 23),
                       total_cases=6,
                       total_deaths=1,
                       total_recovered_cases=2),
            Statistics(date=datetime.date(2020, 5, 24),
                       total_cases=5,
                       total_deaths=4,
                       total_recovered_cases=2)
        ])

    # Act
    result = storage.get_statistics(mandal_id)

    # Assert
    assert result == expected_result
Ejemplo n.º 2
0
def test_update_mandal_statistics_with_valid_details_updates_mandals_statistics(
    daily_statistics
):
    for_date = "27/05/2020"
    total_confirmed=30
    total_deaths=5
    total_recovered=20
    mandal_id=1
    storage = MandalStorageImplementation()

    storage.update_mandal_statistics(
        for_date=for_date,
        total_confirmed=total_confirmed,
        total_deaths=total_deaths,
        total_recovered=total_recovered,
        mandal_id=mandal_id
    )
    for_date = datetime.strptime(for_date, '%d/%m/%Y').date()

    # Act
    daily_stats = DailyStatistics.objects.get(
        mandal_id=mandal_id,
        for_date=for_date
    )

    # Assert
    assert daily_stats.total_confirmed == total_confirmed
    assert daily_stats.total_deaths == total_deaths
    assert daily_stats.total_recovered == total_recovered
Ejemplo n.º 3
0
def test_is_valid_total_confirmed_when_invalid_details_given_raises_error():
    # Arrange
    total_confirmed = -1
    storage = MandalStorageImplementation()

    # Act
    with pytest.raises(InvalidDetailsForTotalConfirmed):
        storage.is_valid_total_confirmed(total_confirmed=total_confirmed)
def test_is_valid_total_deaths_when_invalid_details_given_raises_error():
    # Arrange
    total_recovered = -10
    storage = MandalStorageImplementation()

    # Act
    with pytest.raises(InvalidDetailsForTotalRecovered):
        storage.is_valid_total_recovered(total_recovered=total_recovered)
def test_is_valid_total_deaths(states):
    # Arrange
    total_recovered = 1
    storage = MandalStorageImplementation()

    # Act
    result = storage.is_valid_total_recovered(total_recovered=total_recovered)

    # Assert
    assert result == None
Ejemplo n.º 6
0
def test_is_valid_mandal_id_given_invalid_mandal_id_raises_invalid_mandal_exception(
):

    # Arrange
    mandal_id = -2
    storage = MandalStorageImplementation()

    # Act
    with pytest.raises(InvalidMandal):
        storage.is_valid_mandal_id(mandal_id=mandal_id)
def test_is_valid_mandal_stats_given_invalid_details_raises_exception():

    # Arrange
    mandal_id = 1
    for_date = '10/05/2020'
    storage = MandalStorageImplementation()

    # Act
    with pytest.raises(InvalidMandalStatistics):
        storage.is_mandal_stats_exists(for_date=for_date, mandal_id=mandal_id)
Ejemplo n.º 8
0
def test_get_daily_statistics_returns_daily_statistics_dtos(
    daily_statistics, daily_statistics_dtos):

    # Arrange
    storage = MandalStorageImplementation()
    
    # Act
    daily_statistics_dtos = storage.get_daily_statistics()

    # Assert
    assert daily_statistics_dtos == daily_statistics_dtos
def is_valid_total_stats_when_invalid_details_given_raises_error():
    # Arrange
    total_confirmed = 10
    total_deaths = 10
    total_recovered = 1
    storage = MandalStorageImplementation()

    # Act
    with pytest.raises(InvalidStatsDetails):
        storage.is_statistics_valid(total_confirmed=total_confirmed,
                                    total_deaths=total_deaths,
                                    total_recovered=total_recovered)
def test_get_district_statistics_on_given_date_returns_district_statistics_dto(
        daily_statistics, district_statistics_dto):

    # Arrange
    for_date = '26/05/2020'
    district_id = 1
    storage = MandalStorageImplementation()

    # Act
    district_statistics_dto = \
        storage.get_district_statistics_on_given_date(for_date, district_id)

    # Assert
    assert district_statistics_dto == district_statistics_dto
Ejemplo n.º 11
0
def test_get_day_wise_mandals_cumulative_statistics_returns_day_wise_(
        daily_statistics, mandals_day_wise_dtos):

    # Arrange
    district_id = 1
    storage = MandalStorageImplementation()

    # Act
    mandals_day_wise_cumulative_dtos = \
        storage.get_day_wise_mandals_cumulative_statistics(
            district_id=district_id)

    # Assert
    assert mandals_day_wise_cumulative_dtos == mandals_day_wise_dtos
def is_valid_total_stats():
    # Arrange
    total_confirmed = 10
    total_deaths = 5
    total_recovered = 1
    storage = MandalStorageImplementation()

    # Act
    result = storage.is_statistics_valid(total_confirmed=total_confirmed,
                                         total_deaths=total_deaths,
                                         total_recovered=total_recovered)

    # Assert
    assert result == None
def test_get_statistics_v2(all_states, all_districts, all_mandals, all_stats):
    # Arrange
    import datetime
    storage = MandalStorageImplementation()
    mandal_id = 5
    expected_result = MandalStatistics(mandal_id=5,
                                       mandal_name='Kavali',
                                       reports=[])

    # Act
    result = storage.get_statistics(mandal_id)

    # Assert
    assert result == expected_result
Ejemplo n.º 14
0
def api_wrapper(*args, **kwargs):
    # ---------MOCK IMPLEMENTATION---------

    user = kwargs['user']
    request_data = kwargs['request_data']
    mandal_id = request_data['mandal_id']
    date = request_data['date']
    total_confirmed = request_data['total_confirmed']
    total_deaths = request_data['total_deaths']
    total_recovered = request_data['total_recovered']

    storage = MandalStorageImplementation()
    presenter = PresenterImplementation()

    interactor = UpdateStatistics(storage=storage, presenter=presenter)
    try:
        interactor.update_statistics(mandal_id=mandal_id,
                                     user=user,
                                     date=date,
                                     total_confirmed=total_confirmed,
                                     total_deaths=total_deaths,
                                     total_recovered=total_recovered)
    except InvalidMandalId:
        raise NotFound(*INVALID_MANDAL_ID)
    except InvalidDetailsForTotalConfirmed:
        raise BadRequest(*INVALID_TOTAL_CONFIRMED)
    except InvalidDetailsForTotalDeaths:
        raise BadRequest(*INVALID_TOTAL_DEATHS)
    except InvalidDetailsForTotalRecovered:
        raise BadRequest(*INVALID_TOTAL_RECOVERED)
    except StatNotFound:
        raise BadRequest(*DETAILS_NOT_FOUND)
    except UserNotAdmin:
        raise Forbidden(*USER_NOT_ADMIN)
    return HttpResponse(status=200)
Ejemplo n.º 15
0
def api_wrapper(*args, **kwargs):

    user = kwargs['user']
    request_data = kwargs['request_data']

    mandal_storage = MandalStorageImplementation()
    presenter = PresenterImplementation()

    user_id = user.id
    for_date = request_data['for_date']
    total_confirmed = request_data['total_confirmed']
    total_recovered = request_data['total_recovered']
    total_deaths = request_data['total_deaths']
    mandal_id = kwargs['mandal_id']

    interactor = CreateOrUpdateMandalStatisticsInteractor(
        mandal_storage=mandal_storage,
        presenter=presenter
    )

    interactor.create_or_update_mandal_statistics(
        user_id=user_id,
        for_date=for_date,
        total_confirmed=total_confirmed,
        total_recovered=total_recovered,
        total_deaths=total_deaths,
        mandal_id=mandal_id
    )

    return HttpResponse(status=201)
Ejemplo n.º 16
0
def test_update_statistics_storage(stats, mandals, districts, states):
    # Arrange
    mandal_id = 1
    total_confirmed = 10
    total_deaths = 4
    total_recovered = 3
    date = datetime.date(year=2020, month=5, day=28)
    storage = MandalStorageImplementation()

    # Act
    storage.update_statistics(date=date,
                              mandal_id=mandal_id,
                              total_confirmed=total_confirmed,
                              total_recovered=total_recovered,
                              total_deaths=total_deaths)
    stat = Stats.objects.get(mandal_id=mandal_id, date=date)

    # Assert
    assert stat.mandal_id == mandal_id
    assert stat.total_confirmed == total_confirmed
    assert stat.total_recovered == total_recovered
    assert stat.total_deaths == total_deaths
def api_wrapper(*args, **kwargs):

    user = kwargs['user']
    user_id = user.id
    mandal_storage = MandalStorageImplementation()
    presenter = PresenterImplementation()

    interactor = DailyStatisticsInteractor(storage=mandal_storage,
                                           presenter=presenter)

    response = interactor.get_daily_statistics(user_id=user_id)

    json_data = json.dumps(response)

    return HttpResponse(json_data, status=200)
Ejemplo n.º 18
0
def api_wrapper(*args, **kwargs):
    # ---------MOCK IMPLEMENTATION---------

    mandal_id = kwargs['mandal_id']
    user = kwargs['user']
    storage = MandalStorageImplementation()
    presenter = PresenterImplementation()

    interactor = GetStatistics(storage=storage, presenter=presenter)
    try:
        response = interactor.get_statistics(mandal_id=mandal_id, user=user)
    except UserNotAdmin:
        raise Forbidden(*USER_NOT_ADMIN)
    except InvalidMandalId:
        raise NotFound(*INVALID_MANDAL_ID)
    data = json.dumps(response)
    return HttpResponse(data, status=200)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
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)