-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_Artifactory.py
97 lines (78 loc) · 3.34 KB
/
test_Artifactory.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
# Simple tests as this philosophy makes sense
# http://softwareengineering.stackexchange.com/questions/252748/is-it-actually-worth-unit-testing-an-api-client
import unittest
from mock import patch
from Artifactory import Artifactory
URL = {
'USERS': '/security/users',
'API': '/security/apiKey'
}
class ArtifactoryTestCase(unittest.TestCase):
""" Tests for `Artifactory.py` """
@classmethod
def setUpClass(self):
self.artifactory = Artifactory('admin','password', base_url='https://fake_url/artifactory')
def test_get_users(self):
with patch.object(Artifactory, 'get') as mock:
self.artifactory.get_users()
mock.assert_called_once_with(URL['USERS'])
def test_get_user(self):
with patch.object(Artifactory, 'get') as mock:
self.artifactory.get_user('tim')
mock.assert_called_once_with('/security/users/tim')
def test_create_user(self):
with patch.object(Artifactory, 'put') as mock:
self.artifactory.create_user('tim', {
'password': 'password',
'email': 'tim@email.com'
})
mock.assert_called_once_with('/security/users/tim', {
'password': 'password',
'email': 'tim@email.com'
})
def test_create_user_failure(self):
self.assertFalse(
self.artifactory.create_user('tim', {
'email': 'tim@email.com'
}),
msg='Expected no create_user to return early'
)
def test_delete_user(self):
with patch.object(Artifactory, 'delete') as mock:
self.artifactory.delete_user('tim')
mock.assert_called_once_with('/security/users/tim')
def test_get_api_key(self):
with patch.object(Artifactory, 'get') as mock:
self.artifactory.get_api_key()
mock.assert_called_once_with(URL['API'])
def test_create_api_key(self):
with patch.object(Artifactory, 'post') as mock:
self.artifactory.create_api_key()
mock.assert_called_once_with(URL['API'])
def test_regenerate_api_key(self):
with patch.object(Artifactory, 'put') as mock:
self.artifactory.regenerate_api_key()
mock.assert_called_once_with(URL['API'])
def test_revoke_api_key(self):
with patch.object(Artifactory, 'delete') as mock:
self.artifactory.revoke_api_key()
mock.assert_called_once_with(URL['API'])
def test_delete_item(self):
item_path = '/somerepo/some-item/99.9/some-item.jar'
with patch.object(Artifactory, 'delete') as mock:
self.artifactory.delete_item(item_path)
mock.assert_called_once_with(item_path)
def test_get_storage_info(self):
with patch.object(Artifactory, 'get') as mock:
self.artifactory.get_storage_info()
mock.assert_called_once_with('/storageinfo')
def test_search_by_creation_date(self):
start = 1479790359503
end = 1479790373396
repos = 'somerepo'
params = {'from': start, 'to': end, 'repos': repos}
with patch.object(Artifactory, 'get') as mock:
self.artifactory.search_by_creation_date(start, end, repos)
mock.assert_called_once_with('/search/creation', params=params)
if __name__ == '__main__':
unittest.main()