def test_get_file_sends_get_request(self): self.setup_responses( method=responses.GET, url='https://retdec.com/service/api', adding_headers={'Content-Disposition': 'filename=test.c'}, stream=True) conn = APIConnection('https://retdec.com/service/api', 'KEY') conn.get_file() self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.method, responses.GET)
def test_get_file_sends_get_request(self): self.setup_responses( method=responses.GET, url='https://retdec.com/service/api', adding_headers={'Content-Disposition': 'filename=test.c'}, stream=True ) conn = APIConnection('https://retdec.com/service/api', 'KEY') conn.get_file() self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.method, responses.GET)
def test_get_file_sets_no_name_when_response_does_not_provide_header(self): self.setup_responses(method=responses.GET, url='https://retdec.com/service/api', body='data', stream=True) conn = APIConnection('https://retdec.com/service/api', 'KEY') file = conn.get_file() self.assertIsNone(file.name)
def test_get_file_sets_no_name_when_response_does_not_provide_header(self): self.setup_responses( method=responses.GET, url='https://retdec.com/service/api', body='data', stream=True ) conn = APIConnection('https://retdec.com/service/api', 'KEY') file = conn.get_file() self.assertIsNone(file.name)
def test_get_file_sets_no_name_when_response_header_does_not_contain_name( self): self.setup_responses(method=responses.GET, url='https://retdec.com/service/api', body='data', headers={'Content-Disposition': 'attachment'}, stream=True) conn = APIConnection('https://retdec.com/service/api', 'KEY') file = conn.get_file() self.assertIsNone(file.name)
def test_get_file_sets_no_name_when_response_header_does_not_contain_name(self): self.setup_responses( method=responses.GET, url='https://retdec.com/service/api', body='data', adding_headers={'Content-Disposition': 'attachment'}, stream=True ) conn = APIConnection('https://retdec.com/service/api', 'KEY') file = conn.get_file() self.assertIsNone(file.name)
def test_get_file_returns_file_with_correct_name_when_header_has_quotes( self): self.setup_responses( method=responses.GET, url='https://retdec.com/service/api', body='data', headers={'Content-Disposition': 'attachment; filename="test.c"'}, stream=True) conn = APIConnection('https://retdec.com/service/api', 'KEY') file = conn.get_file() self.assertEqual(file.name, 'test.c')
def test_get_file_returns_file_with_correct_name_when_header_has_quotes(self): self.setup_responses( method=responses.GET, url='https://retdec.com/service/api', body='data', adding_headers={ 'Content-Disposition': 'attachment; filename="test.c"' }, stream=True ) conn = APIConnection('https://retdec.com/service/api', 'KEY') file = conn.get_file() self.assertEqual(file.name, 'test.c')