예제 #1
0
    def test_json_call_if_unknown_return_type(self):
        """check ServiceException raised if unknown return_type"""

        request = Request().withType('unknownType').domain('domaintools.com')

        transport                         = Mock('RestService')
        transport.get_status.mock_returns = 200
        transport.get.mock_returns        = open(self.root_path + '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        request.set_transport(transport)

        self.assertTrue(json.loads(request.execute())!= None)
예제 #2
0
    def test_not_authorized_request_exception(self):
        """test NotAuthorizedException raised for status code 403"""

        request = Request().withType('json').domain('domaintools')

        transport = Mock('RestService')
        transport.get_status.mock_returns = 403
        transport.get.mock_returns = open(
            self.root_path +
            '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        request.set_transport(transport)

        try:
            request.execute()
        except NotAuthorizedException as e:
            self.assertTrue(True)

        def test_bad_request_exception(self):
            """test BadRequestException raised for status code 400"""

            request = Request().withType('json').domain('domaintools')

            transport = Mock('RestService')
            transport.get_status.mock_returns = 400
            transport.get.mock_returns = open(
                self.root_path +
                '/tests/fixtures/domain-profile/domaintools.com/good.json'
            ).read()
            request.set_transport(transport)

            try:
                request.execute()
            except BadRequestException as e:
                self.assertTrue(True)

        def test_not_found_request_exception(self):
            """test NotFoundException raised for status code 404"""

            request = Request().withType('json').domain('domaintools')

            transport = Mock('RestService')
            transport.get_status.mock_returns = 404
            transport.get.mock_returns = open(
                self.root_path +
                '/tests/fixtures/domain-profile/domaintools.com/good.json'
            ).read()
            request.set_transport(transport)

            try:
                request.execute()
            except NotFoundRequestException as e:
                self.assertTrue(True)
예제 #3
0
    def test_json_call_if_unknown_return_type(self):
        """check ServiceException raised if unknown return_type"""

        request = Request().withType('unknownType').domain('domaintools.com')

        transport = Mock('RestService')
        transport.get_status.mock_returns = 200
        transport.get.mock_returns = open(
            self.root_path +
            '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        request.set_transport(transport)

        self.assertTrue(json.loads(request.execute()) != None)
예제 #4
0
        def test_bad_request_exception(self):
            """test BadRequestException raised for status code 400"""

            request = Request().withType('json').domain('domaintools')

            transport                         = Mock('RestService')
            transport.get_status.mock_returns = 400
            transport.get.mock_returns        = open(self.root_path + '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
            request.set_transport(transport)

            try:
                request.execute()
            except BadRequestException as e:
                self.assertTrue(True)
예제 #5
0
    def test_service_unavailable_exception(self):
        """test ServiceUnavailableException raised for status code 503"""

        request = Request().withType('json').domain('domaintools')

        transport = Mock('RestService')
        transport.get_status.mock_returns = 503
        transport.get.mock_returns = open(
            self.root_path +
            '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        request.set_transport(transport)

        try:
            request.execute()
        except ServiceUnavailableException as e:
            self.assertTrue(True)
예제 #6
0
    def test_transport_called_on_get(self):
        """test transport is really called"""

        configuration = Configuration(self.root_path + "/domaintools/conf/api.ini")
        request       = Request(configuration)
        request.withType('json').domain('domaintools.com')

        transport                         = Mock('RestService')
        transport.get_status.mock_returns = 200
        transport.get.mock_returns        = open(self.root_path + '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        request.set_transport(transport)

        try:
            request.execute()
        except Exception as e:
            pass

        self.assertTrue(transport.get_status()==200)
예제 #7
0
    def test_transport_called_on_get(self):
        """test transport is really called"""

        configuration = Configuration(self.root_path +
                                      "/domaintools/conf/api.ini")
        request = Request(configuration)
        request.withType('json').domain('domaintools.com')

        transport = Mock('RestService')
        transport.get_status.mock_returns = 200
        transport.get.mock_returns = open(
            self.root_path +
            '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        request.set_transport(transport)

        try:
            request.execute()
        except Exception as e:
            pass

        self.assertTrue(transport.get_status() == 200)
예제 #8
0
class TestResponse(unittest.TestCase):

    def setUp(self):
        """to execute before each test"""

        self.root_path     = os.path.realpath(os.curdir)
        self.configuration = Configuration(self.root_path+'/domaintools/conf/api.ini')
        self.request       = Request(self.configuration)

        self.request.domain('domaintools.com')

        transport                         = Mock('RestService')
        transport.get_status.mock_returns = 200
        transport.get.mock_returns        = open(self.root_path + '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        self.request.set_transport(transport)

        self.response                     = self.request.execute()



    def test_request_attached_to_response(self):
        """check Request instance has been attached to Response instance"""

        self.assertTrue(self.request == self.response.request)
예제 #9
0
class TestResponse(unittest.TestCase):
    def setUp(self):
        """to execute before each test"""

        self.root_path = os.path.realpath(os.curdir)
        self.configuration = Configuration(self.root_path +
                                           '/domaintools/conf/api.ini')
        self.request = Request(self.configuration)

        self.request.domain('domaintools.com')

        transport = Mock('RestService')
        transport.get_status.mock_returns = 200
        transport.get.mock_returns = open(
            self.root_path +
            '/tests/fixtures/domain-profile/domaintools.com/good.json').read()
        self.request.set_transport(transport)

        self.response = self.request.execute()

    def test_request_attached_to_response(self):
        """check Request instance has been attached to Response instance"""

        self.assertTrue(self.request == self.response.request)