Example #1
0
 def check_for_exception_message(self, message_key, **kwargs):
     """Check that the right exception / message is produced for
     given combination of arguments
     """
     # call the function to produce the exception
     try:
         pc = ParamConverter(**kwargs)
         assert pc
     except ParamConverterIllegalArgumentException as e:
         # exception produced, is it the right message?
         # messages can have values appended to them...
         desired_message = ILLEGAL_ARGUMENT_MESSAGES[message_key]
         # test passes if yes, fails if not
         assert str(e)[0:len(desired_message)] == desired_message
     else:
         # no exception produced, test fails
         assert False
Example #2
0
 def test_resolve_constructor_by_string_reference(self):
     pc = ParamConverter(
         constructor='tests.fixtures.custom_widget_finding_function',
         param='id')
     from tests.fixtures import custom_widget_finding_function
     assert pc.constructor == custom_widget_finding_function
Example #3
0
 def test_simple_callable(self):
     pc = ParamConverter(constructor=self.empty_callable, param='id')
     assert pc.constructor == self.empty_callable
Example #4
0
 def test_str_to_import_with_custom_constructor(self):
     pc = ParamConverter(graph_object='tests.fixtures.Widget',
                         constructor='custom_constructor',
                         param='id')
     assert pc.constructor == Widget.custom_constructor
Example #5
0
 def test_graph_object_with_constructor_attr(self):
     pc = ParamConverter(graph_object=Widget,
                         constructor='custom_constructor',
                         param='id')
     assert pc.constructor == Widget.custom_constructor
Example #6
0
 def test_simple_object(self):
     pc = ParamConverter(graph_object=Widget, param='id')
     assert pc.constructor == Widget.select
Example #7
0
    def test_with_callable(self):
        def c():
            return NotFound()

        assert isinstance(
            ParamConverter.resolve_to_return_callable(c)(), NotFound)
Example #8
0
 def test_with_int(self):
     assert ParamConverter.resolve_to_return_callable(500)() == 500
Example #9
0
 def test_on_not_found_assigned_properly(self):
     pc = ParamConverter(graph_object=Widget, param='id')
     assert pc.on_not_found() == 404
Example #10
0
 def test_on_more_than_one_assigned_properly(self):
     pc = ParamConverter(graph_object=Widget,
                         single=True,
                         check_unique=True,
                         param='id')
     assert pc.on_more_than_one() == 500