Exemple #1
0
    def test_get_last_update(self, mocked_requests):
        url = "http://test.none/api/tle/last/?satellite_number=40014U"
        mocked_response = Mock()
        mocked_response.ok = True
        mocked_response.json.return_value = self.mock_json
        mocked_requests.return_value = mocked_response

        source = sources.WSTLESource(url="http://test.none/")
        tle = source.get_last_update('40014U')

        mocked_requests.assert_called_with(url, headers=self.headers)
        self.assertEqual(tle, self.expected_lines)
Exemple #2
0
    def test_get_tle(self, mocked_requests):
        expected_url = urlparse.urlparse(
            "http://test.none/api/tle/closest/?date=2015-01-01&satellite_number=40014U")
        expected_qs = urlparse.parse_qs(expected_url.query)

        mocked_response = Mock()
        mocked_response.ok = True
        mocked_response.json.return_value = self.mock_json
        mocked_requests.return_value = mocked_response

        source = sources.WSTLESource(url="http://test.none/")
        tle = source._get_tle('40014U', datetime.datetime(2015, 1, 1))

        call_args = mocked_requests.call_args
        url = urlparse.urlparse(call_args[0][0])
        url_qs = urlparse.parse_qs(url.query)

        self.assertEqual(url.path, expected_url.path)
        self.assertEqual(url_qs, expected_qs)
        self.assertEqual(call_args[1], {'headers': self.headers})
        self.assertEqual(tle, self.expected_lines)