Exemple #1
0
 def test_invalid_argument_type_optional(self):
     selection_set = _.is_housetrained(at_other_homes='foo')
     with pytest.raises(quiz.SelectionError) as exc:
         quiz.validate(Dog, selection_set)
     assert exc.value == quiz.SelectionError(
         Dog, 'is_housetrained',
         quiz.InvalidArgumentType('at_other_homes', 'foo'))
Exemple #2
0
    def test_missing_arguments(self):
        selection_set = _.knows_command
        with pytest.raises(quiz.SelectionError) as exc:
            quiz.validate(Dog, selection_set)

        assert exc.value == quiz.SelectionError(
            Dog, 'knows_command', quiz.MissingArgument('command'))
Exemple #3
0
 def test_nested_selection_error(self):
     with pytest.raises(quiz.SelectionError) as exc:
         quiz.validate(Dog, _.owner[_.hobbies[_.foo]])
     assert exc.value == quiz.SelectionError(
         Dog, 'owner',
         quiz.SelectionError(
             Human, 'hobbies',
             quiz.SelectionError(Hobby, 'foo', quiz.NoSuchField())))
Exemple #4
0
    def test_invalid_argument_type(self):
        selection_set = _.knows_command(command='foobar')
        with pytest.raises(quiz.SelectionError) as exc:
            quiz.validate(Dog, selection_set)

        assert exc.value == quiz.SelectionError(
            Dog, 'knows_command',
            quiz.InvalidArgumentType('command', 'foobar'))
Exemple #5
0
 def test_selection_set_on_non_object(self):
     with pytest.raises(quiz.SelectionError) as exc:
         quiz.validate(Dog, _.name[_.foo])
     assert exc.value == quiz.SelectionError(
         Dog,
         'name',
         quiz.SelectionsNotSupported()
     )
Exemple #6
0
 def test_invalid_argument(self):
     with pytest.raises(quiz.SelectionError) as exc:
         quiz.validate(Dog, _.knows_command(
             foo=1, command=Command.SIT))
     assert exc.value == quiz.SelectionError(
         Dog,
         'knows_command',
         quiz.NoSuchArgument('foo'))
Exemple #7
0
 def test_invalid_argument_type_optional(self):
     selection_set = _.is_housetrained(at_other_homes="foo")
     with pytest.raises(quiz.SelectionError) as exc:
         quiz.validate(Dog, selection_set)
     assert exc.value == quiz.SelectionError(
         Dog,
         "is_housetrained",
         quiz.InvalidArgumentType("at_other_homes", "foo"),
     )
Exemple #8
0
 def test_complex_valid(self):
     selection_set = (
         _.name.knows_command(command=Command.SIT)
         .is_housetrained.owner[_.name.hobbies[_.name.cool_factor]]
         .best_friend[_.name]
         .age(on_date=MyDateTime(datetime.now()))
     )
     assert quiz.validate(Dog, selection_set) == selection_set
Exemple #9
0
 def test_no_such_field(self):
     with pytest.raises(quiz.SelectionError) as exc:
         quiz.validate(Dog, _.name.foo.knows_command(command=Command.SIT))
     assert exc.value == quiz.SelectionError(Dog, 'foo', quiz.NoSuchField())
Exemple #10
0
 def test_simple_valid(self):
     assert quiz.validate(Dog, _.name) == _.name
Exemple #11
0
 def test_empty(self):
     selection = SelectionSet()
     assert quiz.validate(Dog, selection) == SelectionSet()