コード例 #1
0
    def test_if_city_is_not_present_and_previous_report_has_0_for_both_counters_add_the_entry(
            self):
        city_data = self.cities_data.pop(0)
        city_data["deaths"] = 0
        city_data["confirmed"] = 0
        table_data = [self.total_data, self.undefined_data, city_data]
        self.new_spreadsheet_with_data(
            date=self.today - timedelta(days=2),
            state=self.uf,
            status=StateSpreadsheet.DEPLOYED,
            table_data=table_data,
        )
        self.spreadsheet.table_data = [self.total_data, self.undefined_data
                                       ] + self.cities_data

        expected = city_data.copy()
        expected["date"] = self.today.isoformat()
        assert expected not in self.spreadsheet.table_data

        warnings = validate_historical_data(self.spreadsheet)

        assert [
            f"{city_data['city']} possui dados históricos zerados/nulos, não presente na planilha e foi adicionado."
        ] == warnings
        assert expected in self.spreadsheet.table_data
コード例 #2
0
    def test_reuse_past_data_if_city_not_present_in_data_with_only_total_sum(
            self):
        table_data = self.cities_data + [self.total_data, self.undefined_data]
        recent = self.new_spreadsheet_with_data(
            date=self.today - timedelta(days=2),
            state=self.uf,
            status=StateSpreadsheet.DEPLOYED,
            table_data=table_data,
        )

        self.total_data["deaths"] = 2
        self.total_data["confirmed"] = 5
        self.spreadsheet.table_data = [self.total_data]  # only total

        warnings = validate_historical_data(self.spreadsheet)
        self.spreadsheet.warnings = warnings

        assert self.total_data in self.spreadsheet.table_data
        assert self.undefined_data in self.spreadsheet.table_data
        for city_data in self.cities_data:
            assert city_data in self.spreadsheet.table_data

        assert 2 == len(warnings)
        assert (
            f"Planilha importada somente com dados totais. Dados de cidades foram reutilizados da importação do dia {recent.date.isoformat()}."
            in warnings)
        assert "Números de confirmados ou óbitos totais é menor que o total anterior." in warnings
        assert self.spreadsheet.get_total_data()["deaths"] == 2
        assert self.spreadsheet.get_total_data()["confirmed"] == 5
        assert self.spreadsheet.only_with_total_entry is True
コード例 #3
0
    def test_reuse_past_data_if_city_not_present_in_data_with_only_total_sum(
            self):
        Covid19Cases = self.Covid19Cases
        previous_entries = self.cities_data + [
            self.total_data, self.undefined_data
        ]
        for cases_data in [c.copy() for c in previous_entries]:
            cases_data["date"] = self.today - timedelta(days=2)
            baker.make(Covid19Cases, **cases_data)

        self.total_data["deaths"] = 2
        self.total_data["confirmed"] = 5
        self.spreadsheet.table_data = [self.total_data]  # only total

        warnings = validate_historical_data(self.spreadsheet)

        assert self.total_data in self.spreadsheet.table_data
        assert self.undefined_data in self.spreadsheet.table_data
        for city_data in self.cities_data:
            assert city_data in self.spreadsheet.table_data

        assert 2 == len(warnings)
        assert (
            f'Planilha importada somente com dados totais. Dados de cidades foram reutilizados da importação do dia {cases_data["date"]}.'
            in warnings)
        assert "Números de confirmados ou óbitos totais é menor que o total anterior." in warnings
        assert self.spreadsheet.get_total_data()["deaths"] == 2
        assert self.spreadsheet.get_total_data()["confirmed"] == 5
コード例 #4
0
    def test_guarantee_warnings_for_new_lower_total_and_undefined_numbers(
            self):
        self.spreadsheet.table_data = [
            self.total_data.copy(),
            self.undefined_data.copy()
        ]
        table_data = []
        for cases_data in [
                c.copy() for c in [self.total_data, self.undefined_data]
        ]:
            cases_data["deaths"] = 200
            table_data.append(cases_data)
        self.new_spreadsheet_with_data(
            date=self.today - timedelta(days=2),
            state=self.uf,
            status=StateSpreadsheet.DEPLOYED,
            table_data=table_data,
        )

        undefined_name = self.undefined_data["city"]
        expected = [
            f"Números de confirmados ou óbitos em {undefined_name} é menor que o anterior.",
            "Números de confirmados ou óbitos totais é menor que o total anterior.",
        ]
        warnings = validate_historical_data(self.spreadsheet)
        self.spreadsheet.warnings = warnings

        assert expected == warnings
        assert self.spreadsheet.only_with_total_entry is False
