Ejemplo n.º 1
0
class TestHttprettyBasicWithDecorator(base.UtilTestCase):
    @decorator.activate('localhost', HelloService())
    def test_basic(self):
        res = requests.get('http://localhost/hello/')
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.text, 'Hello')

    @decorator.activate('localhost', HelloService(), 200, value='Hello')
    def test_basic_with_parameters(self, response_code, value='alpha'):
        res = requests.get('http://localhost/hello/')
        self.assertEqual(res.status_code, response_code)
        self.assertEqual(res.text, value)

    @decorator.activate('localhost',
                        HelloService(),
                        200,
                        value='Hello',
                        access_services="stack")
    def test_basic_with_stack_acccess(self,
                                      response_code,
                                      value='alpha',
                                      stack=None):
        res = requests.get('http://localhost/hello/')
        self.assertEqual(res.status_code, response_code)
        self.assertEqual(res.text, value)
        self.assertEqual(len(stack), 1)
        self.assertTrue(self.hello_service.name in stack)
        self.assertIsInstance(stack[list(stack.keys())[0]], HelloService)
Ejemplo n.º 2
0
    def run():
        StackInABox.reset_services()
        StackInABox.register_service(HelloService())
        stackinabox.util.responses.registration('localhost')

        res = requests.get('http://localhost/hello/')
        assert res.status_code == 200
        assert res.text == 'Hello'
Ejemplo n.º 3
0
def test_basic_with_stack_acccess_and_list(*args, **kwargs):
    # note: work-around for pytest + Py3 and a decorator
    response_code = args[0]
    value = kwargs.get('value', 'alpha')
    stack = kwargs.get('stack', None)
    res = requests.get('http://localhost/hello/')
    assert res.status_code == response_code
    assert res.text == value
    assert len(stack) == 1
    assert HelloService().name in stack
    assert isinstance(stack[list(stack.keys())[0]], HelloService)
Ejemplo n.º 4
0
class TestHttprettyBasicWithDecoratorErrors(base.UtilTestCase):
    def test_basic(self):

        decor_instance = decorator.activate('localhost')
        with self.assertRaises(TypeError):
            decor_instance.process_service({}, raise_on_type=True)

    @decorator.stack_activate('localhost', HelloService())
    def test_deprecated(self):
        res = requests.get('http://localhost/hello/')
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.text, 'Hello')
Ejemplo n.º 5
0
def responses_list():
    return [HelloService()]
Ejemplo n.º 6
0
def responses_generator():
    yield HelloService()
Ejemplo n.º 7
0
def test_verify_generator():
    assert isinstance(responses_generator(), types.GeneratorType)


def test_verify_list():
    assert isinstance(responses_list(), collections.Iterable)


class TestDecoratorParameters(base.TestCase):
    def test_process_service_parameters(self):
        decor_instance = decorator.activate('localhost')
        with self.assertRaises(TypeError):
            decor_instance.process_service({}, raise_on_type=True)


@decorator.activate('localhost', HelloService())
def test_basic_responses():
    res = requests.get('http://localhost/hello/')
    assert res.status_code == 200
    assert res.text == 'Hello'


@decorator.stack_activate('localhost', HelloService())
def test_deprecated():
    res = requests.get('http://localhost/hello/')
    assert res.status_code == 200
    assert res.text == 'Hello'


@decorator.activate('localhost', responses_generator())
def test_basic_responses_and_generator():
Ejemplo n.º 8
0
def httpretty_generator():
    yield HelloService()
Ejemplo n.º 9
0
def httpretty_list():
    return [HelloService()]