summaryrefslogtreecommitdiff
path: root/tests/test_vgstash.py
blob: 43cd639b26cbd1d9caf3e4b3f6711883de063827 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import os
import pytest
import vgstash
import sqlite3

def test_config():
    assert vgstash.DEFAULT_CONFIG['db_location']
    assert vgstash.DEFAULT_CONFIG['progress'] in vgstash.PROGRESS.values()
    assert vgstash.DEFAULT_CONFIG['ownership'] in vgstash.OWNERSHIP.values()

@pytest.fixture(scope="module")
def vgstash_db():
    vgstash.DEFAULT_CONFIG['db_location'] = '.vgstash.db'
    yield vgstash.DB(vgstash.DEFAULT_CONFIG['db_location'])
    os.remove(vgstash.DEFAULT_CONFIG['db_location'])

def test_game_min():
    game = vgstash.Game("test_game1", "system3")
    assert isinstance(game, vgstash.Game)
    assert isinstance(game.title, str)
    assert isinstance(game.system, str)
    assert isinstance(game.ownership, int)
    assert isinstance(game.progress, int)
    assert isinstance(game.notes, str)
    assert game.ownership in vgstash.OWNERSHIP.values()
    assert game.progress in vgstash.PROGRESS.values()

def test_game_ownership():
    game = vgstash.Game("test_game2", "system3", 1)
    assert isinstance(game, vgstash.Game)
    assert isinstance(game.title, str)
    assert isinstance(game.system, str)
    assert isinstance(game.ownership, int)
    assert isinstance(game.progress, int)
    assert isinstance(game.notes, str)
    assert game.ownership in vgstash.OWNERSHIP.values()
    assert game.progress in vgstash.PROGRESS.values()

def test_game_ownership_str():
    game = vgstash.Game("test_game2", "system3", 'd')
    assert isinstance(game, vgstash.Game)
    assert isinstance(game.title, str)
    assert isinstance(game.system, str)
    assert isinstance(game.ownership, int)
    assert isinstance(game.progress, int)
    assert isinstance(game.notes, str)
    assert game.ownership in vgstash.OWNERSHIP.values()
    assert game.progress in vgstash.PROGRESS.values()

def test_game_progress():
    game = vgstash.Game("test_game3", "system3", progress=1)
    assert isinstance(game, vgstash.Game)
    assert isinstance(game.title, str)
    assert isinstance(game.system, str)
    assert isinstance(game.ownership, int)
    assert isinstance(game.progress, int)
    assert isinstance(game.notes, str)
    assert game.ownership in vgstash.OWNERSHIP.values()
    assert game.progress in vgstash.PROGRESS.values()

def test_game_progress_str():
    game = vgstash.Game("test_game3", "system3", progress='c')
    assert isinstance(game, vgstash.Game)
    assert isinstance(game.title, str)
    assert isinstance(game.system, str)
    assert isinstance(game.ownership, int)
    assert isinstance(game.progress, int)
    assert isinstance(game.notes, str)
    assert game.ownership in vgstash.OWNERSHIP.values()
    assert game.progress in vgstash.PROGRESS.values()

def test_game_notes_no_own_or_progress():
    game = vgstash.Game("test_game4", "system3", notes="Hello world")
    assert isinstance(game, vgstash.Game)
    assert isinstance(game.title, str)
    assert isinstance(game.system, str)
    assert isinstance(game.ownership, int)
    assert isinstance(game.progress, int)
    assert isinstance(game.notes, str)
    assert game.ownership in vgstash.OWNERSHIP.values()
    assert game.progress in vgstash.PROGRESS.values()

def test_game_full():
    game = vgstash.Game("test_game5", "system3", 'b', 2, "Blah")
    assert isinstance(game, vgstash.Game)
    assert isinstance(game.title, str)
    assert isinstance(game.system, str)
    assert isinstance(game.ownership, int)
    assert isinstance(game.progress, int)
    assert isinstance(game.notes, str)
    assert game.ownership in vgstash.OWNERSHIP.values()
    assert game.progress in vgstash.PROGRESS.values()

def test_db(vgstash_db):
    assert isinstance(vgstash_db.conn, sqlite3.Connection)

def test_db_create_schema(vgstash_db):
    assert vgstash_db.create_schema()

def test_db_add_game(vgstash_db):
    game = vgstash.Game("db_add_game", "system")
    assert vgstash_db.add_game(game)
    assert vgstash_db.has_game(game)

def test_db_add_game_ownership(vgstash_db):
    game = vgstash.Game("db_add_game_ownership", "system2", 'p')
    assert vgstash_db.add_game(game)
    assert vgstash_db.has_game(game)

def test_db_add_game_notes(vgstash_db):
    game = vgstash.Game("db_add_game_notes", "system2", '-', '-', 'my notes')
    assert vgstash_db.add_game(game)
    assert vgstash_db.has_game(game)

def test_db_update_game(vgstash_db):
    oldgame = vgstash.Game("db_add_game", "system")
    newgame = vgstash.Game("db_update_game", "system")
    if vgstash_db.has_game(oldgame):
        assert vgstash_db.update_game(oldgame, newgame)
        assert vgstash_db.has_game(newgame)

def test_db_delete_game(vgstash_db):
    game = vgstash.Game("db_delete_game", "system2")
    vgstash_db.add_game(game)
    assert vgstash_db.delete_game(game)

def test_db_list_games(vgstash_db):
    res = vgstash_db.list_games()
    assert isinstance(res, list)
    assert isinstance(res[0], sqlite3.Row)

def test_db_list_games_not_found(vgstash_db):
    res = vgstash_db.list_games("derp")
    assert res == False

def test_db_add_filter(vgstash_db):
    assert vgstash_db.add_filter("db_add_filter", "SELECT * FROM games WHERE system = 'system2'")
    assert vgstash_db.has_filter("db_add_filter")

def test_db_update_filter(vgstash_db):
    assert vgstash_db.update_filter("db_add_filter", "SELECT * FROM games WHERE system='system'")
    assert vgstash_db.has_filter("db_add_filter")
    assert "'system'" in vgstash.FILTERS["db_add_filter"]

def test_db_delete_filter(vgstash_db):
    assert vgstash_db.delete_filter("db_add_filter")

def test_db_list_filters(vgstash_db):
    assert len(vgstash_db.list_filters()) > 0