def test_fetcher_get_json(self, mock_requests): mock_requests.get.return_value = self.response url_fetcher = UrlFetcher('url') url_fetcher.response.json = mock.MagicMock() url_fetcher.get_json() url_fetcher.response.json.assert_called_once()
def create_film_from_url(url): film_fetcher = UrlFetcher(url) data = film_fetcher.get_json() return Film.objects.create( id=uuid.UUID(data['id']), name=data['name'] )
def refresh_data(): logger.info('Refreshing data.') try: films_data_url = DataURL.objects.get(name='films') films_url_fetcher = UrlFetcher(films_data_url.url) FilmsFetcher(films_data_url, films_url_fetcher).refresh() except DataURL.DoesNotExist: logger.error('No defined DataURL with name: films') try: people_data_url = DataURL.objects.get(name='people') people_url_fetcher = UrlFetcher(people_data_url.url) PeopleFetcher(people_data_url, people_url_fetcher).refresh() except DataURL.DoesNotExist: logger.error('No defined DataURL with name: people')
def test_fetcher_signature(self, mock_requests): mock_requests.get.return_value = self.response url_fetcher = UrlFetcher('url') self.assertEqual(get_signature(self.response.text), url_fetcher.signature)
def test_fetcher_has_data(self, mock_requests): mock_requests.get.return_value = self.response url_fetcher = UrlFetcher('url') self.assertTrue(hasattr(url_fetcher, 'data'))
def test_get_response_401(self, mock_requests): self.response.status_code = 401 mock_requests.get.return_value = self.response with self.assertRaises(ApiServiceError): UrlFetcher('url')
def test_get_response_404(self, mock_requests): self.response.status_code = 404 mock_requests.get.return_value = self.response with self.assertRaises(NoDataError): UrlFetcher('url')