Skip to content

Commit

Permalink
Add support for component's category attribute (#471)
Browse files Browse the repository at this point in the history
* Add support for component's category attribute

* Extend mocks with components listings

* Add category to OPTIONALS of Component

* Extend tests with all components fields, add ComponentCompatibilityTest test class for optional fields support
  • Loading branch information
m-aciek authored Sep 11, 2023
1 parent a499510 commit f6a19fa
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 1 deletion.
3 changes: 2 additions & 1 deletion wlc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,9 @@ class Component(LazyObject, RepoObjectMixin):
"source_language",
"priority",
"is_glossary",
"category",
)
OPTIONALS: ClassVar[Set[str]] = {"source_language", "is_glossary"}
OPTIONALS: ClassVar[Set[str]] = {"source_language", "is_glossary", "category"}
ID: ClassVar[str] = "slug"
MAPPINGS: ClassVar[Dict[str, Any]] = {
"project": Project,
Expand Down
1 change: 1 addition & 0 deletions wlc/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def register_uris():
"components",
"components/hello/android",
"components/hello/android/file",
"components/hello/olderweblate",
"components/hello/weblate",
"components/hello/weblate/file",
"components/hello/weblate/changes",
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 @@ -5,6 +5,7 @@
"results": [
{
"branch": "main",
"category": "http://127.0.0.1:8000/api/categories/1/",
"file_format": "aresource",
"filemask": "android/values-*/strings.xml",
"git_export": "",
Expand Down Expand Up @@ -57,6 +58,7 @@
},
{
"branch": "main",
"category": null,
"file_format": "po",
"filemask": "po/*.po",
"git_export": "",
Expand Down
31 changes: 31 additions & 0 deletions wlc/test_data/api/components-hello-olderweblate
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"branch": "main",
"file_format": "po",
"filemask": "po/*.po",
"git_export": "",
"license": "",
"license_url": "",
"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",
"repository_url": "http://127.0.0.1:8000/api/projects/hello/repository/",
"slug": "hello",
"url": "http://127.0.0.1:8000/api/projects/hello/",
"web": "http://weblate.org/",
"web_url": "http://127.0.0.1:8000/projects/hello/"
},
"repo": "file:///home/WeblateOrg/work/weblate-hello",
"repository_url": "http://127.0.0.1:8000/api/components/hello/weblate/repository/",
"slug": "weblate",
"statistics_url": "http://127.0.0.1:8000/api/components/hello/weblate/statistics/",
"template": "",
"translations_url": "http://127.0.0.1:8000/api/components/hello/weblate/translations/",
"changes_list_url": "http://127.0.0.1:8000/api/components/hello/weblate/changes/",
"url": "http://127.0.0.1:8000/api/components/hello/weblate/",
"vcs": "git",
"web_url": "http://127.0.0.1:8000/projects/hello/weblate/"
}
2 changes: 2 additions & 0 deletions wlc/test_data/api/components-hello-weblate
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"branch": "main",
"category": "http://127.0.0.1:8000/api/categories/1/",
"file_format": "po",
"filemask": "po/*.po",
"git_export": "",
"is_glossary": false,
"license": "",
"license_url": "",
"lock_url": "http://127.0.0.1:8000/api/components/hello/weblate/lock/",
Expand Down
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 @@ -5,6 +5,7 @@
"results": [
{
"branch": "main",
"category": "http://127.0.0.1:8000/api/categories/1/",
"file_format": "aresource",
"filemask": "android/values-*/strings.xml",
"git_export": "",
Expand Down Expand Up @@ -48,6 +49,7 @@
},
{
"branch": "main",
"category": null,
"file_format": "po",
"filemask": "po/*.po",
"git_export": "",
Expand Down
46 changes: 46 additions & 0 deletions wlc/test_wlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def check_object(self, obj):
"""Perform verification whether object is valid."""
self.assertEqual(obj.name, "Weblate")
self.assertEqual(obj.priority, 100)
self.assertEqual(obj.category, "http://127.0.0.1:8000/api/categories/1/")

def check_list(self, obj):
"""Perform verification whether listing is valid."""
Expand Down Expand Up @@ -486,9 +487,11 @@ def test_keys(self):
obj.keys(),
[
"branch",
"category",
"file_format",
"filemask",
"git_export",
"is_glossary",
"license",
"license_url",
"name",
Expand All @@ -512,6 +515,49 @@ def test_components_patch(self):
self.assertIn("--patched--", resp.decode())


class ComponentCompatibilityTest(ObjectTest):
"""Tests a component with lack of all optional fields in a response."""

_name = "hello/olderweblate"
_cls = Component

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."""
lst = list(obj)
self.assertEqual(len(lst), 33)
self.assertIsInstance(lst[0], Translation)

def test_keys(self):
"""Test keys lazy loading."""
obj = Component(Weblate(), f"components/{self._name}/")
self.assertCountEqual(
obj.keys(),
[
"branch",
"file_format",
"filemask",
"git_export",
"license",
"license_url",
"name",
"new_base",
"priority",
"project",
"repo",
"slug",
"template",
"url",
"vcs",
"web_url",
],
)


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

Expand Down

0 comments on commit f6a19fa

Please sign in to comment.