Beispiel #1
0
 def test_download_file_missing_content_type(self, **kwargs):
     mock_request = kwargs['mock_request']
     headers = {}
     mock_request.get(self.url, headers=headers)
     try:
         download_file(self.url)
         raise pytest.fail(
             'No exception occurred. Expected: MissingContentType')
     except MissingContentType as err:
         assert err.args == ()
Beispiel #2
0
 def test_unsupported_content_type(self, **kwargs):
     mock_request = kwargs['mock_request']
     headers = {'Content-Type': 'video/mp4'}
     mock_request.get(self.url, headers=headers)
     try:
         download_file(self.url)
         raise pytest.fail(
             'No exception occurred. Expected: UnsupportedContentType')
     except UnsupportedContentType as err:
         assert err.args[0] == 'Unsupported type: video/mp4'
Beispiel #3
0
 def test_invalid_content_type(self, **kwargs):
     mock_request = kwargs['mock_request']
     headers = {'Content-Type': 'application/text/json'}
     mock_request.get(self.url, headers=headers)
     try:
         download_file(self.url)
         raise pytest.fail(
             'No exception occurred. Expected: InvalidContentType')
     except InvalidContentType as err:
         assert err.args[0] == 'application/text/json'
Beispiel #4
0
 def test_throw_invalid_response_code(self, **kwargs):
     mock_request = kwargs['mock_request']
     headers = {'Content-Type': 'application/json'}
     mock_request.get(self.url, headers=headers, status_code=504)
     try:
         download_file(self.url)
         raise pytest.fail(
             'No exception occurred. Expected: InvalidResponseCode')
     except InvalidResponseCode as err:
         assert err.args[0] == 'Invalid response code: 504'
Beispiel #5
0
 def test_throw_invalid_url_scheme(self, **kwargs):
     mock_request = kwargs['mock_request']
     headers = {'Content-Type': 'application/json'}
     mock_request.get('http://mocker-test.com',
                      headers=headers,
                      status_code=504)
     try:
         download_file('http://mocker-test.com')
         raise pytest.fail('No exception occurred. Expected: InvalidScheme')
     except InvalidSchema as err:
         assert err.args[0] == 'Invalid schema!'
Beispiel #6
0
 def test_download_file_is_octetstream(self, **kwargs):
     mock_request = kwargs['mock_request']
     headers = {
         'Content-Type': 'application/octetstream',
         'Content-Disposition': 'attachment; filename=example_file.doc'
     }
     mock_request.get(self.url, headers=headers, content=b'')
     res_type, res_details = download_file(self.url)
     assert res_details['format'] == 'doc'
Beispiel #7
0
 def test_download_file_filename_from_content_disposition(self, **kwargs):
     mock_request = kwargs['mock_request']
     headers = {
         'Content-Type': 'text/html',
         'Content-Disposition': 'attachment; filename=example_file.html'
     }
     mock_request.get(self.url, headers=headers, content=b'')
     res_type, res_details = download_file(self.url)
     assert res_details['filename'] == 'example_file.html'
Beispiel #8
0
 def test_throw_invalid_url(self):
     try:
         download_file('www.brokenlink')
         raise pytest.fail('No exception occurred. Expected: InvalidUrl')
     except InvalidUrl as err:
         assert err.args[0] == 'Invalid url address: www.brokenlink'