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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
import os
from . import test_dir
from obsapi.sourceapi import ObsSourceApi
prj = 'home:sbahling:obsapi:test'
pkg = 'suse-hello-1.0'
repo = 'SLE_12_SP3'
arch = 'x86_64'
sourceapi = ObsSourceApi(apiurl='https://api.opensuse.org')
class RequestMatcher():
def __init__(self):
self.put_data = None
def match_put_data(self, request):
return request.text == self.put_data
def test_source_put_meta(requests_mock):
content = b'<status code="ok"></status>'
uri = '{}/source/{}/_meta'.format(sourceapi.apiurl, prj)
with open(os.path.join(test_dir, 'obsapi_test_prj_meta.xml')) as f:
xml = f.read().replace('__PRJ__', prj)
matcher = RequestMatcher()
matcher.put_data = xml
requests_mock.put(uri, content=content, additional_matcher=matcher.match_put_data)
response = sourceapi.put_meta(prj, xml)
assert response.content == content
# GET /source/
# Result: directory listing as xml
def test_source_get(requests_mock):
uri = '{}/source/'.format(sourceapi.apiurl)
text = '<directory></directory>'
requests_mock.get(uri, text=text)
xml = sourceapi.get()
assert xml == text
# GET /source/<project>
# Result: directory listing as xml
def test_source_get_prj(requests_mock):
uri = '{}/source/{}'.format(sourceapi.apiurl, prj)
text = '<directory></directory>'
requests_mock.get(uri, text=text)
xml = sourceapi.get(prj)
assert xml == text
# GET /source/<project>/<package>
# Result: directory listing as xml
def test_source_get_pkg(requests_mock):
uri = '{}/source/{}/{}'.format(sourceapi.apiurl, prj, pkg)
text = '<directory></directory>'
requests_mock.get(uri, text=text)
xml = sourceapi.get(prj, pkg)
assert xml == text
# GET /source/<project>/<package></filename>
# Result: contents of a source file
def test_source_get_file(requests_mock):
fname = 'suse-hello-kmp-default.rpm'
uri = '{}/source/{}/{}/{}'.format(sourceapi.apiurl, prj, pkg, fname)
with open(os.path.join(test_dir, fname), 'rb') as f:
content = f.read()
requests_mock.get(uri, content=content)
source_file = sourceapi.get(prj, pkg, fname)
assert source_file == content
# GET /source/<project>/_meta
# Result: contents of the project meta file
def test_source_get_meta_prj(requests_mock):
uri = '{}/source/{}/_meta'.format(sourceapi.apiurl, prj)
text = 'Project Meta File'
requests_mock.get(uri, text=text)
xml = sourceapi.get_meta(prj)
assert xml == text
# GET /source/<project>/<package>/_meta
# Result: contents of the package meta file
def test_source_get_meta_pkg(requests_mock):
uri = '{}/source/{}/{}/_meta'.format(sourceapi.apiurl, prj, pkg)
text = 'Package Meta File'
requests_mock.get(uri, text=text)
xml = sourceapi.get_meta(prj, pkg)
assert xml == text
# GET /source/<project>/_attribute
# Result: list of attributes as xml
def test_source_get_prj_attributes(requests_mock):
uri = '{}/source/{}/_attribute'.format(sourceapi.apiurl, prj)
text = '<attributes></attributes>'
requests_mock.get(uri, text=text)
xml = sourceapi.get_attribute(prj)
assert xml == text
# GET /source/<project>/_attribute/<attribute>
# Result: return single attribute in attributes xml container
def test_source_get_prj_attribute(requests_mock):
attribute = 'OBS:Screenshots'
uri = '{}/source/{}/_attribute/{}'.format(sourceapi.apiurl, prj, attribute)
text = '<attributes></attributes>'
requests_mock.get(uri, text=text)
xml = sourceapi.get_attribute(prj, attribute=attribute)
assert xml == text
# GET /source/<project>/<package>/_attribute
# Result: return package level attributes as xml
def test_source_get_pkg_attributes(requests_mock):
uri = '{}/source/{}/{}/_attribute'.format(sourceapi.apiurl, prj, pkg)
text = '<attributes></attributes>'
requests_mock.get(uri, text=text)
xml = sourceapi.get_attribute(prj, pkg)
assert xml == text
# GET /source/<project>/_attribute
# Result: return project config file as text
def test_source_get_prj_config(requests_mock):
uri = '{}/source/{}/_config'.format(sourceapi.apiurl, prj)
text = 'Project Config'
requests_mock.get(uri, text=text)
config = sourceapi.get_config(prj)
assert config == text
# GET /source/<project>/_pubkey
# Result: return project pub key as text
def test_source_get_prj_pubkey(requests_mock):
uri = '{}/source/{}/_pubkey'.format(sourceapi.apiurl, prj)
text = 'PubKey Contents'
requests_mock.get(uri, text=text)
pubkey = sourceapi.get_pubkey(prj)
assert pubkey == text
# GET /source/<project>/<package>/_history
# Result: return package commit history as xml
def test_source_get_history(requests_mock):
uri = '{}/source/{}/{}/_history'.format(sourceapi.apiurl, prj, pkg)
text = '<revisionlist></revisionlist>'
requests_mock.get(uri, text=text)
xml = sourceapi.get_history(prj, pkg)
assert xml == text
|