Skip to content

Commit

Permalink
Add support for component's priority attribute and component's patchi…
Browse files Browse the repository at this point in the history
…ng (#454)

* Add support for component's priority attribute

* Add patch() method on component

* Extend mock responses for test_list_components and test_ls in TestCommands

* Add unit test for component patching
  • Loading branch information
m-aciek authored Aug 4, 2023
1 parent 8b1beb9 commit 088cfe8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
4 changes: 4 additions & 0 deletions wlc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ class Component(LazyObject, RepoObjectMixin):
"license",
"license_url",
"source_language",
"priority",
"is_glossary",
)
OPTIONALS: ClassVar[Set[str]] = {"source_language", "is_glossary"}
Expand Down Expand Up @@ -670,6 +671,9 @@ def download(self, convert=None):
url = "{}?{}".format(url, urlencode({"format": convert}))
return self.weblate.raw_request("get", url)

def patch(self, **kwargs):
return self.weblate.raw_request("patch", self._url, data=kwargs)


class Translation(LazyObject, RepoObjectMixin):
"""Translation object."""
Expand Down
2 changes: 2 additions & 0 deletions wlc/test_data/api/components
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lock_url": "http://127.0.0.1:8000/api/components/hello/android/lock/",
"name": "Android",
"new_base": "",
"priority": 100,
"project": {
"components_list_url": "http://127.0.0.1:8000/api/projects/hello/components/",
"name": "Hello",
Expand Down Expand Up @@ -64,6 +65,7 @@
"lock_url": "http://127.0.0.1:8000/api/components/hello/weblate/lock/",
"name": "Weblate",
"new_base": "",
"priority": 100,
"project": {
"components_list_url": "http://127.0.0.1:8000/api/projects/hello/components/",
"name": "Hello",
Expand Down
1 change: 1 addition & 0 deletions wlc/test_data/api/components-hello-weblate
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lock_url": "http://127.0.0.1:8000/api/components/hello/weblate/lock/",
"name": "Weblate",
"new_base": "",
"priority": 100,
"project": {
"components_list_url": "http://127.0.0.1:8000/api/projects/hello/components/",
"name": "Hello",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--patched--
2 changes: 2 additions & 0 deletions wlc/test_data/api/projects-hello-components
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lock_url": "http://127.0.0.1:8000/api/components/hello/android/lock/",
"name": "Android",
"new_base": "",
"priority": 100,
"repo": "https://github.com/WeblateOrg/test.git",
"repository_url": "http://127.0.0.1:8000/api/components/hello/android/repository/",
"slug": "android",
Expand Down Expand Up @@ -55,6 +56,7 @@
"lock_url": "http://127.0.0.1:8000/api/components/hello/weblate/lock/",
"name": "Weblate",
"new_base": "",
"priority": 100,
"repo": "file:///home/WeblateOrg/work/weblate-hello",
"repository_url": "http://127.0.0.1:8000/api/components/hello/weblate/repository/",
"slug": "weblate",
Expand Down
51 changes: 28 additions & 23 deletions wlc/test_wlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class ComponentTest(ObjectTest):
def check_object(self, obj):
"""Perform verification whether object is valid."""
self.assertEqual(obj.name, "Weblate")
self.assertEqual(obj.priority, 100)

def check_list(self, obj):
"""Perform verification whether listing is valid."""
Expand Down Expand Up @@ -478,31 +479,35 @@ def test_unlock(self):
def test_keys(self):
"""Test keys lazy loading."""
obj = Component(Weblate(), f"components/{self._name}/")
self.assertEqual(
sorted(obj.keys()),
sorted(
[
"branch",
"file_format",
"filemask",
"git_export",
"license",
"license_url",
"name",
"new_base",
"project",
"repo",
"slug",
"source_language",
"source_language",
"template",
"url",
"vcs",
"web_url",
]
),
self.assertCountEqual(
obj.keys(),
[
"branch",
"file_format",
"filemask",
"git_export",
"license",
"license_url",
"name",
"new_base",
"priority",
"project",
"repo",
"slug",
"source_language",
"source_language",
"template",
"url",
"vcs",
"web_url",
],
)

def test_components_patch(self):
obj = self.get()
resp = obj.patch(priority=80)
self.assertIn("--patched--", resp.decode())


class TranslationTest(ObjectTest):
"""Translation object tests."""
Expand Down

0 comments on commit 088cfe8

Please sign in to comment.