def test_return_of_custom_error_message_in_nested_object(self): schema = { 'type': 'object', 'required': ['name', 'age', 'club_name'], 'properties': { 'name': { 'type': 'object', 'required': ['first_name', 'last_name'], 'properties': { 'first_name': {'type': 'string', 'message': 'Hello World'}, 'last_name': {'type': 'string'} } }, 'age': {'type': 'integer'}, 'club_name': {'type': 'string'} } } payload = { 'name': { 'first_name': 666, 'last_name': 'Tardelli', }, 'age': 31, 'club_name': 'Clube Atletico Mineiro' } error = validate(payload, schema) expected = "Validation of property 'first_name' failed: Hello World" self.assertEqual(expected, error)
def get_element(self, param, value): # Метод в дополнение к get запросу валилирует параметр из ответа r = requests.get(self.url) error = validate(r.json(), self.schema) assert error == None assert r.status_code == 200 assert r.json()[param] == value
def test_required_property_validation_in_nested_object(self): payload = { 'name': { 'last_name': 'Tardelli' }, 'age': 27, 'club_name': 'Clube Atletico Mineiro' } error = validate(payload, self.nested_schema) expected = "'first_name' is a required property" self.assertEqual(expected, error)
def test_nested_object_passing_validation(self): payload = { 'name': { 'first_name': 'Diego', 'last_name': 'Tardelli', }, 'age': 26, 'club_name': 'Clube Atletico Mineiro' } error = validate(payload, self.nested_schema) self.assertEqual(None, error)
def test_return_of_custom_error_message_in_flat_object(self): schema = { 'type': 'object', 'properties': { 'name': {'type': 'string', 'message': 'Foo bar'}, 'surname': {'type': 'string'}, }, 'required': [ 'name', 'surname' ] } error = validate({'name': 666, 'surname': 'Maus'}, schema) expected = "Validation of property 'name' failed: Foo bar" self.assertEqual(expected, error)
def test_return_of_validation_rule_in_nested_object(self): payload = { 'name': { 'first_name': 66, 'last_name': 'Tardelli', }, 'age': 76, 'club_name': 'Clube Atletico Mineiro' } error = validate(payload, self.nested_schema) self.assertTrue("Validation of property 'first_name' failed:" in error) self.assertTrue("'minLength': 2" in error) self.assertTrue("'type': 'string'" in error) self.assertTrue("'maxLength': 50" in error)
def patch_simple(self): r = requests.patch(self.url, data=self.payload) error = validate(r.json(), self.schema) assert error == None assert r.status_code == 200
def post_simple(self): #Метод отправляет post запрос r = requests.post(self.url, data=self.payload) error = validate(r.json(), self.schema) assert error == None assert r.status_code == 201
def get_payload(self): # Метод отправляет get запрос с параметрами r = requests.get(self.url, params=self.payload) error = validate(r.json(), self.schema) assert error == None assert r.status_code == 200
def get_simple(self): # Метод отправляет простой get запрос, валидирует json и код ответа r = requests.get(self.url) error = validate(r.json(), self.schema) assert error == None assert r.status_code == 200
def test_return_of_validation_rule_in_flat_object(self): error = validate({'name': 666, 'surname': 'Maus'}, self.flat_schema) expected = "Validation of property 'name' failed: {'type': 'string'}" self.assertEqual(expected, error)
def test_required_property_validation_with_other_property_present(self): error = validate({'name': 'John'}, self.flat_schema) expected = "'surname' is a required property" self.assertEqual(expected, error)
def test_required_property_validation_with_empty_payload(self): error = validate({}, self.flat_schema) expected = "'name' is a required property" self.assertEqual(expected, error)
def test_flat_object_passing_validation(self): error = validate({'name': 'John', 'surname': 'Maus'}, self.flat_schema) self.assertEqual(None, error)