From 17f207b265fca901580327a417d6065164623d33 Mon Sep 17 00:00:00 2001 From: Josh Santos Date: Mon, 21 Sep 2020 01:49:28 +0700 Subject: [PATCH] Add test for Item model --- .../services/items/tests/fixtures/item.json | 4 ++++ .../services/items/tests/test_items.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/fixtures/item.json create mode 100644 cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/test_items.py diff --git a/cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/fixtures/item.json b/cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/fixtures/item.json new file mode 100644 index 0000000..0b6731b --- /dev/null +++ b/cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/fixtures/item.json @@ -0,0 +1,4 @@ +{ + "name": "test" +} + diff --git a/cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/test_items.py b/cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/test_items.py new file mode 100644 index 0000000..18f53e7 --- /dev/null +++ b/cookiecutter/app/default/{{cookiecutter.app}}/{{cookiecutter.app}}/services/items/tests/test_items.py @@ -0,0 +1,16 @@ +import pytest +import json +from pydantic import ValidationError +from {{cookiecutter.app}}.services.items.model import Items + +def test_create_item(): + with open("fixtures/item.json") as item_json_file: + item_json = json.load(item_json_file) + try: + item = Items(**item_json) + except ValidationError as error: + err_str = "" + for err_obj in error.errors(): + err_str += "{} gave error {}\r\n".format(err_obj["loc"][0], err_obj["msg"]) + pytest.fail(err_str) +