Test Failed
Push — main ( 3c00a2...7c8c49 )
by torrua
02:08
created

tests.test_model_init   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 72
dl 0
loc 99
rs 10
c 0
b 0
f 0
wmc 13
1
# -*- coding: utf-8 -*-
2
# pylint: disable=R0201, R0903
3
4
"""HTML Model unit tests."""
5
6
import pytest
7
8
from loglan_db.model import Word
9
from tests.data import word_1, words
10
from tests.functions import db_add_and_return, db_add_object, db_add_objects
11
from loglan_db.model_init import InitBase
12
13
14
@pytest.mark.usefixtures("db")
15
class TestInitBase:
16
    """InitBase class tests."""
17
18
    def test___repr__(self):
19
        w = InitBase()
20
        result = w.__repr__()
21
        assert isinstance(result, str)
22
23
    def test___str__(self):
24
        db_add_object(Word, word_1)
25
        w = Word.get_by_id(word_1.get("id"))
26
        result = w.__str__()
27
        assert result == \
28
            "{'TID_old': None, 'event_end_id': None, 'event_start_id': 1, 'id': 7316, " \
29
            "'id_old': 7191, 'match': '', 'name': 'prukao', 'notes': None, 'origin': 'pru(ci)+ka(kt)o', " \
30
            "'origin_x': 'test act', 'rank': '1.9', 'type_id': 5, 'year': datetime.date(1975, 1, 1)}"
31
32
    def test_from_dict(self):
33
        w = Word.from_dict(word_1)
34
        assert w.name == "prukao"
35
36
37
@pytest.mark.usefixtures("db")
38
class TestDBBase:
39
    """DBBase class tests."""
40
41
    @staticmethod
42
    def test_save():
43
        w = Word(**word_1)
44
        assert w.save() is None
45
46
    @staticmethod
47
    def test_update():
48
        w = db_add_and_return(Word, word_1)
49
        assert w.update({'name': 'test', }) is None
50
51
    @staticmethod
52
    def test_delete():
53
        w = db_add_and_return(Word, word_1)
54
        assert w.delete() is None
55
56
    def test_get_all(self):
57
        db_add_objects(Word, words)
58
        words_from_db = Word.get_all()
59
        assert isinstance(words_from_db, list)
60
        assert len(words_from_db) == 6
61
62
    def test_attributes_all(self):
63
        result = Word.attributes_all()
64
        assert sorted(result) == [
65
            'TID_old', 'authors', 'created', 'definitions',
66
            'event_end', 'event_end_id', 'event_start',
67
            'event_start_id', 'id', 'id_old', 'match', 'name',
68
            'notes', 'origin', 'origin_x', 'rank', 'type',
69
            'type_id', 'updated', 'year']
70
71
    def test_attributes_basic(self):
72
        result = Word.attributes_basic()
73
        assert sorted(result) == [
74
            'TID_old', 'created', 'event_end_id', 'event_start_id',
75
            'id', 'id_old', 'match', 'name', 'notes', 'origin',
76
            'origin_x', 'rank', 'type_id', 'updated', 'year']
77
78
    def test_attributes_extended(self):
79
        result = Word.attributes_extended()
80
        assert sorted(result) == [
81
            'TID_old', 'authors', 'created', 'definitions', 'event_end',
82
            'event_start', 'id', 'id_old', 'match', 'name', 'notes',
83
            'origin', 'origin_x', 'rank', 'type', 'updated', 'year']
84
85
    def test_relationships(self):
86
        result = Word.relationships()
87
        assert sorted(result) == [
88
            'authors', 'definitions', 'event_end', 'event_start', 'type']
89
90
    def test_foreign_keys(self):
91
        result = Word.foreign_keys()
92
        assert sorted(result) == ['event_end_id', 'event_start_id', 'type_id']
93
94
    def test_non_foreign_keys(self):
95
        result = Word.non_foreign_keys()
96
        assert sorted(result) == [
97
            'TID_old', 'created', 'id', 'id_old', 'match', 'name',
98
            'notes', 'origin', 'origin_x', 'rank', 'updated', 'year']
99