Add tests for PTS._NameToId, PTS._IdToName, and PTS._NameOrId.
[invirt/packages/python-afs.git] / afs / tests / test__pts.py
1 import os
2 from afs._pts import PTS
3 import nose
4
5 def get_this_cell():
6     # Feel free to add more places ThisCell might show up
7     to_try = ['/private/var/db/openafs/etc/ThisCell',
8               '/etc/openafs/ThisCell',
9               '/usr/vice/etc/ThisCell']
10     for f in to_try:
11         if os.path.isfile(f):
12             return open(f).read().strip()
13
14 def test_init_home_cell():
15     p = PTS()
16     assert p.cell == get_this_cell(), "PTS doesn't initialize to ThisCell when none specified."
17
18 def test_init_other_cell():
19     cell = 'zone.mit.edu'
20     p = PTS('zone.mit.edu')
21     assert p.cell == cell, "PTS doesn't initialize to provided cell."
22
23 def test_user_name_to_id():
24     p = PTS()
25     name = 'broder'
26     id = p._NameToId(name)
27     assert id == 41803, "PTS can't convert user name to ID."
28     assert p._IdToName(id) == name, "PTS can't convert user ID to name."
29
30 def test_group_name_to_id():
31     p = PTS()
32     name = 'system:administrators'
33     id = p._NameToId(name)
34     assert id == -204, "PTS can't convert group name to ID."
35     assert p._IdToName(id) == name, "PTS can't convert group ID to name."
36
37 def test_name_or_id():
38     p = PTS()
39     name = 'system:administrators'
40     id = -204
41     assert p._NameOrId(name) == id, "PTS._NameOrId can't identify name."
42     assert p._NameOrId(id) == id, "PTS._NameOrId can't identify ID."
43
44 if __name__ == '__main__':
45     nose.main()