コード例 #5
0
    def test_accept_first_spreadsheet_only_with_total_tada(self):
        self.spreadsheet.table_data = [self.total_data]  # only total

        warnings = validate_historical_data(self.spreadsheet)

        assert 1 == len(self.spreadsheet.table_data)
        assert self.total_data in self.spreadsheet.table_data
        assert ["Planilha importada somente com dados totais."] == warnings
コード例 #6
0
    def test_raise_validation_error_previous_city_not_present_in_data(self):
        self.spreadsheet.table_data = [self.total_data,
                                       self.undefined_data]  # no cities
        self.new_spreadsheet_with_data(
            date=self.today - timedelta(days=2),
            state=self.uf,
            status=StateSpreadsheet.DEPLOYED,
            table_data=[self.total_data, self.undefined_data] +
            self.cities_data,
        )

        # older city from the same state is not considered
        self.new_spreadsheet_with_data(
            date=self.today - timedelta(days=8),
            state=self.uf,
            status=StateSpreadsheet.DEPLOYED,
            table_data=[{
                "place_type": "city",
                "confirmed": 1000,
                "deaths": 1000,
                "city": "bar",
            }],
        )

        # report with date greater than the spreadsheet's one shouldn't be considered
        self.new_spreadsheet_with_data(
            date=self.today + timedelta(days=8),
            state=self.uf,
            status=StateSpreadsheet.DEPLOYED,
            table_data=[{
                "place_type": "city",
                "confirmed": 500,
                "deaths": 500,
                "city": "bar",
            }],
        )

        with pytest.raises(SpreadsheetValidationErrors) as execinfo:
            validate_historical_data(self.spreadsheet)

        exception = execinfo.value
        assert len(self.cities_cases) == len(exception.error_messages)
        for city_name in [c["city"] for c in self.cities_cases]:
            msg = f"{city_name} possui dados históricos e não está presente na planilha."
            assert msg in exception.error_messages
コード例 #7
0
    def test_raise_validation_error_previous_city_not_present_in_data(self):
        Covid19Cases = self.Covid19Cases
        self.spreadsheet.table_data = [self.total_data,
                                       self.undefined_data]  # no cities
        for cases_data in [c.copy() for c in self.cities_data]:
            cases_data['date'] = self.today - timedelta(days=2)
            baker.make(Covid19Cases, **cases_data)

        # older city from the same state is not considered
        baker.make(
            Covid19Cases,
            date=self.today - timedelta(days=8),
            state=self.uf,
            place_type='city',
            confirmed=1000,
            deaths=1000,
            city='bar',
        )

        # report with date greater than the spreadsheet's one shouldn't be considered
        baker.make(
            Covid19Cases,
            date=self.today + timedelta(days=8),
            state=self.uf,
            place_type='city',
            confirmed=1000,
            deaths=1000,
            city='foo',
        )

        # a more recent report, but from other state
        baker.make(Covid19Cases,
                   date=self.today,
                   state='RR',
                   place_type='city')

        with pytest.raises(SpreadsheetValidationErrors) as execinfo:
            validate_historical_data(self.spreadsheet)

        exception = execinfo.value
        assert len(self.cities_cases) == len(exception.error_messages)
        for city_name in [c['city'] for c in self.cities_cases]:
            msg = f"{city_name} possui dados históricos e não está presente na planilha"
            assert msg in exception.error_messages
コード例 #8
0
    def test_is_valid_if_historical_data_has_the_same_values_as_the_new_import(
            self):
        Covid19Cases = self.Covid19Cases
        self.spreadsheet.table_data = [self.total_data, self.undefined_data
                                       ] + self.cities_data
        for cases_data in [c.copy() for c in self.cities_data]:
            cases_data['date'] = self.today - timedelta(days=1)
            baker.make(Covid19Cases, **cases_data)

        warnings = validate_historical_data(self.spreadsheet)

        assert not warnings
