Beispiel #1
0
    def test_raises_an_error_on_blank_like_company_numbers(
            self, company_number):
        """Test that an error is raised for company numbers that are blank or only zeroes."""
        client = DataScienceCompanyAPIClient()

        with pytest.raises(InvalidCompanyNumberError):
            client.get_timeline_events_by_company_number(company_number)
Beispiel #2
0
 def test_transforms_the_api_response(self, company_number):
     """Test the re-formatting of the API response."""
     client = DataScienceCompanyAPIClient()
     assert client.get_timeline_events_by_company_number(
         company_number) == [
             {
                 'data_source': 'companies_house.companies',
                 'datetime': datetime(2018, 12, 31, tzinfo=utc),
                 'description': 'Accounts next due date',
             },
             {
                 'data_source': 'companies_house.companies',
                 'datetime': datetime(2017, 12, 31, tzinfo=utc),
                 'description': 'Accounts filed',
             },
         ]
Beispiel #3
0
    def test_raises_an_error_on_invalid_configuration(self, monkeypatch, api_url, api_id, api_key):
        """Test that ImproperlyConfigured if the API connection details are not configured."""
        monkeypatch.setattr(settings, 'DATA_SCIENCE_COMPANY_API_URL', api_url)
        monkeypatch.setattr(settings, 'DATA_SCIENCE_COMPANY_API_ID', api_id)
        monkeypatch.setattr(settings, 'DATA_SCIENCE_COMPANY_API_KEY', api_key)

        with pytest.raises(ImproperlyConfigured):
            DataScienceCompanyAPIClient()
Beispiel #4
0
def _get_events_for_company(company):
    client = DataScienceCompanyAPIClient()
    try:
        return client.get_timeline_events_by_company_number(company.company_number)
    except InvalidCompanyNumberError:
        return []
Beispiel #5
0
    def test_raises_api_exception_on_an_api_response(self):
        """Test that an APIException is raised when data is received in an unexpected format."""
        client = DataScienceCompanyAPIClient()

        with pytest.raises(APIException):
            client.get_timeline_events_by_company_number('989087')
Beispiel #6
0
    def test_raises_api_exception_on_api_error(self):
        """Test that an APIException is raised when a 500 is returned by the API."""
        client = DataScienceCompanyAPIClient()

        with pytest.raises(APIException):
            client.get_timeline_events_by_company_number('886423')
Beispiel #7
0
 def test_returns_an_empty_list_on_non_existent_company_number(self):
     """Test that an empty list of events is returned for a non-existent company number."""
     client = DataScienceCompanyAPIClient()
     assert client.get_timeline_events_by_company_number('356812') == []