コード例 #1
0
    def test_pacifica_ci_bad_request(self):
        """test pacifica cart interface bad request method"""
        def start_response(*args):
            """stub for start_response to do some checking"""
            self.assertEqual(args[0], '501 Not Implemented')
            self.assertEqual(args[1][0][0], 'Content-Type')
            self.assertEqual(args[1][0][1], 'application/json')

        env = {'REQUEST_METHOD': 'IMNOTREAL', 'QUERY_STRING': ''}
        cgen = CartGenerator()
        message = cgen.pacifica_cartinterface(env, start_response)
        self.assertEqual(loads(message)['message'], 'Unknown request method')
コード例 #2
0
    def test_pacifica_ci_throw_error(self):
        """test pacifica cart interface throw exception"""
        def start_response(*args):
            """stub for start_response to do some checking"""
            self.assertEqual(args[0], '500 Internal Server Error')
            self.assertEqual(args[1][0][0], 'Content-Type')
            self.assertEqual(args[1][0][1], 'application/json')

        def fake_get(other_self, env, other_start_response):
            """fake the get method"""
            self.assertTrue(not other_self is None)
            self.assertEqual(env['REQUEST_METHOD'], 'GET')
            self.assertEqual(start_response, other_start_response)
            raise CartInterfaceError('This is an error')

        env = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': ''}
        cgen = CartGenerator()
        cgen.get = MethodType(fake_get, cgen)
        message = cgen.pacifica_cartinterface(env, start_response)
        self.assertEqual(
            loads(message)['message'], 'Unknown Exception Occured')
コード例 #3
0
    def test_pacifica_cartinterface(self):
        """test pacifica cart interface"""

        ####
        # this is going to be tricky we need to override the methods we tested
        # above so we don't need to make an super test harness
        # used to validate start_response, not actually calling it so no coverage
        # Stubs out the response
        ####
        # pylint: disable=unused-argument
        def start_response(*args):  # pragma no cover
            """stub for start_response to do some checking"""
            pass

        # pylint: enable=unused-argument
        env = {
            'REQUEST_METHOD': '',
            'called_get': False,
            'called_status': False,
            'called_stage': False,
            'called_delete': False
        }

        def fake_get(other_self, env, other_start_response):
            """fake the get method"""
            self.assertTrue(not other_self is None)
            self.assertEqual(env['REQUEST_METHOD'], 'GET')
            self.assertEqual(start_response, other_start_response)
            env['called_get'] = True
            return 'this is get()'

        def fake_status(other_self, env, other_start_response):
            """fake the get method"""
            self.assertTrue(not other_self is None)
            self.assertEqual(env['REQUEST_METHOD'], 'HEAD')
            self.assertEqual(start_response, other_start_response)
            env['called_status'] = True
            return 'this is status()'

        def fake_stage(other_self, env, other_start_response):
            """fake the stage method"""
            self.assertTrue(not other_self is None)
            self.assertEqual(env['REQUEST_METHOD'], 'POST')
            self.assertEqual(start_response, other_start_response)
            env['called_stage'] = True
            return 'this is stage()'

        def fake_delete(other_self, env, other_start_response):
            """fake the delete method"""
            self.assertTrue(not other_self is None)
            self.assertEqual(env['REQUEST_METHOD'], 'DELETE')
            self.assertEqual(start_response, other_start_response)
            env['called_delete'] = True
            return 'this is delete()'

        cgen = CartGenerator()
        cgen.get = MethodType(fake_get, cgen)
        cgen.status = MethodType(fake_status, cgen)
        cgen.stage = MethodType(fake_stage, cgen)
        cgen.delete_cart = MethodType(fake_delete, cgen)
        for method, message in [('GET', 'this is get()'),
                                ('HEAD', 'this is status()'),
                                ('POST', 'this is stage()'),
                                ('DELETE', 'this is delete()')]:
            env['REQUEST_METHOD'] = method
            chk_message = cgen.pacifica_cartinterface(env, start_response)
            self.assertEqual(message, chk_message)
        self.assertTrue(env['called_get'])
        self.assertTrue(env['called_stage'])
        self.assertTrue(env['called_status'])
        self.assertTrue(env['called_delete'])