コード例 #9
0
    def test_is_valid_if_historical_data_has_the_same_values_as_the_new_import(
            self):
        self.spreadsheet.table_data = [self.total_data, self.undefined_data
                                       ] + self.cities_data
        self.new_spreadsheet_with_data(
            date=self.today - timedelta(days=2),
            state=self.uf,
            status=StateSpreadsheet.DEPLOYED,
            table_data=[self.total_data, self.undefined_data] +
            self.cities_data,
        )

        warnings = validate_historical_data(self.spreadsheet)

        assert not warnings
コード例 #10
0
    def test_return_warning_message_if_number_of_deaths_is_lower_than_previous_day(
            self):
        Covid19Cases = self.Covid19Cases
        self.spreadsheet.table_data = [self.total_data, self.undefined_data
                                       ] + self.cities_data
        for cases_data in [c.copy() for c in self.cities_data]:
            cases_data['date'] = self.today - timedelta(days=1)
            baker.make(Covid19Cases, **cases_data)

        Covid19Cases.objects.all().update(deaths=200)

        warnings = validate_historical_data(self.spreadsheet)

        assert len(self.cities_cases) == len(warnings)
        for city_name in [c['city'] for c in self.cities_cases]:
            msg = f"Números de confirmados ou óbitos em {city_name} é menor que o anterior."
            assert msg in warnings
コード例 #11
0
    def test_return_warning_message_if_number_of_deaths_is_lower_than_previous_day(
            self):
        self.spreadsheet.table_data = [self.total_data, self.undefined_data
                                       ] + self.cities_data
        table_data = [self.total_data, self.undefined_data]
        for cases_data in [c.copy() for c in self.cities_data]:
            cases_data["deaths"] = 200
            table_data.append(cases_data)
        self.new_spreadsheet_with_data(date=self.today - timedelta(days=2),
                                       state=self.uf,
                                       status=StateSpreadsheet.DEPLOYED,
                                       table_data=table_data)

        warnings = validate_historical_data(self.spreadsheet)

        assert len(self.cities_cases) == len(warnings)
        for city_name in [c["city"] for c in self.cities_cases]:
            msg = f"Números de confirmados ou óbitos em {city_name} é menor que o anterior."
            assert msg in warnings
コード例 #12
0
    def test_guarantee_warnings_for_new_lower_total_and_undefined_numbers(
            self):
        Covid19Cases = self.Covid19Cases
        self.spreadsheet.table_data = [
            self.total_data.copy(),
            self.undefined_data.copy()
        ]
        self.total_data['date'] = self.today - timedelta(days=1)
        baker.make(Covid19Cases, **self.total_data)
        self.undefined_data['date'] = self.today - timedelta(days=1)
        baker.make(Covid19Cases, **self.undefined_data)

        Covid19Cases.objects.all().update(deaths=200)
        undefined_name = self.undefined_data['city']
        expected = [
            f"Números de confirmados ou óbitos em {undefined_name} é menor que o anterior.",
            f"Números de confirmados ou óbitos totais é menor que o total anterior.",
        ]
        warnings = validate_historical_data(self.spreadsheet)

        assert expected == warnings
コード例 #13
0
    def test_if_city_is_not_present_and_previous_report_has_0_for_both_counters_add_the_entry(
            self):
        Covid19Cases = self.Covid19Cases
        city_data = self.cities_data.pop(0)
        city_data["deaths"] = 0
        city_data["confirmed"] = 0
        city_data["date"] = self.today - timedelta(days=2)
        baker.make(Covid19Cases, **city_data)
        self.spreadsheet.table_data = [self.total_data, self.undefined_data
                                       ] + self.cities_data

        expected = city_data.copy()
        expected["date"] = self.today.isoformat()
        assert expected not in self.spreadsheet.table_data

        warnings = validate_historical_data(self.spreadsheet)

        assert [
            f"{city_data['city']} possui dados históricos zerados/nulos, não presente na planilha e foi adicionado."
        ] == warnings
        assert expected in self.spreadsheet.table_data