test_groups.py 3.51 KB
Newer Older
1
import mcommunity
Rob Carleski's avatar
Rob Carleski committed
2
3
4
5
6
7
8
9
10

config = {
    'client_id': '1234567890',
    'secret': '123abc-456def-789ghi',
    'url_base': 'http://localhost:5000'
}


def test_group_fetch(mock_mcomm):
11
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
12
13
14
15
16
    conn.fetch_group('testgroup')
    assert conn.group_data['name'] == 'testgroup'


def test_person_fetch(mock_mcomm):
17
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
18
19
20
21
22
    person = conn.fetch_person('testuser')
    assert person['naming'] == 'testuser'


def test_group_creation(mock_mcomm):
23
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
24
25
26
27
    conn.create_group('testgroup')
    assert conn.group_data['name'] == 'testgroup'


28
29
30
31
32
33
def test_group_reservation(mock_mcomm):
    conn = mcommunity.Client(config=config)
    conn.reserve_group('testgroup')
    assert conn.group_data['name'] == 'testgroup'


Rob Carleski's avatar
Rob Carleski committed
34
def test_group_deletion(mock_mcomm):
35
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
36
37
38
39
40
    r = conn.delete_group('testgroup')
    assert r['status'] == 'success'


def test_group_renew(mock_mcomm):
41
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
42
43
44
45
46
    r = conn.renew_group('testgroup')
    assert r['status'] == 'success'


def test_group_update_aliases(mock_mcomm):
47
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
48
49
50
51
52
53
    conn.fetch_group('testgroup')
    conn.update_group_aliases('testalias')
    assert 'testalias' in conn.group_data['aliases']


def test_group_update_description(mock_mcomm):
54
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
55
56
57
58
59
60
    conn.fetch_group('testgroup')
    conn.update_group_description('test description')
    assert conn.group_data['description'] == 'test description'


def test_group_update_notice(mock_mcomm):
61
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
62
63
64
65
66
67
    conn.fetch_group('testgroup')
    conn.update_group_notice('test notice')
    assert conn.group_data['notice'] == 'test notice'


def test_group_update_links_labeled(mock_mcomm):
68
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
69
70
71
72
73
74
75
76
    conn.fetch_group('testgroup')
    links = ('Test Link', 'https://test.link')
    conn.update_group_links(links)
    assert conn.group_data['labeledUri'][0]['urlLabel'] == 'Test Link'
    assert conn.group_data['labeledUri'][0]['urlValue'] == 'https://test.link'


def test_group_update_links_plain(mock_mcomm):
77
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
78
79
80
81
82
83
84
    conn.fetch_group('testgroup')
    links = 'https://test.link'
    conn.update_group_links(links)
    assert conn.group_data['labeledUri'][0]['urlValue'] == 'https://test.link'


def test_group_owners_update(mock_mcomm):
85
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
86
87
88
89
90
91
92
93
94
    conn.fetch_group('testgroup')
    conn.add_group_owners('testuser2')
    testuser2 = conn._create_entity_ldap('testuser2')
    assert testuser2 in conn.group_data['ownerDn']
    conn.remove_group_owners('testuser2')
    assert testuser2 not in conn.group_data['ownerDn']


def test_group_members_update(mock_mcomm):
95
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    conn.fetch_group('testgroup')
    members = [
        'testuser2',
        'testgroup2',
        'test@domain.tld'
    ]
    conn.add_group_members(members)
    testuser2 = conn._create_entity_ldap('testuser2')
    testgroup2 = conn._create_entity_ldap('testgroup2')
    externalMember = 'test@domain.tld'
    assert testuser2 in conn.group_data['memberDn']
    assert testgroup2 in conn.group_data['memberGroupDn']
    assert conn.group_data['memberExternal'][0]['email'] == externalMember
    conn.remove_group_members(members)
    assert testuser2 not in conn.group_data['memberDn']
    assert testgroup2 not in conn.group_data['memberGroupDn']
    assert not conn.group_data['memberExternal']