-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
129 lines (92 loc) · 4.08 KB
/
tests.py
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
import unittest
from os import path
import shutil
import tempfile
from hashlib import sha1
from mock import patch
class GitomaticTestCase(unittest.TestCase):
def setUp(self):
# Change home path for a temporary one.
self._directory = tempfile.mkdtemp()
# Mock os.path.expanduser function.
self.mock_expanduser = patch('os.path.expanduser')
mock = self.mock_expanduser.start()
mock.side_effect = lambda x: x.replace('~', self._directory)
from gitomatic import Gitomatic
self.gitomatic = Gitomatic()
def tearDown(self):
# Delete temporary directory
self.mock_expanduser.stop()
shutil.rmtree(self._directory)
def test_initialize_gitomatic(self):
self.gitomatic.initialize()
self.assertTrue(path.exists(path.join(
self._directory, '.ssh')))
self.assertTrue(path.exists(path.join(
self._directory, '.gitomatic')))
self.assertTrue(path.exists(path.join(
self._directory, '.gitomatic/keys')))
self.assertTrue(path.exists(path.join(
self._directory, '.gitomatic/repositories')))
def test_add_repo(self):
self.gitomatic.initialize()
self.gitomatic.repository.create('test.git')
self.assertTrue(path.exists(path.join(
self._directory, '.gitomatic/repositories/test.git')))
def test_delete_repo(self):
# Add repo
self.gitomatic.initialize()
self.gitomatic.repository.create('test.git')
self.assertTrue(path.exists(path.join(
self._directory, '.gitomatic/repositories/test.git')))
# Delete repo
self.gitomatic.repository.delete('test.git')
self.assertTrue(not path.exists(path.join(
self._directory, '.gitomatic/repositories/test.git')))
def test_add_key(self):
# Initialize repo.
self.gitomatic.initialize()
key = 'ssh-rsa asasdav asda'
hash_1 = sha1(key).hexdigest()
hash_2 = self.gitomatic.keys.add('test@test.com', key)
self.assertEqual(hash_1, hash_2)
self.assertTrue(path.exists(path.join(
self._directory, '.gitomatic/keys/test@test.com:%s' % (hash_1, ))))
def test_delete_key(self):
# Initialize repo.
self.gitomatic.initialize()
key = 'ssh-rsa asasdav asda'
hash_ = self.gitomatic.keys.add('test@test.com', key)
self.assertTrue(path.exists(path.join(
self._directory, '.gitomatic/keys/test@test.com:%s' % (hash_, ))))
self.gitomatic.keys.remove('test@test.com', hash_)
self.assertTrue(not path.exists(path.join(
self._directory, '.gitomatic/keys/test@test.com:%s' % (hash_, ))))
def test_add_and_read_perm(self):
# Initialize repo.
self.gitomatic.initialize()
self.gitomatic.repository.create('test.git')
self.gitomatic.permissions.add('test@test.com', 'test', 'R')
self.assertTrue(
'R' in self.gitomatic.permissions.get('test@test.com', 'test'))
self.assertTrue(not
'W' in self.gitomatic.permissions.get('test@test.com', 'test'))
self.gitomatic.permissions.add('test@test.com', 'test', 'W')
self.assertTrue(
'R' in self.gitomatic.permissions.get('test@test.com', 'test'))
self.assertTrue(
'W' in self.gitomatic.permissions.get('test@test.com', 'test'))
def test_delete_perm(self):
# Initialize repo.
self.gitomatic.initialize()
self.gitomatic.repository.create('test.git')
self.gitomatic.permissions.add('test@test.com', 'test', 'RW')
self.assertTrue(
'R' in self.gitomatic.permissions.get('test@test.com', 'test'))
self.assertTrue(
'W' in self.gitomatic.permissions.get('test@test.com', 'test'))
self.gitomatic.permissions.remove('test@test.com', 'test', 'R')
self.assertTrue(not
'R' in self.gitomatic.permissions.get('test@test.com', 'test'))
self.assertTrue(not
'W' in self.gitomatic.permissions.get('test@test.com', 'test'))