def test_1_url_not_found(self): recipe_model.RecipeTest().custom_test({"title": "a"}).insert() recipe_model.RecipeTest().custom_test({"title": "b"}).insert() """ cal api """ url = server.main_url + "/" + api.url + "x" response = requests.get(url, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 404) self.assertEqual( response.headers["Content-Type"], 'application/json', ) self.assertEqual(response_body[api.rep_code_status], 404) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_404_url)
def test_0_api_ok(self): tc_recipe1 = recipe_model.RecipeTest().custom_test({ "title": "a" }).insert() recipe_model.RecipeTest().custom_test({"title": "b"}).insert() tc_id = tc_recipe1.get_id() """ cal api """ url = server.main_url + "/" + api.url + "/" + tc_id response = requests.get(url, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 200) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 200) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_ok) self.assertEqual(response_body[api.rep_data], tc_recipe1.get_data_stringify_object_id())
def test_1_url_not_found(self): body = {api.param_title: "qa_rhr_title"} tc_recipe = recipe_model.RecipeTest().custom(body) """ cal api """ url = server.main_url + "/" + api.url + "x" response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 404) self.assertEqual(response.headers["Content-Type"], 'application/json', ) self.assertEqual(response_body[api.rep_code_status], 404) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_404_url) self.assertEqual(response_body[api.rep_detail], server.detail_url_not_found) tc_recipe.select_nok_by_title()
def test_2_id_object_id_invalid(self): recipe_model.RecipeTest().custom_test({"title": "a"}).insert() tc_id = "aaaaaaaaaaaaaaaaaaaaaaaa" """ cal api """ url = server.main_url + "/" + api.url + "/" + tc_id response = requests.get(url, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 404) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 404) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_404) self.assertEqual(response_body[api.rep_detail], "")
def test_11_title_already_exist(self): tc_recipe = recipe_model.RecipeTest().custom_test({}).insert() body = {api.param_title: tc_recipe.get_data_value("title")} """ cal api """ url = server.main_url + "/" + api.url response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 400) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 400) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_400) detail = api.create_detail(api.param_title, server.detail_already_exist, body[api.param_title]) self.assertEqual(response_body[api.rep_detail], detail) tc_recipe.select_ok()
def test_2_title_empty(self): body = {api.param_title: ""} tc_recipe = recipe_model.RecipeTest().custom(body) """ cal api """ url = server.main_url + "/" + api.url response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 400) self.assertEqual(response.headers["Content-Type"], 'application/json', ) self.assertEqual(response_body[api.rep_code_status], 400) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_400) detail = api.create_detail(api.param_title, server.detail_must_be_not_empty, body[api.param_title]) self.assertEqual(response_body[api.rep_detail], detail) tc_recipe.select_nok_by_title()
def test_10_steps_without(self): body = {api.param_title: "qa_rhr_title"} tc_recipe = recipe_model.RecipeTest().custom(body) """ cal api """ url = server.main_url + "/" + api.url response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 201) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 201) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_created) self.assertEqual(api.format_response(response_body[api.rep_data]), tc_recipe.get_data_without_id()) """ refacto """ tc_recipe.custom({"_id": response_body[api.rep_data]["_id"]}).select_ok()
def test_2_id_without(self): tc_recipe = recipe_model.RecipeTest().custom_test({"steps": ["a", "b"]}).insert() tc_id = "" body = {api.param_step: "new_step" } """ cal api """ url = server.main_url + "/" + api.url1 + "/" + tc_id + "/" + api.url2 response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 405) self.assertEqual(response.headers["Content-Type"], 'application/json', ) self.assertEqual(response_body[api.rep_code_status], 405) self.assertEqual(response_body[api.rep_detail], server.rep_code_msg_error_405) tc_recipe.select_ok()
def test_9_ingredients_string(self): body = {api.param_title: "qa_rhr_title", api.param_ingredients: "invalid"} tc_recipe = recipe_model.RecipeTest().custom(body) """ cal api """ url = server.main_url + "/" + api.url response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 400) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 400) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_400) detail = api.create_detail(api.param_ingredients, server.detail_must_be_an_object, body[api.param_ingredients]) self.assertEqual(response_body[api.rep_detail], detail) tc_recipe.select_nok_by_title()
def test_4_position_without(self): tc_recipe = recipe_model.RecipeTest().custom_test({"steps": ["a", "b"]}).insert() tc_id = tc_recipe.get_id() body = {api.param_step: "new_step"} """ cal api """ url = server.main_url + "/" + api.url1 + "/" + tc_id + "/" + api.url2 response = requests.post(url, json=body, verify=False) response_body = response.json() tc_recipe.custom({"steps": ["a", "b", "new_step"]}) """ assert """ self.assertEqual(response.status_code, 201) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 201) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_created) self.assertEqual(response_body[api.rep_data], tc_recipe.get_data_stringify_object_id()) tc_recipe.select_ok()
def test_3_step_object(self): tc_recipe = recipe_model.RecipeTest().custom_test({"steps": ["a", "b"]}).insert() tc_id = tc_recipe.get_id() body = {api.param_step: {}} """ cal api """ url = server.main_url + "/" + api.url1 + "/" + tc_id + "/" + api.url2 response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 400) self.assertEqual(response.headers["Content-Type"], 'application/json', ) self.assertEqual(response_body[api.rep_code_status], 400) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_400) detail = api.create_detail(api.param_step, server.detail_must_be_a_string, body[api.param_step]) self.assertEqual(response_body[api.rep_detail], detail) tc_recipe.select_ok()
def test_2_id_string(self): recipe_model.RecipeTest().custom_test({"title": "a"}).insert() tc_id = "invalid" """ cal api """ url = server.main_url + "/" + api.url + "/" + tc_id response = requests.get(url, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 400) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 400) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_400) detail = api.create_detail(api.param_id, server.detail_must_be_an_object_id, tc_id) self.assertEqual(response_body[api.rep_detail], detail)
def test_0_api_ok(self): tc_recipe = recipe_model.RecipeTest().custom_test({"steps": ["a", "b"]}).insert() tc_id = tc_recipe.get_id() tc_step_index = "1" """ cal api """ url = server.main_url + "/" + api.url1 + "/" + tc_id + "/" + api.url2 + "/" + tc_step_index response = requests.delete(url, verify=False) response_body = response.json() tc_recipe.custom({"steps": ["a"]}) """ assert """ print(response_body) self.assertEqual(response.status_code, 200) self.assertEqual(response.headers["Content-Type"], 'application/json') # self.assertEqual(response_body[api.rep_code_status], 201) # self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_created) # self.assertEqual(response_body[api.rep_data], tc_recipe.get_data_stringify_object_id()) tc_recipe.select_ok()
def test_1_url_not_found_2(self): tc_recipe = recipe_model.RecipeTest().custom_test({"steps": ["a", "b"]}).insert() tc_id = tc_recipe.get_id() body = {api.param_step: "new_step", "invalid": "invalid" } """ cal api """ url = server.main_url + "/" + api.url1 + "/" + tc_id + "/x" + api.url2 response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 404) self.assertEqual(response.headers["Content-Type"], 'application/json', ) self.assertEqual(response_body[api.rep_code_status], 404) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_error_404_url) self.assertEqual(response_body[api.rep_detail], server.detail_url_not_found) tc_recipe.select_ok()
import unittest import requests import factory as factory import recipe.recipe.model as recipe_model import recipe.recipe.test.PostRecipe.api as api server = factory.Server() api = api.PostRecipe() recipe = recipe_model.RecipeTest() class PostRecipe(unittest.TestCase): def setUp(self): recipe.clean() def test_0_api_ok(self): body = {api.param_title: "qa_rhr_title"} tc_recipe = recipe_model.RecipeTest().custom(body) """ cal api """ url = server.main_url + "/" + api.url response = requests.post(url, json=body, verify=False) response_body = response.json() """ assert """ self.assertEqual(response.status_code, 201) self.assertEqual(response.headers["Content-Type"], 'application/json') self.assertEqual(response_body[api.rep_code_status], 201) self.assertEqual(response_body[api.rep_code_msg], api.rep_code_msg_created) self.assertEqual(api.format_response(response_body[api.rep_data]), tc_recipe.get_data_without_id()) """ refacto """