Exemplo 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.")
Exemplo 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.")
Exemplo 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.")
Exemplo n.º 4
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.")
Exemplo n.º 5
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.")
Exemplo n.º 6
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.")
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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.")
Exemplo n.º 10
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.")
Exemplo n.º 11
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."
        )
Exemplo n.º 12
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.")
Exemplo n.º 13
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.")
Exemplo n.º 14
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")
Exemplo n.º 15
0
    def test_no_timeout_value_in_config(self):
        """
        Unit test to ensure that default "request_timeout" value is used when "requst_timeout"  is not passed in config
        """
        client = SnapchatClient("test", "test", "test", None, "test")

        # verify that the SnapchatClient has expected timeout value
        self.assertEqual(client.request_timeout, 300)
Exemplo n.º 16
0
    def test_string_zero_timeout_value_in_config(self):
        """
        Unit tests to ensure that "request_timeout" is set based on default value if string 0  is given in config
        """
        client = SnapchatClient("test", "test", "test", "0", "test")

        # verify that the SnapchatClient has expected timeout value
        self.assertEqual(client.request_timeout, 300)
Exemplo n.º 17
0
    def test_float_timeout_value_in_config(self):
        """
        Unit tests to ensure that "request_timeout" is set based on config float value
        """

        client = SnapchatClient("test", "test", "test", 100.10, "test")

        # verify that the SnapchatClient has expected timeout value
        self.assertEqual(client.request_timeout, 100.10)
Exemplo n.º 18
0
    def test_wrong_string_timeout_value_in_config(self):
        """
        Unit tests to ensure that exception is raised when "request_timeout" is given in alphabet string
        """

        # Create SnapchatClient object
        with self.assertRaises(Exception) as e:
            client = SnapchatClient("test", "test", "test", "abc", "test")

        self.assertEqual(str(e.exception),
                         "could not convert string to float: 'abc'",
                         "Enter timeout in numerics")
Exemplo n.º 19
0
    def test_request_connection_error_for_Snapchat_client(
            self, mocked_request, mocked_sleep):
        """
            Verify request function is backing off 5 times on the Connection exception for SnapchatClient creation.
        """
        mocked_request.side_effect = requests.exceptions.ConnectionError

        try:
            with SnapchatClient("test", "test", "test", 300, "test") as client:
                pass
        except requests.exceptions.ConnectionError:
            pass

        # verify that we backoff for 5 times
        self.assertEqual(mocked_request.call_count, 7)