Ejemplo n.º 1
0
    def test_500_error_custom_message(self, mocked_time, mocked_request):
        """
            Test case to verify 500 error message from response
        """
        mocked_request.return_value = MockedResponse(500)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.Server5xxError) as e:
            clx.request('GET')

        self.assertEqual(str(e.exception),
                         "500: An error has occurred at Snapchat's end.")
Ejemplo n.º 2
0
    def test_503_error_custom_message(self, mocked_time, mocked_request):
        """
            Test case to verify 503 error message from response
        """
        mocked_request.return_value = MockedResponse(503)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.Server5xxError) as e:
            clx.request('GET')

        self.assertEqual(str(e.exception),
                         "503: API service is currently unavailable.")
Ejemplo n.º 3
0
    def test_406_error_custom_message(self, mocked_request):
        """
            Test case to verify 406 error message from response
        """
        mocked_request.return_value = MockedResponse(406)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatNotAcceptableError) as e:
            clx.request('GET')

        self.assertEqual(str(e.exception),
                         "406: You requested a format that isn’t json.")
Ejemplo n.º 4
0
    def test_401_error_custom_message(self, mocked_request):
        """
            Test case to verify 401 error message from response
        """

        mocked_request.return_value = MockedResponse(401)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatUnauthorizedError) as e:
            clx.request('GET')

        self.assertEqual(str(e.exception),
                         "401: Unauthorized access for the URL.")
Ejemplo n.º 5
0
    def test_400_error_custom_message(self, mocked_request):
        """
            Test case to verify 400 error message from response
        """
        mocked_request.return_value = MockedResponse(400)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatBadRequestError) as e:
            clx.request('GET')

        self.assertEqual(
            str(e.exception),
            "400: The request is missing or has a bad parameter.")
Ejemplo n.º 6
0
    def test_410_error_custom_message(self, mocked_request):
        """
            Test case to verify 410 error message from response
        """
        mocked_request.return_value = MockedResponse(410)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatGoneError) as e:
            clx.request('GET')

        self.assertEqual(
            str(e.exception),
            "410: Access to the Snapchat is no longer available.")
Ejemplo n.º 7
0
    def test_405_error_custom_message(self, mocked_request):
        """
            Test case to verify 405 error message from response
        """
        mocked_request.return_value = MockedResponse(405)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatMethodNotAllowedError) as e:
            clx.request('GET')

        self.assertEqual(
            str(e.exception),
            "405: The provided HTTP method is not supported by the URL.")
Ejemplo n.º 8
0
    def test_404_error_custom_message(self, mocked_request):
        """
            Test case to verify 404 error message from response
        """
        mocked_request.return_value = MockedResponse(404)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatNotFoundError) as e:
            clx.request('GET')

        self.assertEqual(
            str(e.exception),
            "404: The resource you have specified cannot be found.")
Ejemplo n.º 9
0
    def test_connection_error(self, mocked_request, mocked_sleep):
        """
            Verify request function is backing off 7 times on the Connection exception for request function.
        """
        mocked_request.side_effect = requests.exceptions.ConnectionError
        client = SnapchatClient("test", "test", "test", 300, "test")

        with self.assertRaises(requests.exceptions.ConnectionError):
            client.request("get", "test", "test")

        # Verify that Session.send is called 5 times
        self.assertEqual(mocked_request.call_count, 7)
Ejemplo n.º 10
0
    def test_request_timeout_backoff(self, mocked_request, mocked_sleep):
        """
            Verify request function is backing off 7 times on the Timeout exception for request function.
        """
        mocked_request.side_effect = requests.exceptions.Timeout
        client = SnapchatClient("test", "test", "test", 300, "test")

        with self.assertRaises(requests.exceptions.Timeout):
            client.request("get", "test", "test")

        # Verify that Session.send is called 7 times
        self.assertEqual(mocked_request.call_count, 7)
Ejemplo n.º 11
0
    def test_403_error_custom_message(self, mocked_request):
        """
            Test case to verify 403 error message from response
        """

        mocked_request.return_value = MockedResponse(403)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatForbiddenError) as e:
            clx.request('GET')

        self.assertEqual(
            str(e.exception),
            "403: User does not have permission to access the resource.")
Ejemplo n.º 12
0
    def test_400_error_response_message(self, mocked_request):
        """
            Test case to verify 400 error message from response
        """

        mocked_request.return_value = MockedResponse(
            400, "This mesaage from response 400.")
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatBadRequestError) as e:
            clx.request('GET')

        self.assertEqual(str(e.exception),
                         "400: This mesaage from response 400.")
Ejemplo n.º 13
0
    def test_503_error_response_message(self, mocked_time, mocked_request):
        """
            Test case to verify 503 error message from response
        """

        mocked_request.return_value = MockedResponse(
            503, "This mesaage from response 503")
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.Server5xxError) as e:
            clx.request('GET')

        self.assertEqual(str(e.exception),
                         "503: This mesaage from response 503")
Ejemplo n.º 14
0
    def test_418_error_custom_message(self, mocked_request):
        """
            Test case to verify 418 error message from response
        """
        mocked_request.return_value = MockedResponse(418)
        clx = SnapchatClient("test", "test", "test", 300)
        with self.assertRaises(client.SnapchatTeapotError) as e:
            clx.request('GET')

        self.assertEqual(
            str(e.exception),
            "418: The server refuses to brew coffee because it is, permanently, a teapot."
        )