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'))
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'))
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())))
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'))
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() )
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'))
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"), )
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
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())
def test_simple_valid(self): assert quiz.validate(Dog, _.name) == _.name
def test_empty(self): selection = SelectionSet() assert quiz.validate(Dog, selection) == SelectionSet()