예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
    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')
예제 #8
0
    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')