def test_request_contains_correct_content(self):
        smartyrequest = smarty.Request()
        smartyrequest.url_prefix = "http://localhost"
        smartyrequest.payload = "This is the test content."

        request = smarty.requests_sender.build_request(smartyrequest)

        self.assertEqual("This is the test content.", request.data)
    def test_http_request_contains_post_when_appropriate(self):
        smartyrequest = smarty.Request()
        smartyrequest.url_prefix = "http://localhost"

        smartyrequest.payload = "Test Payload"
        request = smarty.requests_sender.build_request(smartyrequest)

        self.assertEqual("POST", request.method)
    def test_smartyresponse_contains_status_code_400_when_server_gives_a_400(
            self, mock_send):
        sender = smarty.RequestsSender()
        smartyrequest = smarty.Request()
        smartyrequest.url_prefix = "http://localhost/error"

        response = sender.send(smartyrequest)

        self.assertEqual(400, response.status_code)
    def test_smartyresponse_contains_status_code_200_on_success(
            self, mock_send):
        sender = smarty.RequestsSender()
        smartyrequest = smarty.Request()
        smartyrequest.url_prefix = "http://localhost"

        response = sender.send(smartyrequest)

        self.assertEqual(200, response.status_code)
    def test_smartyresponse_contains_correct_payload(self, mock_send):
        sender = smarty.RequestsSender()
        smartyrequest = smarty.Request()
        smartyrequest.url_prefix = "http://localhost"
        smartyrequest.payload = "This is the test content."

        response = sender.send(smartyrequest)

        self.assertEqual("This is the test payload.", response.payload)
    def test_request_has_correct_content_type(self):
        smartyrequest = smarty.Request()
        smartyrequest.url_prefix = "http://localhost"
        smartyrequest.payload = "This is the test content."
        smartyrequest.content_type = 'text/plain'

        request = smarty.requests_sender.build_request(smartyrequest)

        self.assertEqual('text/plain', request.headers['Content-Type'])
    def test_license_not_set(self):
        sender = smarty.RequestsSender()
        sender = smarty.LicenseSender([], sender)
        request = smarty.Request()
        request.url_prefix = "http://localhost"

        sender.send(request)

        self.assertEqual(0, len(request.parameters))
    def test_license_set(self):
        sender = smarty.RequestsSender()
        licenses = ['one', 'two', 'three']
        sender = smarty.LicenseSender(licenses, sender)
        request = smarty.Request()
        request.url_prefix = "http://localhost"

        sender.send(request)

        self.assertEqual('one,two,three', request.parameters['license'])
Beispiel #9
0
    def test_custom_headers_used(self):
        sender = smarty.RequestsSender()
        header = {'User-Agent': 'Test-Agent', 'Content-Type': 'Test-Type'}
        sender = smarty.CustomHeaderSender(header, sender)
        smartyrequest = smarty.Request()
        smartyrequest.url_prefix = "http://localhost"
        smartyrequest.payload = "This is the test content."

        request = sender.build_request(smartyrequest)

        request = smarty.requests_sender.build_request(request)

        self.assertEqual('Test-Agent', request.headers['User-Agent'])
        self.assertEqual('Test-Type', request.headers['Content-Type'])