Skip to content

Commit c41ab9c

Browse files
authored
Add get published list (#213)
* feat: add get_published_list to fetch published binaries of a project/repo/arch * fix: use raw strings where unknown escapes are used
1 parent 650e24a commit c41ab9c

File tree

5 files changed

+63
-4
lines changed

5 files changed

+63
-4
lines changed

osctiny/extensions/buildresults.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ def get_package_list(self, project, repo, arch):
111111

112112
return self.osc.get_objectified_xml(response)
113113

114+
def get_published_list(self, project: str, repo: str, arch: str, **params):
115+
"""
116+
Get a list of published binaries in a repository
117+
118+
Returns the directory listing of published packages for a given
119+
project, repository, and architecture combination.
120+
121+
:param project: Project name
122+
:param repo: Repository name
123+
:param arch: Architecture name
124+
:param params: Additional parameters
125+
:return: Objectified XML element containing directory entries
126+
:rtype: lxml.objectify.ObjectifiedElement
127+
128+
"""
129+
response = self.osc.request(
130+
method="GET",
131+
url=urljoin(self.osc.url, f"/published/{project}/{repo}/{arch}"),
132+
params=params,
133+
)
134+
135+
return self.osc.get_objectified_xml(response)
136+
114137
def get_status_and_build_id(self, project, repo, arch):
115138
"""
116139
Get build status and build ID

osctiny/tests/test_build.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,39 @@ def callback(headers, params, request):
9696
HTTPError,
9797
self.osc.build.get, project=project, package="xyz123"
9898
)
99+
100+
@responses.activate
101+
def test_get_published_list(self):
102+
project = "openSUSE:Factory"
103+
repo = "standard"
104+
arch = "x86_64"
105+
106+
response_body = """
107+
<directory>
108+
<entry name="acme-webserver-1.2.3-1.1.x86_64.rpm"/>
109+
<entry name="acme-webserver-debuginfo-1.2.3-1.1.x86_64.rpm"/>
110+
<entry name="acme-webserver-debugsource-1.2.3-1.1.x86_64.rpm"/>
111+
<entry name="python-foobar-2.0.1-4.2.x86_64.rpm"/>
112+
<entry name="python-foobar-doc-2.0.1-4.2.x86_64.rpm"/>
113+
<entry name="libcoolstuff3-0.5.7-2.1.x86_64.rpm"/>
114+
<entry name="libcoolstuff-devel-0.5.7-2.1.x86_64.rpm"/>
115+
</directory>
116+
"""
117+
118+
self.mock_request(
119+
method=responses.GET,
120+
url=re.compile(f"{self.osc.url}/published/{project}/{repo}/{arch}"),
121+
body=response_body,
122+
)
123+
124+
response = self.osc.build.get_published_list(
125+
project=project,
126+
repo=repo,
127+
arch=arch
128+
)
129+
130+
entries = response.findall("entry")
131+
self.assertEqual(len(entries), 7)
132+
self.assertEqual(entries[0].get("name"), "acme-webserver-1.2.3-1.1.x86_64.rpm")
133+
self.assertEqual(entries[3].get("name"), "python-foobar-2.0.1-4.2.x86_64.rpm")
134+
self.assertEqual(entries[5].get("name"), "libcoolstuff3-0.5.7-2.1.x86_64.rpm")

osctiny/tests/test_issues.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def setUp(self):
1414
super(TestIssue, self).setUp()
1515

1616
def callback(headers, params, request):
17-
status, body = 200, """
17+
status, body = 200, r"""
1818
<issue-trackers>
1919
<issue-tracker>
2020
<name>boost</name>
@@ -69,7 +69,7 @@ def test_get_trackers(self):
6969
def test_get_tracker(self):
7070
def callback(headers, params, request):
7171
if re.search("bnc/?$", request.url):
72-
status, body = 200, """
72+
status, body = 200, r"""
7373
<issue-tracker>
7474
<name>bnc</name>
7575
<kind>bugzilla</kind>

osctiny/tests/test_projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def callback(headers, params, request):
269269
"""
270270
if request.url.endswith("_attribute"):
271271
status = 200
272-
body = """
272+
body = r"""
273273
<attributes>
274274
<attribute name="IgnoredIssues" namespace="OSRT">
275275
<value>last_seen: {}</value>

osctiny/tests/test_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def callback(headers, params, request):
307307
and "changereviewstate" in params.get("cmd", [])):
308308
status = 403
309309
body = "Forbidden for url: http://api.example.com/request/30902"
310-
elif request.method == "POST" and re.search("/request/?\?", request.url):
310+
elif request.method == "POST" and re.search(r"/request/?\?", request.url):
311311
status = 200
312312
body = """<request id="42"/>"""
313313
else:

0 commit comments

Comments
 (0)