Exemplo n.º 1
0
def mock_spk_url(request):
    # Mock requests so we don't hit the server
    with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
        for data in spk_data:
            body = 'fake data for ' + data['kernel']

            # If the file is in the 'old' directory, mock a 404 response in the
            # top level directory.
            if data['old']:
                rsps.add(GET, SPK_URL.format(**data), status=404)
                url = SPK_OLD_URL
            else:

                url = SPK_URL
            if request.param:
                rsps.add(GET, url.format(**data), body=body)
            else:
                headers = {'Content-Length': str(len(body))}
                rsps.add(GET,
                         url.format(**data),
                         body=body,
                         adding_headers=headers)

        rsps.add(GET,
                 SPK_URL.format(category='planets', kernel='tatooine'),
                 status=404)
        rsps.add(GET,
                 SPK_OLD_URL.format(category='planets', kernel='tatooine'),
                 status=404)

        yield rsps
def mock_spk_url(request):
    # Mock requests so we don't hit the server
    with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
        for data in spk_data:
            body = 'fake data for ' + data['kernel']

            # If the file is in the 'old' directory, mock a 404 response in the
            # top level directory.
            if data['old']:
                rsps.add(GET, SPK_URL.format(**data), status=404)
                url = SPK_OLD_URL
            else:

                url = SPK_URL
            if request.param:
                rsps.add(GET, url.format(**data), body=body)
            else:
                headers = {'Content-Length': str(len(body))}
                rsps.add(GET, url.format(**data), body=body, adding_headers=headers)

        rsps.add(GET, SPK_URL.format(category='planets', kernel='tatooine'),
                 status=404)
        rsps.add(GET, SPK_OLD_URL.format(category='planets', kernel='tatooine'),
                 status=404)

        yield rsps
Exemplo n.º 3
0
 def test_default_dir(self, capsys):
     with patch('astrodynamics.utils.web.download_file_with_progress',
                autospec=True) as mock:
         url = SPK_URL.format(category='planets', kernel='de432s')
         download_spk('planets', 'de432s')
         mock.assert_called_once_with(url, str(SPK_DIR / 'de432s.bsp'))
         capsys.readouterr()
 def test_default_dir(self, capsys):
     with patch('astrodynamics.utils.web.download_file_with_progress',
                autospec=True) as mock:
         url = SPK_URL.format(category='planets', kernel='de432s')
         download_spk('planets', 'de432s')
         mock.assert_called_once_with(url, str(SPK_DIR / 'de432s.bsp'))
         capsys.readouterr()
    def test_download_failed(self, tmpdir):
        with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
            rsps.add(
                GET, SPK_URL.format(category='planets', kernel='jakku'),
                status=500)
            rsps.add(
                GET, SPK_OLD_URL.format(category='planets', kernel='jakku'),
                status=500)

            with pytest.raises(requests.HTTPError):
                download_spk(category='planets', kernel='jakku',
                             download_dir=str(tmpdir))
Exemplo n.º 6
0
    def test_download_failed(self, tmpdir):
        with responses.RequestsMock(
                assert_all_requests_are_fired=False) as rsps:
            rsps.add(GET,
                     SPK_URL.format(category='planets', kernel='jakku'),
                     status=500)
            rsps.add(GET,
                     SPK_OLD_URL.format(category='planets', kernel='jakku'),
                     status=500)

            with pytest.raises(requests.HTTPError):
                download_spk(category='planets',
                             kernel='jakku',
                             download_dir=str(tmpdir))
    def test_kernel_with_extension(self, tmpdir, capsys):
        """Test that kernel can still be downloaded if it has its extension."""
        with patch('astrodynamics.utils.web.download_file_with_progress',
                   autospec=True) as mock_download_file_with_progress:

            download_spk(category='planets', kernel='de432s.bsp',
                         download_dir=str(tmpdir))

            url = SPK_URL.format(category='planets', kernel='de432s')
            filepath = tmpdir.join('de432s.bsp')

            mock_download_file_with_progress.assert_called_once_with(
                url, str(filepath))

            mock_download_file_with_progress.reset_mock()
            assert not mock_download_file_with_progress.called
        capsys.readouterr()
Exemplo n.º 8
0
    def test_kernel_with_extension(self, tmpdir, capsys):
        """Test that kernel can still be downloaded if it has its extension."""
        with patch('astrodynamics.utils.web.download_file_with_progress',
                   autospec=True) as mock_download_file_with_progress:

            download_spk(category='planets',
                         kernel='de432s.bsp',
                         download_dir=str(tmpdir))

            url = SPK_URL.format(category='planets', kernel='de432s')
            filepath = tmpdir.join('de432s.bsp')

            mock_download_file_with_progress.assert_called_once_with(
                url, str(filepath))

            mock_download_file_with_progress.reset_mock()
            assert not mock_download_file_with_progress.called
        capsys.readouterr()