Exemple #1
0
 def test_ensure_loaded(self):
     """Test lazy loading of attributes."""
     obj = Weblate().get_object("hello")
     obj.ensure_loaded("missing")
     obj.ensure_loaded("missing")
     with self.assertRaises(AttributeError):
         print(obj.missing)
Exemple #2
0
 def test_ensure_loaded(self):
     """Test lazy loading of attributes."""
     obj = Weblate().get_object("hello")
     obj.ensure_loaded("missing")
     obj.ensure_loaded("missing")
     with self.assertRaises(AttributeError):
         getattr(obj, "missing")
Exemple #3
0
 def test_ensure_loaded(self):
     """Test lazy loading of attributes."""
     obj = Weblate().get_object('hello')
     obj.ensure_loaded('missing')
     obj.ensure_loaded('missing')
     with self.assertRaises(AttributeError):
         getattr(obj, 'missing')
Exemple #4
0
def get_changes(force=False):
    key = 'wlweb-changes-list'
    results = cache.get(key)
    if not force and results is not None:
        return results
    wlc = Weblate(key=settings.CHANGES_KEY, url=settings.CHANGES_API)

    stats = [p.statistics() for p in wlc.list_projects()]
    stats = [p.get_data() for p in stats if p['last_change'] is not None]

    stats.sort(key=lambda x: x['last_change'], reverse=True)

    cache.set(key, stats[:10], timeout=3600)
    return stats[:10]
Exemple #5
0
 def test_invalid_attribute(self):
     """Test attributes getting."""
     obj = Weblate().get_object('hello')
     self.assertEqual(obj.name, 'Hello')
     self.assertEqual(getattr(obj, 'name'), 'Hello')
     with self.assertRaises(AttributeError):
         getattr(obj, 'invalid_attribute')
Exemple #6
0
 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",
         ]),
     )
Exemple #7
0
 def test_invalid_attribute(self):
     """Test attributes getting."""
     obj = Weblate().get_object("hello")
     self.assertEqual(obj.name, "Hello")
     self.assertEqual(getattr(obj, "name"), "Hello")
     with self.assertRaises(AttributeError):
         getattr(obj, "invalid_attribute")
Exemple #8
0
 def test_add_source_string_to_bilingual_component(self):
     with self.assertRaises(IsNotMonolingual):
         Weblate().add_source_string(
             project="hello",
             component="weblate",
             msgid="test-bilingual",
             msgstr="test it good",
         )
Exemple #9
0
 def test_create_project(self):
     resp = Weblate().create_project("Hello", "hello",
                                     "http://example.com/", "Malayalam",
                                     "ml")
     self.assertEqual("Hello", resp["name"])
     self.assertEqual("hello", resp["slug"])
     self.assertEqual("http://example.com/", resp["web"])
     self.assertEqual("Malayalam", resp["source_language"]["name"])
     self.assertEqual("ml", resp["source_language"]["code"])
Exemple #10
0
 def test_denied_json(self):
     """Test permission denied when posting components."""
     with self.assertRaisesRegex(WeblateException, "Can not create"):
         Weblate().create_component(
             project="denied_json",
             slug="component1",
             name="component1",
             file_format="po",
             filemask="/something",
             repo="a_repo",
         )
Exemple #11
0
 def test_add_source_string_to_monolingual_component(self):
     resp = Weblate().add_source_string(
         project="hello",
         component="android",
         msgid="test-monolingual",
         msgstr="test-me",
     )
     # ensure it is definitely monolingual
     self.assertEqual(resp["component"]["template"], "android/values/strings.xml")
     self.assertEqual(resp["component"]["slug"], "android")
     self.assertEqual(resp["id"], 1646)
Exemple #12
0
 def test_create_language(self):
     resp = Weblate().create_language(
         name="Test Language",
         code="tst",
         direction="rtl",
         plural={"number": 2, "formula": "n != 1"},
     )
     self.assertEqual("Test Language", resp["name"])
     self.assertEqual("tst", resp["code"])
     self.assertEqual("rtl", resp["direction"])
     self.assertEqual(2, resp["plural"]["number"])
     self.assertEqual("n != 1", resp["plural"]["formula"])
Exemple #13
0
    def test_create_component_local_files(self):

        test_file = os.path.join(
            os.path.dirname(__file__), "test_data", "mock", "project-local-file.pot"
        )
        with open(test_file) as file:
            resp = Weblate().create_component(
                docfile=file.read(),
                project="hello",
                branch="main",
                file_format="po",
                filemask="po/*.po",
                git_export="",
                license="",
                license_url="",
                name="Weblate",
                slug="weblate",
                repo="local:",
                template="",
                new_base="",
                vcs="local",
            )
            self.assertEqual("Hello", resp["project"]["name"])
            self.assertEqual("hello", resp["project"]["slug"])
            self.assertEqual("Weblate", resp["name"])
            self.assertEqual("weblate", resp["slug"])
            self.assertEqual("local:", resp["repo"])
            self.assertEqual("main", resp["branch"])
            self.assertEqual("po/*.po", resp["filemask"])
            self.assertEqual("local", resp["vcs"])
            self.assertEqual("po", resp["file_format"])

            with self.assertRaisesRegex(WeblateException, "required"):
                Weblate().create_component(project="hello")

            with self.assertRaisesRegex(WeblateException, "required"):
                Weblate().create_component(project="hello", name="Weblate")

            with self.assertRaisesRegex(WeblateException, "required"):
                Weblate().create_component(
                    project="hello", name="Weblate", slug="weblate"
                )

            with self.assertRaisesRegex(WeblateException, "required"):
                Weblate().create_component(
                    project="hello", name="Weblate", slug="weblate", file_format="po"
                )

            with self.assertRaisesRegex(WeblateException, "required"):
                Weblate().create_component(
                    project="hello",
                    name="Weblate",
                    slug="weblate",
                    file_format="po",
                    filemask="po/*.po",
                )
