Beispiel #1
0
 def test_2_id_object_id_invalid(self):
     tc_ingredient1 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     tc_ingredient2 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     tc_id = "aaaaaaaaaaaaaaaaaaaaaaaa"
     """ cal api """
     url = server.main_url + "/" + api.url + "/" + tc_id
     response = requests.delete(url, verify=False)
     """ assert """
     self.assertEqual(response.status_code, 204)
     self.assertEqual(response.headers["Content-Type"], 'application/json')
     tc_ingredient1.select_ok()
     tc_ingredient2.select_ok()
Beispiel #2
0
 def test_2_id_without(self):
     tc_ingredient1 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     tc_ingredient2 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     """ cal api """
     url = server.main_url + "/" + api.url + "/"
     response = requests.delete(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)
     tc_ingredient1.select_ok()
     tc_ingredient2.select_ok()
Beispiel #3
0
 def test_0_api_ok(self):
     tc_ingredient1 = ingredient_model.IngredientTest().custom_test({
         "name":
         "a"
     }).insert()
     ingredient_model.IngredientTest().custom_test({"name": "b"}).insert()
     tc_id = tc_ingredient1.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_ingredient1.get_data_stringify_object_id())
Beispiel #4
0
 def test_4_name_already_exist(self):
     tc_ingredient1 = ingredient_model.IngredientTest().custom_test({"name": "a"}).insert()
     tc_ingredient2 = ingredient_model.IngredientTest().custom_test({"name": "b"}).insert()
     tc_id = tc_ingredient1.get_id()
     body = {api.param_name: tc_ingredient2.get_data_value("name")}
     """ cal api """
     url = server.main_url + "/" + api.url + "/" + tc_id
     response = requests.put(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_name, server.detail_already_exist, body[api.param_name])
     self.assertEqual(response_body[api.rep_detail], detail)
     tc_ingredient1.select_ok()
     tc_ingredient2.select_ok()
Beispiel #5
0
 def test_1_url_not_found(self):
     ingredient_model.IngredientTest().custom_test({"name": "a"}).insert()
     ingredient_model.IngredientTest().custom_test({"name": "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)
     self.assertEqual(response_body[api.rep_detail],
                      server.detail_url_not_found)
Beispiel #6
0
 def test_0_api_ok(self):
     tc_ingredient1 = ingredient_model.IngredientTest().custom_test({"name": "a"}).insert()
     tc_ingredient2 = ingredient_model.IngredientTest().custom_test({"name": "b"}).insert()
     tc_id = tc_ingredient1.get_id()
     body = {api.param_name: "qa_rhr_name_update"}
     """ cal api """
     url = server.main_url + "/" + api.url + "/" + tc_id
     response = requests.put(url, json=body, verify=False)
     response_body = response.json()
     tc_ingredient1.custom(body)
     """ 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_ingredient1.get_data_stringify_object_id())
     """ refacto """
     tc_ingredient1.select_ok()
     tc_ingredient2.select_ok()
Beispiel #7
0
 def test_2_id_string(self):
     tc_ingredient1 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     tc_ingredient2 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     tc_id = "invalid"
     """ cal api """
     url = server.main_url + "/" + api.url + "/" + tc_id
     response = requests.delete(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)
     tc_ingredient1.select_ok()
     tc_ingredient2.select_ok()
Beispiel #8
0
 def test_2_id_object_id_invalid(self):
     ingredient_model.IngredientTest().custom_test({"name": "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], "")
Beispiel #9
0
 def test_2_id_without(self):
     tc_ingredient = ingredient_model.IngredientTest().custom_test({"name": "a"}).insert()
     body = {api.param_name: "qa_rhr_name_update"}
     """ cal api """
     url = server.main_url + "/" + api.url + "/"
     response = requests.put(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_ingredient.select_ok()
Beispiel #10
0
 def test_1_url_not_found(self):
     tc_ingredient1 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     tc_ingredient2 = ingredient_model.IngredientTest().custom_test(
         {}).insert()
     tc_id = tc_ingredient1.get_id()
     """ cal api """
     url = server.main_url + "/" + api.url + "x/" + tc_id
     response = requests.delete(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)
     self.assertEqual(response_body[api.rep_detail],
                      server.detail_url_not_found)
     tc_ingredient1.select_ok()
     tc_ingredient2.select_ok()
Beispiel #11
0
 def test_2_id_object_id_invalid(self):
     tc_ingredient = ingredient_model.IngredientTest().custom_test({"name": "a"}).insert()
     tc_id = "aaaaaaaaaaaaaaaaaaaaaaaa"
     body = {api.param_name: "qa_rhr_name_update"}
     """ cal api """
     url = server.main_url + "/" + api.url + "/" + tc_id
     response = requests.put(url, json=body, 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_ingredient.select_ok()
Beispiel #12
0
 def test_3_name_without(self):
     tc_ingredient = ingredient_model.IngredientTest().custom_test({"name": "a"}).insert()
     tc_id = tc_ingredient.get_id()
     body = {}
     """ cal api """
     url = server.main_url + "/" + api.url + "/" + tc_id
     response = requests.put(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_name, server.detail_is_required, "missing")
     self.assertEqual(response_body[api.rep_detail], detail)
     tc_ingredient.select_ok()
Beispiel #13
0
 def test_1_url_not_found(self):
     body = {api.param_name: "qa_rhr_name"}
     tc_ingredient = ingredient_model.IngredientTest().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_ingredient.select_nok_by_name()
Beispiel #14
0
 def test_0_api_ok_more_param(self):
     body = {api.param_name: "qa_rhr_name", "invalid": "invalid"}
     tc_ingredient = ingredient_model.IngredientTest().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_ingredient.get_data_without_id())
     """ refacto """
     tc_ingredient.custom({
         "_id": response_body[api.rep_data]["_id"]
     }).select_ok()
Beispiel #15
0
 def test_2_name_none(self):
     body = {api.param_name: None}
     tc_ingredient = ingredient_model.IngredientTest().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_name,
                                server.detail_must_be_a_string,
                                body[api.param_name])
     self.assertEqual(response_body[api.rep_detail], detail)
     tc_ingredient.select_nok_by_name()
Beispiel #16
0
import unittest
import requests

import factory as factory
import ingredient.model as ingredient_model
import ingredient.test.GetIngredient.api as api

server = factory.Server()
api = api.GetIngredient()
ingredient = ingredient_model.IngredientTest()


class GetIngredient(unittest.TestCase):
    def setUp(self):
        ingredient.clean()

    def test_0_api_ok(self):
        tc_ingredient1 = ingredient_model.IngredientTest().custom_test({
            "name":
            "a"
        }).insert()
        ingredient_model.IngredientTest().custom_test({"name": "b"}).insert()
        tc_id = tc_ingredient1.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)