-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_auth.py
More file actions
56 lines (44 loc) · 1.7 KB
/
test_auth.py
File metadata and controls
56 lines (44 loc) · 1.7 KB
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
from pycamp_bot.models import Pycampista
from pycamp_bot.commands.auth import get_admins_username
from test.conftest import use_test_database, test_db, MODELS
def setup_module(module):
test_db.bind(MODELS, bind_refs=False, bind_backrefs=False)
test_db.connect()
def teardown_module(module):
test_db.drop_tables(MODELS)
test_db.close()
class TestGetAdminsUsername:
@use_test_database
def test_returns_empty_when_no_admins(self):
Pycampista.create(username="pepe", admin=False)
assert get_admins_username() == []
@use_test_database
def test_returns_admin_usernames(self):
Pycampista.create(username="admin1", admin=True)
result = get_admins_username()
assert result == ["admin1"]
@use_test_database
def test_excludes_non_admin_users(self):
Pycampista.create(username="admin1", admin=True)
Pycampista.create(username="user1", admin=False)
result = get_admins_username()
assert "admin1" in result
assert "user1" not in result
@use_test_database
def test_multiple_admins(self):
Pycampista.create(username="admin1", admin=True)
Pycampista.create(username="admin2", admin=True)
Pycampista.create(username="user1", admin=False)
result = get_admins_username()
assert len(result) == 2
assert "admin1" in result
assert "admin2" in result
@use_test_database
def test_admin_with_null_flag(self):
Pycampista.create(username="pepe", admin=None)
result = get_admins_username()
assert result == []
@use_test_database
def test_no_users_returns_empty(self):
result = get_admins_username()
assert result == []