Exemple #1
0
 def test_base_url_with_services(self):
     theStack = stack.StackInABox()
     theStack.register(hello.HelloService())
     self.assertEqual(theStack.base_url, '/')
     new_url = 'https://matrimony'
     theStack.base_url = new_url
     self.assertEqual(theStack.base_url, new_url)
Exemple #2
0
 def test_base_url_no_services(self):
     theStack = stack.StackInABox()
     self.assertEqual(theStack.base_url, '/')
     self.assertEqual(theStack.services, {})
     new_url = 'https://matrimony'
     theStack.base_url = new_url
     self.assertEqual(theStack.base_url, new_url)
Exemple #3
0
    def test_from_hold(self):
        theStack = stack.StackInABox()
        self.assertEqual(theStack.holds, {})

        item_name = 'ring'
        item_value = 'engagement-band'

        theStack.holds[item_name] = item_value
        self.assertEqual(theStack.from_hold(item_name), item_value)
Exemple #4
0
    def test_double_service_registration(self):
        service1 = hello.HelloService()
        service2 = hello.HelloService()

        theStack = stack.StackInABox()

        theStack.register(service1)
        with self.assertRaises(stack.ServiceAlreadyRegisteredError):
            theStack.register(service2)
Exemple #5
0
    def test_into_hold(self):
        theStack = stack.StackInABox()
        self.assertEqual(theStack.holds, {})

        item_name = 'ring'
        item_value = 'wedding-band'

        theStack.into_hold(item_name, item_value)
        self.assertIn(item_name, theStack.holds)
        self.assertEqual(item_value, theStack.holds[item_name])
Exemple #6
0
 def test_call_basic(self):
     theStack = stack.StackInABox()
     theStack.register(hello.HelloService())
     theStack.base_url = 'localhost'
     result = theStack.call('GET', mock.MagicMock(), 'localhost/hello/', {})
     self.assertEqual(len(result), 3)
     status_code, headers, msg = result
     self.assertEqual(status_code, 200)
     self.assertEqual(headers, {})
     self.assertEqual('Hello', msg)
Exemple #7
0
 def test_register(self):
     service = hello.HelloService()
     theStack = stack.StackInABox()
     self.assertEqual(theStack.services, {})
     theStack.register(service)
     self.assertIn(service.name, theStack.services)
     self.assertEqual(len(theStack.services[service.name]), 2)
     matcher, stored_service = theStack.services[service.name]
     self.assertEqual(service, stored_service)
     self.assertIsInstance(matcher, type(re.compile('')))
Exemple #8
0
 def test_call_no_service_matches(self, services_to_register):
     theStack = stack.StackInABox()
     theStack.base_url = 'localhost'
     for svc in services_to_register:
         theStack.register(svc)
     result = theStack.call('GET', mock.MagicMock(), 'localhost/except/',
                            {})
     self.assertEqual(len(result), 3)
     status_code, headers, msg = result
     self.assertEqual(status_code, 597)
     self.assertEqual(headers, {})
     self.assertIn('Unknown service', msg)
Exemple #9
0
    def test_call_service_exception(self):
        theStack = stack.StackInABox()
        exceptional = ExceptionalServices()
        theStack.register(exceptional)
        theStack.base_url = 'localhost'

        result = theStack.call('GET', mock.MagicMock(), 'localhost/except/',
                               {})
        self.assertEqual(len(result), 3)
        status_code, headers, msg = result
        self.assertEqual(status_code, 596)
        self.assertEqual(headers, {})
        self.assertIn('Service Handler had an error', msg)
Exemple #10
0
    def test_reset(self, service_count, hold_count):
        theStack = stack.StackInABox()
        self.assertEqual(theStack.services, {})
        self.assertEqual(theStack.holds, {})
        for service_number in range(service_count):
            name = 'service{0}'.format(service_number)
            theStack.services[name] = (service_number, hello.HelloService())

        for hold_number in range(hold_count):
            hold_key = 'hold{0}'.format(hold_number)
            theStack.holds[hold_key] = hold_number

        self.assertEqual(len(theStack.services), service_count)
        self.assertEqual(len(theStack.holds), hold_count)

        theStack.reset()
        self.assertEqual(theStack.services, {})
        self.assertEqual(theStack.holds, {})
Exemple #11
0
 def test_instantiation(self):
     theStack = stack.StackInABox()
     self.assertEqual(theStack.base_url, '/')
     self.assertEqual(theStack.services, {})
     self.assertEqual(theStack.holds, {})