Exemple #14
0
    def test_create_component(self):
        resp = Weblate().create_component(
            project="hello",
            branch="master",
            file_format="po",
            filemask="po/*.po",
            git_export="",
            license="",
            license_url="",
            name="Weblate",
            slug="weblate",
            repo="file:///home/nijel/work/weblate-hello",
            template="",
            new_base="",
            vcs="git",
        )
        self.assertEqual("Hello", resp["project"]["name"])
        self.assertEqual("hello", resp["project"]["slug"])
        self.assertEqual("Weblate", resp["name"])
        self.assertEqual("weblate", resp["slug"])
        self.assertEqual("file:///home/nijel/work/weblate-hello", resp["repo"])
        self.assertEqual("http://example.com/git/hello/weblate/",
                         resp["git_export"])
        self.assertEqual("master", resp["branch"])
        self.assertEqual("po/*.po", resp["filemask"])
        self.assertEqual("git", resp["vcs"])
        self.assertEqual("po", resp["file_format"])

        with self.assertRaisesRegex(WeblateException, "required"):
            Weblate().create_component(project="hello")

        with self.assertRaisesRegex(WeblateException, "required"):
            Weblate().create_component(project="hello", name="Weblate")

        with self.assertRaisesRegex(WeblateException, "required"):
            Weblate().create_component(project="hello",
                                       name="Weblate",
                                       slug="weblate")

        with self.assertRaisesRegex(WeblateException, "required"):
            Weblate().create_component(project="hello",
                                       name="Weblate",
                                       slug="weblate",
                                       file_format="po")

        with self.assertRaisesRegex(WeblateException, "required"):
            Weblate().create_component(
                project="hello",
                name="Weblate",
                slug="weblate",
                file_format="po",
                filemask="po/*.po",
            )
Exemple #15
0
 def test_too_long(self):
     """Test listing projects."""
     with self.assertRaises(ValueError):
         Weblate().get_object("a/b/c/d")
Exemple #16
0
 def test_invalid(self):
     """Test listing projects."""
     with self.assertRaisesRegex(WeblateException, "invalid JSON"):
         Weblate().get_object("invalid")
Exemple #17
0
 def test_oserror(self):
     """Test listing projects."""
     with self.assertRaises(IOError):
         Weblate().get_object("io")
Exemple #18
0
 def test_error(self):
     """Test listing projects."""
     with self.assertRaisesRegex(WeblateException, "500"):
         Weblate().get_object("error")
Exemple #19
0
 def test_throttled(self):
     """Test listing projects."""
     with self.assertRaisesRegex(WeblateException, "Throttling"):
         Weblate().get_object("throttled")
Exemple #20
0
 def test_bug(self):
     """Test listing projects."""
     with self.assertRaises(Exception):
         Weblate().get_object("bug")
Exemple #21
0
 def test_components(self):
     """Test listing components."""
     self.assertEqual(len(list(Weblate().list_components())), 2)
Exemple #22
0
 def get(self):
     """Return remote object."""
     return Weblate().get_object(self._name)
Exemple #23
0
 def test_repr(self):
     """Test str and repr behavior."""
     obj = Weblate().get_object("hello")
     self.assertIn("'slug': 'hello'", repr(obj))
     self.assertIn("'slug': 'hello'", str(obj))
Exemple #24
0
 def test_authentication(self):
     """Test authentication against server."""
     with self.assertRaisesRegex(WeblateException, "permission"):
         obj = Weblate().get_object("acl")
     obj = Weblate(key="KEY").get_object("acl")
     self.assertEqual(obj.name, "ACL")
Exemple #25
0
 def test_languages(self):
     """Test listing projects."""
     self.assertEqual(
         len(list(Weblate().list_languages())),
         47,
     )
Exemple #26
0
 def test_api_trailing_slash(self):
     """Test listing projects."""
     self.assertEqual(len(list(Weblate(url=API_URL[:-1]).list_languages())),
                      47)
Exemple #27
0
 def test_nonexisting(self):
     """Test listing projects."""
     with self.assertRaisesRegex(WeblateException, "not found"):
         Weblate().get_object("nonexisting")
Exemple #28
0
 def test_projects(self):
     """Test listing projects."""
     self.assertEqual(len(list(Weblate().list_projects())), 2)
Exemple #29
0
 def test_denied(self):
     """Test listing projects."""
     with self.assertRaisesRegex(WeblateException, "permission"):
         Weblate().get_object("denied")
Exemple #30
0
 def test_translations(self):
     """Test listing translations."""
     self.assertEqual(len(list(Weblate().list_translations())), 50)
Exemple #31
0
 def test_authentication(self):
     """Test authentication against server."""
     with self.assertRaisesRegex(WeblateException, 'permission'):
         obj = Weblate().get_object('acl')
     obj = Weblate(key='KEY').get_object('acl')
     self.assertEqual(obj.name, 'ACL')