aboutsummaryrefslogtreecommitdiffstats
path: root/python_moondb/tests/unit_python/models/test_categories.py
blob: 0ffcf96ee72bceddbdc7065167214dda6a06435b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pytest
import logging
from python_moonutilities.exceptions import *

logger = logging.getLogger("moon.db.tests.models.test_categories")


def add_subject_category(cat_id=None, value=None):
    from python_moondb.core import ModelManager
    category = ModelManager.add_subject_category(user_id=None, category_id=cat_id, value=value)
    return category


def test_add_subject_category_twice():
    category = add_subject_category(value={"name":"category name", "description":"description 1"})
    category_id = list(category.keys())[0]
    assert category is not None
    with pytest.raises(SubjectCategoryExisting):
        add_subject_category(category_id, value={"name":"category name", "description":"description 2"})


def get_subject_category(cat_id=None):
    from python_moondb.core import ModelManager
    category = ModelManager.get_subject_categories(user_id=None, category_id=cat_id)
    return category


def test_get_subject_categories():
    added_category = add_subject_category(value={"name":"category name", "description":"description 1"})
    category_id = list(added_category.keys())[0]
    subject_category = get_subject_category(category_id)
    assert subject_category == added_category


def test_get_subject_categories_with_invalid_id():
    category_id = "invalid_id"
    subject_category = get_subject_category(category_id)
    assert len(subject_category) == 0


def add_object_category(cat_id=None, value=None):
    from python_moondb.core import ModelManager
    category = ModelManager.add_object_category(user_id=None, category_id=cat_id, value=value)
    return category


def test_add_object_category_twice():
    category = add_object_category(value={"name":"category name", "description":"description 1"})
    category_id = list(category.keys())[0]
    assert category is not None
    with pytest.raises(ObjectCategoryExisting):
        add_object_category(category_id, value={"name":"category name", "description":"description 2"})


def get_object_category(cat_id=None):
    from python_moondb.core import ModelManager
    category = ModelManager.get_object_categories(user_id=None, category_id=cat_id)
    return category


def test_get_object_categories():
    added_category = add_object_category(value={"name":"category name", "description":"description 1"})
    category_id = list(added_category.keys())[0]
    object_category = get_object_category(category_id)
    assert object_category == added_category


def test_get_object_categories_with_invalid_id():
    category_id = "invalid_id"
    object_category = get_object_category(category_id)
    assert len(object_category) == 0


def add_action_category(cat_id=None, value=None):
    from python_moondb.core import ModelManager
    category = ModelManager.add_action_category(user_id=None, category_id=cat_id, value=value)
    return category


def test_add_action_category_twice():
    category = add_action_category(value={"name":"category name", "description":"description 1"})
    category_id = list(category.keys())[0]
    assert category is not None
    with pytest.raises(ActionCategoryExisting):
        add_action_category(category_id, value={"name":"category name", "description":"description 2"})


def get_action_category(cat_id=None):
    from python_moondb.core import ModelManager
    category = ModelManager.get_action_categories(user_id=None, category_id=cat_id)
    return category


def test_get_action_categories():
    added_category = add_action_category(value={"name":"category name", "description":"description 1"})
    category_id = list(added_category.keys())[0]
    action_category = get_action_category(category_id)
    assert action_category == added_category


def test_get_action_categories_with_invalid_id():
    category_id = "invalid_id"
    action_category = get_action_category(category_id)
    assert len(action_category) == 0