示例#1
0
 def test_14_del_fail(self):
     ">X< Delete superhero by id: negative 4xx"
     my_id = 999        #999999
     r = s.get_superheroes(my_id)
     r_format = s.req_info(r)
     self.assertNotEqual(r_format[0], 200, msg=f"Status code is: {r_format[0]}, wait 4xx")
     r = s.del_superheroes(my_id)
     r_format = s.req_info(r)
     self.assertNotEqual(r_format[0], 200, msg=f"Status code is: {r_format[0]}, wait 4xx") 
示例#2
0
 def test_11_del_ok(self):
     ">X< Delete superhero by id: positive"
     try:
         my_id = get_hero_id()
     except (KeyError, ValueError) as e:
         my_id = "Error get id"
     r = s.del_superheroes(my_id)
     r_format = s.req_info(r)
     self.assertEqual(r_format[0], 200, msg=f"Status code is: {r_format[0]}, expected: 200")
     sleep(1)
     r = s.get_superheroes(my_id)
     r_format = s.req_info(r)
     self.assertNotEqual(r_format[0], 200, msg=f"Status code is: {r_format[0]}, wait 4xx")
示例#3
0
 def test_02_post_fail(self):
     "=> Send and chek new superhero: negative 403"
     hero = get_hero_data(False)
     r = s.post_superheroes(hero)
     r_format = s.req_info(r)
     self.assertEqual(r_format[0], 403, 
         msg=f"Status code is: {r_format[0]}, expected: 403\n{r_format[1]}\n{hero}")
示例#4
0
 def test_04_get_ok(self):
     "=> Get all superhero: positive"
     r = s.get_superheroes()
     r_format = s.req_info(r)
     self.assertEqual(r_format[0], 200, msg=f"Status code is: {r_format[0]}, expected: 200")
     self.assertIsInstance(r_format[1], list, msg=f"Expected list, get {type(r_format[1])}")
     self.assertIsInstance(r_format[1][0], dict, msg=f"Expected dict, get {type(r_format[1][0])}")
示例#5
0
 def test_03_post_fail(self):
     "=> Send and chek new superhero: negative 400"
     hero = hd6
     r = s.post_superheroes(hero)
     r_format = s.req_info(r)
     self.assertEqual(r_format[0], 400, 
         msg=f"Status code is: {r_format[0]}, expected: 400\n{r_format[1]}\n{hero}")
示例#6
0
 def test_01_post_ok(self):
     "=> Send and chek new superhero: positive"
     hero = get_hero_data()
     r = s.post_superheroes(hero)
     r_format = s.req_info(r)
     del r_format[1]['id']
     self.assertEqual(r_format[0], 200, msg=f"Status code is: {r_format[0]}, expected: 200")
     msg=f"The data received is different from the data sent\nsend:{hero}\nget:{r_format[1]}"
     self.assertDictEqual(r_format[1], hero, msg=msg)
示例#7
0
def get_hero_id():
    r = s.get_superheroes()
    r_format = s.req_info(r)
    hero = random.choice(r_format[1])
    try:
        my_id = hero['id']
    except (KeyError, ValueError) as e:
        my_id = "Error get id"
    return my_id
示例#8
0
 def test_10_put_fail(self):
     "U> Update superhero by id: negative 400"
     try:
         my_id = get_hero_id()
     except (KeyError, ValueError) as e:
         my_id = "Error get id"
     self.assertNotEqual(my_id,"Error get id", msg=my_id)
     upd_for_hero = hd6
     r = s.put_superheroes(my_id,upd_for_hero)
     r_format = s.req_info(r)
     msg = f"Status code is: {r_format[0]}, expected: 400\nsend:{upd_for_hero}\nid:{my_id}\nget:{r_format[1]}"
     self.assertEqual(r_format[0], 400, msg=msg)
示例#9
0
 def test_05_get_ok(self):
     "=> Get superhero by id: positive"
     try:
         my_id = get_hero_id()
     except (KeyError, ValueError) as e:
         my_id = "Error get id"
     r = s.get_superheroes(my_id)
     r_format = s.req_info(r)
     my_hero = r_format[1]
     msg = f"Status code is: {r_format[0]}, expected: 200\nid:{my_id}\nget:{my_hero}"
     self.assertEqual(r_format[0], 200, msg=msg)
     msg = f"The data received is different from the data sent\nget:{my_hero}\nid:{my_id}"
     self.assertIsInstance(my_hero, dict, msg=f"Expected dict, get {my_hero}")
示例#10
0
 def test_08_put_ok(self):
     "U> Update superhero by id: positive"
     try:
         my_id = get_hero_id()
     except (KeyError, ValueError) as e:
         my_id = "Error get id"
     r = s.get_superheroes(my_id)
     r_format = s.req_info(r)
     hero = r_format[1]
     upd_for_hero = get_hero_data()
     del upd_for_hero['phone']
     r = s.put_superheroes(my_id,upd_for_hero)
     r_format = s.req_info(r)
     
     msg = f"Status code is: {r_format[0]}, expected: 200\nsend:{hero}\nid:{my_id}\nget:{r_format[1]}"
     self.assertEqual(r_format[0], 200, msg=msg)
     r = s.get_superheroes(my_id)
     r_format = s.req_info(r)
     msg = f"Status code is: {r_format[0]}, expected: 200\nsend:{hero}\nid:{my_id}\nget:{r_format[1]}"
     self.assertEqual(r_format[0], 200, msg=msg)
     del r_format[1]['id']
     del r_format[1]['phone']
     msg = f"The data received is different from the data sent\nsend:{upd_for_hero}\nid:{my_id}\nget:{r_format[1]}"
     self.assertDictEqual(r_format[1], upd_for_hero, msg=msg)
示例#11
0
 def test_13_del_fail(self):
     ">X< Delete superhero by id: negative 400"
     my_id = "aa"#999#999999
     r = s.del_superheroes(my_id)
     r_format = s.req_info(r)
     self.assertEqual(r_format[0], 400, msg=f"Status code is: {r_format[0]}, wait 400") 
示例#12
0
 def test_07_get_fail(self):
     "=> Get superhero: negative get with 0"
     r = s.get_superheroes(0)
     r_format = s.req_info(r)
     self.assertEqual(r_format[0], 400, msg=f"Status code is: {r_format[0]}, expected: 400")
示例#13
0
 def test_06_get_fail(self):
     "=> Get superhero: negative get w/o id"
     r = s.get_superheroes(None, "sh")
     r_format = s.req_info(r)
     self.assertEqual(r_format[0], 404, msg=f"Status code is: {r_format[0]}, expected: 404")