[Python-modules-commits] [wlc] 01/03: New upstream version 0.7
Michal Cihar
nijel at moszumanska.debian.org
Fri Dec 16 12:25:15 UTC 2016
This is an automated email from the git hooks/post-receive script.
nijel pushed a commit to branch master
in repository wlc.
commit 561188f0d22f3b77b0c97a6b074da23ff0d8d591
Author: Michal Čihař <michal at cihar.com>
Date: Fri Dec 16 12:57:43 2016 +0100
New upstream version 0.7
---
PKG-INFO | 10 +-
README.rst | 8 +-
requirements-test.txt | 1 +
setup.py | 2 +-
wlc.egg-info/PKG-INFO | 10 +-
wlc.egg-info/SOURCES.txt | 13 ++
wlc/__init__.py | 109 ++++++++++--
wlc/config.py | 2 +-
wlc/main.py | 188 +++++++++++++++------
wlc/test_base.py | 36 +++-
wlc/test_data/api/changes | 35 ++++
wlc/test_data/api/components-hello-weblate | 1 +
wlc/test_data/api/components-hello-weblate-changes | 35 ++++
...hello-weblate-repository--POST--operation=reset | 3 +
wlc/test_data/api/projects-acl | 20 +++
wlc/test_data/api/projects-empty | 20 +++
wlc/test_data/api/projects-empty-components | 7 +
wlc/test_data/api/projects-hello | 2 +
wlc/test_data/api/projects-hello-changes | 35 ++++
...rojects-hello-repository--POST--operation=reset | 3 +
wlc/test_data/api/projects-hello-statistics | 22 +++
wlc/test_data/api/translations-hello-weblate-cs | 1 +
.../api/translations-hello-weblate-cs-changes | 35 ++++
.../api/translations-hello-weblate-cs-file | 40 +++++
...slations-hello-weblate-cs-file--GET--format=csv | 10 ++
...lo-weblate-cs-repository--POST--operation=reset | 3 +
wlc/test_data/wlc | 4 +
wlc/test_main.py | 69 +++++++-
wlc/test_wlc.py | 79 ++++++++-
29 files changed, 722 insertions(+), 81 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 05477f2..af20c90 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: wlc
-Version: 0.6
+Version: 0.7
Summary: A command line utility for Weblate, translation tool with tight version control integration
Home-page: https://weblate.org/
Author: Michal Čihař
@@ -61,14 +61,20 @@ Description: wlc
.. code-block:: sh
wlc list-projects
- wlc list-subprojects
+ wlc list-components
wlc list-translations
+ wlc list-languages
wlc show
wlc ls
wlc commit
wlc push
+ wlc pull
wlc repo
wlc stats
+ wlc lock
+ wlc unlock
+ wlc lock-status
+ wlc download
Configuration is stored in ``~/.config/weblate``:
diff --git a/README.rst b/README.rst
index 106df93..8e4b345 100644
--- a/README.rst
+++ b/README.rst
@@ -52,14 +52,20 @@ Command line usage:
.. code-block:: sh
wlc list-projects
- wlc list-subprojects
+ wlc list-components
wlc list-translations
+ wlc list-languages
wlc show
wlc ls
wlc commit
wlc push
+ wlc pull
wlc repo
wlc stats
+ wlc lock
+ wlc unlock
+ wlc lock-status
+ wlc download
Configuration is stored in ``~/.config/weblate``:
diff --git a/requirements-test.txt b/requirements-test.txt
index 72a9492..11185fd 100644
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -1,3 +1,4 @@
+-r requirements.txt
codecov
codacy-coverage
HTTPretty!=0.8.11,!=0.8.12,!=0.8.13,!=0.8.14
diff --git a/setup.py b/setup.py
index 4cc2ce8..3b21b03 100755
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
-# Copyright © 2016 Michal Čihař <michal at cihar.com>
+# Copyright (c) 2016 Michal Cihar <michal at cihar.com>
#
# This file is part of Weblate Client <https://github.com/WeblateOrg/wlc>
#
diff --git a/wlc.egg-info/PKG-INFO b/wlc.egg-info/PKG-INFO
index 05477f2..af20c90 100644
--- a/wlc.egg-info/PKG-INFO
+++ b/wlc.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: wlc
-Version: 0.6
+Version: 0.7
Summary: A command line utility for Weblate, translation tool with tight version control integration
Home-page: https://weblate.org/
Author: Michal Čihař
@@ -61,14 +61,20 @@ Description: wlc
.. code-block:: sh
wlc list-projects
- wlc list-subprojects
+ wlc list-components
wlc list-translations
+ wlc list-languages
wlc show
wlc ls
wlc commit
wlc push
+ wlc pull
wlc repo
wlc stats
+ wlc lock
+ wlc unlock
+ wlc lock-status
+ wlc download
Configuration is stored in ``~/.config/weblate``:
diff --git a/wlc.egg-info/SOURCES.txt b/wlc.egg-info/SOURCES.txt
index c8aa01b..6feeab3 100644
--- a/wlc.egg-info/SOURCES.txt
+++ b/wlc.egg-info/SOURCES.txt
@@ -19,9 +19,11 @@ wlc.egg-info/top_level.txt
wlc/test_data/.weblate
wlc/test_data/section
wlc/test_data/wlc
+wlc/test_data/api/changes
wlc/test_data/api/components
wlc/test_data/api/components-hello-android
wlc/test_data/api/components-hello-weblate
+wlc/test_data/api/components-hello-weblate-changes
wlc/test_data/api/components-hello-weblate-lock
wlc/test_data/api/components-hello-weblate-lock--POST--lock=0
wlc/test_data/api/components-hello-weblate-lock--POST--lock=1
@@ -29,6 +31,7 @@ wlc/test_data/api/components-hello-weblate-repository
wlc/test_data/api/components-hello-weblate-repository--POST--operation=commit
wlc/test_data/api/components-hello-weblate-repository--POST--operation=pull
wlc/test_data/api/components-hello-weblate-repository--POST--operation=push
+wlc/test_data/api/components-hello-weblate-repository--POST--operation=reset
wlc/test_data/api/components-hello-weblate-statistics
wlc/test_data/api/components-hello-weblate-statistics--GET--page=2
wlc/test_data/api/components-hello-weblate-statistics--GET--page=3
@@ -38,19 +41,29 @@ wlc/test_data/api/languages
wlc/test_data/api/languages--GET--page=2
wlc/test_data/api/languages--GET--page=3
wlc/test_data/api/projects
+wlc/test_data/api/projects-acl
+wlc/test_data/api/projects-empty
+wlc/test_data/api/projects-empty-components
wlc/test_data/api/projects-hello
+wlc/test_data/api/projects-hello-changes
wlc/test_data/api/projects-hello-components
wlc/test_data/api/projects-hello-repository
wlc/test_data/api/projects-hello-repository--POST--operation=commit
wlc/test_data/api/projects-hello-repository--POST--operation=pull
wlc/test_data/api/projects-hello-repository--POST--operation=push
+wlc/test_data/api/projects-hello-repository--POST--operation=reset
+wlc/test_data/api/projects-hello-statistics
wlc/test_data/api/projects-invalid
wlc/test_data/api/translations
wlc/test_data/api/translations--GET--page=2
wlc/test_data/api/translations--GET--page=3
wlc/test_data/api/translations-hello-weblate-cs
+wlc/test_data/api/translations-hello-weblate-cs-changes
+wlc/test_data/api/translations-hello-weblate-cs-file
+wlc/test_data/api/translations-hello-weblate-cs-file--GET--format=csv
wlc/test_data/api/translations-hello-weblate-cs-repository
wlc/test_data/api/translations-hello-weblate-cs-repository--POST--operation=commit
wlc/test_data/api/translations-hello-weblate-cs-repository--POST--operation=pull
wlc/test_data/api/translations-hello-weblate-cs-repository--POST--operation=push
+wlc/test_data/api/translations-hello-weblate-cs-repository--POST--operation=reset
wlc/test_data/api/translations-hello-weblate-cs-statistics
\ No newline at end of file
diff --git a/wlc/__init__.py b/wlc/__init__.py
index c9c3ce6..2f63e1d 100644
--- a/wlc/__init__.py
+++ b/wlc/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# Copyright © 2016 Michal Čihař <michal at cihar.com>
+# Copyright (c) 2016 Michal Cihar <michal at cihar.com>
#
# This file is part of Weblate Client <https://github.com/WeblateOrg/wlc>
#
@@ -24,7 +24,7 @@ from urllib.parse import urlencode
import json
-__version__ = '0.6'
+__version__ = '0.7'
URL = 'https://weblate.org/'
DEVEL_URL = 'https://github.com/WeblateOrg/wlc'
@@ -59,7 +59,8 @@ class Weblate(object):
)
elif error.code == 404:
raise WeblateException(
- 'Object not found on the server'
+ 'Object not found on the server '
+ '(maybe operation is not supported on the server)'
)
elif error.code == 403:
raise WeblateException(
@@ -69,7 +70,7 @@ class Weblate(object):
'HTTP error {0}: {1}'.format(error.code, error.reason)
)
- def request(self, path, params=None):
+ def request(self, path, params=None, raw=False):
"""Construct request object."""
if not path.startswith('http'):
path = '{0}{1}'.format(self.url, path)
@@ -88,6 +89,8 @@ class Weblate(object):
except IOError as error:
self.process_error(error)
raise
+ if raw:
+ return content
try:
result = json.loads(content.decode('utf-8'))
except ValueError:
@@ -110,7 +113,6 @@ class Weblate(object):
"""Wrapper for listing objects."""
while path is not None:
data = self.get(path)
-
for item in data['results']:
yield parser(weblate=self, **item)
@@ -155,6 +157,10 @@ class Weblate(object):
"""List components in the instance."""
return self.list_factory(path, Component)
+ def list_changes(self, path='changes/'):
+ """List components in the instance."""
+ return self.list_factory(path, Change)
+
def list_translations(self, path='translations/'):
"""List translations in the instance."""
return self.list_factory(path, Translation)
@@ -190,12 +196,18 @@ class LazyObject(dict):
def _load_params(self, **kwargs):
for param in self._params:
if param in kwargs:
- if param in self._mappings:
- self._data[param] = self._mappings[param](
- self.weblate, **kwargs[param]
- )
+ value = kwargs[param]
+ if value is not None and param in self._mappings:
+ if isinstance(value, str):
+ self._data[param] = self._mappings[param](
+ self.weblate, url=value
+ )
+ else:
+ self._data[param] = self._mappings[param](
+ self.weblate, **value
+ )
else:
- self._data[param] = kwargs[param]
+ self._data[param] = value
del kwargs[param]
for key in kwargs:
self._attribs[key] = kwargs[key]
@@ -237,6 +249,7 @@ class LazyObject(dict):
def to_value(self):
"""Return identifier for the object."""
+ self.ensure_loaded(self._id)
return self.__getattr__(self._id)
@@ -251,6 +264,17 @@ class Language(LazyObject):
_id = 'code'
+class LanguageStats(LazyObject):
+
+ """Language object."""
+
+ _params = (
+ 'total', 'code', 'translated_words', 'language', 'translated',
+ 'translated_percent', 'total_words', 'words_percent',
+ )
+ _id = 'code'
+
+
class RepoMixin(object):
"""Repository mixin providing generic repository wide operations."""
@@ -280,6 +304,13 @@ class RepoMixin(object):
operation='pull'
)
+ def reset(self):
+ """Reset Weblate repository to upstream."""
+ return self.weblate.post(
+ self._get_repo_url(),
+ operation='reset'
+ )
+
class ProjectRepository(LazyObject, RepoMixin):
@@ -336,6 +367,22 @@ class Project(LazyObject, RepoObjectMixin):
self._attribs['components_list_url']
)
+ def statistics(self):
+ """Return statistics for component."""
+ self.ensure_loaded('statistics_url')
+ url = self._attribs['statistics_url']
+ return [
+ LanguageStats(self.weblate, url, **item)
+ for item in self.weblate.get(url)
+ ]
+
+ def changes(self):
+ """List changes in the project."""
+ self.ensure_loaded('changes_list_url')
+ return self.weblate.list_changes(
+ self._attribs['changes_list_url']
+ )
+
class Component(LazyObject, RepoObjectMixin):
@@ -391,6 +438,13 @@ class Component(LazyObject, RepoObjectMixin):
self._get_lock_url(),
)
+ def changes(self):
+ """List changes in the project."""
+ self.ensure_loaded('changes_list_url')
+ return self.weblate.list_changes(
+ self._attribs['changes_list_url']
+ )
+
class Translation(LazyObject, RepoObjectMixin):
@@ -405,7 +459,7 @@ class Translation(LazyObject, RepoObjectMixin):
'is_template', 'translated_percent', 'fuzzy_percent',
'failing_checks_percent', 'last_change', 'last_author',
)
- _id = 'slug'
+ _id = 'language_code'
_mappings = {
'language': Language,
'component': Component,
@@ -423,6 +477,24 @@ class Translation(LazyObject, RepoObjectMixin):
data = self.weblate.get(self._attribs['statistics_url'])
return Statistics(weblate=self.weblate, **data)
+ def changes(self):
+ """List changes in the project."""
+ self.ensure_loaded('changes_list_url')
+ return self.weblate.list_changes(
+ self._attribs['changes_list_url']
+ )
+
+ def download(self, convert=None):
+ """Download translation file from server."""
+ self.ensure_loaded('file_url')
+ url = self._attribs['file_url']
+ if convert is not None:
+ url = '{0}?{1}'.format(
+ url,
+ urlencode({'format': convert})
+ )
+ return self.weblate.request(url, raw=True)
+
class Statistics(LazyObject):
@@ -433,3 +505,18 @@ class Statistics(LazyObject):
'total_words', 'failing', 'translated_words', 'url_translate',
'fuzzy_percent', 'translated', 'fuzzy', 'total', 'last_change', 'name',
)
+
+
+class Change(LazyObject):
+
+ """Change object."""
+
+ _params = (
+ 'url', 'unit', 'translation', 'component',
+ 'timestamp', 'action_name', 'target',
+ )
+ _id = 'id'
+ _mappings = {
+ 'translation': Translation,
+ 'component': Component,
+ }
diff --git a/wlc/config.py b/wlc/config.py
index 7951974..858fef6 100644
--- a/wlc/config.py
+++ b/wlc/config.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# Copyright © 2016 Michal Čihař <michal at cihar.com>
+# Copyright (c) 2016 Michal Cihar <michal at cihar.com>
#
# This file is part of Weblate Client <https://github.com/WeblateOrg/wlc>
#
diff --git a/wlc/main.py b/wlc/main.py
index 1c1d97f..d80b3bb 100644
--- a/wlc/main.py
+++ b/wlc/main.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# Copyright © 2016 Michal Čihař <michal at cihar.com>
+# Copyright (c) 2016 Michal Cihar <michal at cihar.com>
#
# This file is part of Weblate Client <https://github.com/WeblateOrg/wlc>
#
@@ -275,6 +275,47 @@ class ObjectCommand(Command):
"""Main execution of the command."""
raise NotImplementedError()
+ @staticmethod
+ def check_result(result, message):
+ """Check result json data."""
+ if not result['result']:
+ raise CommandError(
+ message,
+ result['detail'] if 'detail' in result else '',
+ )
+
+
+class ComponentCommand(ObjectCommand):
+
+ """Wrapper to allow only component objects."""
+
+ def get_object(self):
+ """Return component object."""
+ obj = super(ComponentCommand, self).get_object()
+ if not isinstance(obj, wlc.Component):
+ raise CommandError('Not supported')
+ return obj
+
+ def run(self):
+ """Main execution of the command."""
+ raise NotImplementedError()
+
+
+class TranslationCommand(ObjectCommand):
+
+ """Wrapper to allow only translation objects."""
+
+ def get_object(self):
+ """Return translation object."""
+ obj = super(TranslationCommand, self).get_object()
+ if not isinstance(obj, wlc.Translation):
+ raise CommandError('Not supported')
+ return obj
+
+ def run(self):
+ """Main execution of the command."""
+ raise NotImplementedError()
+
@register_command
class Version(Command):
@@ -356,7 +397,7 @@ class ListTranslations(Command):
@register_command
-class ShowObject(ObjectCommand):
+class Show(ObjectCommand):
"""Show object."""
@@ -369,7 +410,7 @@ class ShowObject(ObjectCommand):
@register_command
-class ListObject(ObjectCommand):
+class List(ObjectCommand):
"""List object."""
@@ -388,7 +429,7 @@ class ListObject(ObjectCommand):
@register_command
-class CommitObject(ObjectCommand):
+class Commit(ObjectCommand):
"""Commit object."""
@@ -399,15 +440,11 @@ class CommitObject(ObjectCommand):
"""Executor."""
obj = self.get_object()
result = obj.commit()
- if not result['result']:
- raise CommandError(
- 'Failed to commit changes!',
- result['detail'],
- )
+ self.check_result(result, 'Failed to commit changes!')
@register_command
-class PushObject(ObjectCommand):
+class Push(ObjectCommand):
"""Push object."""
@@ -421,15 +458,11 @@ class PushObject(ObjectCommand):
"""Executor."""
obj = self.get_object()
result = obj.push()
- if not result['result']:
- raise CommandError(
- 'Failed to push changes!',
- result['detail'] if 'detail' in result else '',
- )
+ self.check_result(result, 'Failed to push changes!')
@register_command
-class PullObject(ObjectCommand):
+class Pull(ObjectCommand):
"""Pull object."""
@@ -443,15 +476,29 @@ class PullObject(ObjectCommand):
"""Executor."""
obj = self.get_object()
result = obj.pull()
- if not result['result']:
- raise CommandError(
- 'Failed to pull changes!',
- result['detail'],
- )
+ self.check_result(result, 'Failed to pull changes!')
+
+
+ at register_command
+class Reset(ObjectCommand):
+
+ """Reset object."""
+
+ name = 'reset'
+ description = (
+ "Resets all changes in Weblate repository to upstream "
+ "in translation, component or project"
+ )
+
+ def run(self):
+ """Executor."""
+ obj = self.get_object()
+ result = obj.reset()
+ self.check_result(result, 'Failed to reset changes!')
@register_command
-class RepoObject(ObjectCommand):
+class Repo(ObjectCommand):
"""Display repository status for object."""
@@ -468,7 +515,24 @@ class RepoObject(ObjectCommand):
@register_command
-class StatsObject(ObjectCommand):
+class Changes(ObjectCommand):
+
+ """Display repository status for object."""
+
+ name = 'changes'
+ description = (
+ "Displays list of changes "
+ "for translation, component or project"
+ )
+
+ def run(self):
+ """Executor."""
+ obj = self.get_object()
+ self.print(list(obj.changes()))
+
+
+ at register_command
+class Stats(ObjectCommand):
"""Display repository statistics for object."""
@@ -482,31 +546,15 @@ class StatsObject(ObjectCommand):
"""Executor."""
obj = self.get_object()
if isinstance(obj, wlc.Project):
- raise CommandError('Not supported')
+ self.print(list(obj.statistics()))
elif isinstance(obj, wlc.Component):
self.print(list(obj.statistics()))
else:
self.print(obj.statistics())
-class ComponentCommand(ObjectCommand):
-
- """Wrapper to allow only component objects."""
-
- def get_object(self):
- """Return component object."""
- obj = super(ComponentCommand, self).get_object()
- if not isinstance(obj, wlc.Component):
- raise CommandError('Not supported')
- return obj
-
- def run(self):
- """Main execution of the command."""
- raise NotImplementedError()
-
-
@register_command
-class LockStatusObject(ComponentCommand):
+class LockStatus(ComponentCommand):
"""Show lock status."""
@@ -522,7 +570,7 @@ class LockStatusObject(ComponentCommand):
@register_command
-class LockObject(ComponentCommand):
+class Lock(ComponentCommand):
"""Lock component for transaltion."""
@@ -538,7 +586,7 @@ class LockObject(ComponentCommand):
@register_command
-class UnlockObject(ComponentCommand):
+class Unlock(ComponentCommand):
"""Unock component for transaltion."""
@@ -553,13 +601,43 @@ class UnlockObject(ComponentCommand):
obj.unlock()
-def main(settings=None, stdout=None, args=None):
- """Execution entry point."""
- parser = get_parser()
- if args is None:
- args = sys.argv[1:]
- args = parser.parse_args(args)
+ at register_command
+class Download(TranslationCommand):
+
+ """Downloads translation file."""
+
+ name = 'download'
+ description = (
+ "Downloads translation file"
+ )
+
+ @classmethod
+ def add_parser(cls, subparser):
+ """Create parser for command line."""
+ parser = super(Download, cls).add_parser(subparser)
+ parser.add_argument(
+ '-c', '--convert',
+ help='Convert file format on server (defaults to none)'
+ )
+ parser.add_argument(
+ '-o', '--output',
+ help='File where to store output (defaults to stdout)'
+ )
+ return parser
+
+ def run(self):
+ """Executor."""
+ obj = self.get_object()
+ content = obj.download(self.args.convert)
+ if self.args.output and self.args.output != '-':
+ with open(self.args.output, 'wb') as handle:
+ handle.write(content)
+ else:
+ self.stdout.buffer.write(content)
+
+def parse_settings(args, settings):
+ """Read settings based on command line params."""
config = WeblateConfig(args.config_section)
if settings is None:
config.load(args.config)
@@ -572,6 +650,18 @@ def main(settings=None, stdout=None, args=None):
if value is not None:
config.set(args.config_section, override, value)
+ return config
+
+
+def main(settings=None, stdout=None, args=None):
+ """Execution entry point."""
+ parser = get_parser()
+ if args is None:
+ args = sys.argv[1:]
+ args = parser.parse_args(args)
+
+ config = parse_settings(args, settings)
+
command = COMMANDS[args.cmd](args, config, stdout)
try:
command.run()
diff --git a/wlc/test_base.py b/wlc/test_base.py
index a7e3cec..5b3c8f8 100644
--- a/wlc/test_base.py
+++ b/wlc/test_base.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# Copyright © 2016 Michal Čihař <michal at cihar.com>
+# Copyright (c) 2016 Michal Cihar <michal at cihar.com>
#
# This file is part of Weblate Client <https://github.com/WeblateOrg/wlc>
#
@@ -30,10 +30,11 @@ class ResponseHandler(object):
"""httpretty response handler."""
- def __init__(self, body, filename):
+ def __init__(self, body, filename, auth=False):
"""Construct response handler object."""
self.body = body
self.filename = filename
+ self.auth = auth
def get_filename(self, request):
"""Return filename for given request."""
@@ -60,10 +61,13 @@ class ResponseHandler(object):
def __call__(self, request, uri, headers):
"""Function call interface for httpretty."""
+ if self.auth:
+ if request.headers['Authorization'] != 'Token KEY':
+ return (403, headers, '')
return (200, headers, self.get_content(request))
-def register_uri(path, domain='http://127.0.0.1:8000/api'):
+def register_uri(path, domain='http://127.0.0.1:8000/api', auth=False):
"""Simplified URL registration."""
filename = os.path.join(DATA_TEST_BASE, path.replace('/', '-'))
url = '/'.join((domain, path, ''))
@@ -71,23 +75,30 @@ def register_uri(path, domain='http://127.0.0.1:8000/api'):
httpretty.register_uri(
httpretty.GET,
url,
- body=ResponseHandler(handle.read(), filename),
+ body=ResponseHandler(handle.read(), filename, auth),
content_type='application/json'
)
httpretty.register_uri(
httpretty.POST,
url,
- body=ResponseHandler(handle.read(), filename),
+ body=ResponseHandler(handle.read(), filename, auth),
content_type='application/json'
)
-def register_error(path, code, domain='http://127.0.0.1:8000/api'):
+def raise_error(request, uri, headers):
+ """Raise IOError."""
+ # pylint: disable=W0613
+ raise IOError('Some error')
+
+
+def register_error(path, code, domain='http://127.0.0.1:8000/api', body=None):
"""Simplified URL error registration."""
url = '/'.join((domain, path, ''))
httpretty.register_uri(
httpretty.GET,
url,
+ body=body,
status=code
)
@@ -95,18 +106,26 @@ def register_error(path, code, domain='http://127.0.0.1:8000/api'):
def register_uris():
"""Register URIs for httpretty."""
paths = (
+ 'changes',
'projects', 'components', 'translations',
'projects/hello',
+ 'projects/hello/changes',
+ 'projects/hello/components',
+ 'projects/hello/statistics',
+ 'projects/empty',
+ 'projects/empty/components',
'projects/invalid',
'components/hello/weblate',
'components/hello/android',
'translations/hello/weblate/cs',
'projects/hello/repository',
'components/hello/weblate/repository',
+ 'components/hello/weblate/changes',
+ 'translations/hello/weblate/cs/file',
'translations/hello/weblate/cs/repository',
+ 'translations/hello/weblate/cs/changes',
'components/hello/weblate/statistics',
'translations/hello/weblate/cs/statistics',
- 'projects/hello/components',
'components/hello/weblate/translations',
'components/hello/weblate/lock',
'languages',
@@ -114,11 +133,14 @@ def register_uris():
for path in paths:
register_uri(path)
+ register_uri('projects/acl', auth=True)
+
register_uri('projects', domain='https://example.net')
register_error('projects/nonexisting', 404)
register_error('projects/denied', 403)
register_error('projects/throttled', 429)
register_error('projects/error', 500)
+ register_error('projects/io', 500, body=raise_error)
class APITest(TestCase):
diff --git a/wlc/test_data/api/changes b/wlc/test_data/api/changes
new file mode 100644
index 0000000..6c8281a
--- /dev/null
+++ b/wlc/test_data/api/changes
@@ -0,0 +1,35 @@
+ {
+ "count": 2,
+ "next": null,
+ "previous": null,
+ "results": [
+ {
+ "unit": null,
+ "component": "http://127.0.0.1:8000/api/components/hello/android/",
+ "url": "http://127.0.0.1:8000/api/changes/1/",
+ "translation": null,
+ "dictionary": null,
+ "user": null,
+ "author": null,
+ "timestamp": "2016-11-18T10:47:01.355911Z",
+ "action": 20,
+ "target": "",
+ "id": 353,
+ "action_name": "Sloučen repozitář"
+ },
+ {
+ "unit": "http://127.0.0.1:8000/api/units/227/",
+ "component": "http://127.0.0.1:8000/api/components/hello/weblate/",
+ "url": "http://127.0.0.1:8000/api/changes/2/",
+ "translation": "http://127.0.0.1:8000/api/translations/hello/weblate/cs/",
+ "dictionary": null,
+ "user": 2,
+ "author": 2,
+ "timestamp": "2016-10-24T07:21:54.121348Z",
+ "action": 26,
+ "target": "",
+ "id": 350,
+ "action_name": "Odstraněn návrh"
+ }
+ ]
+ }
diff --git a/wlc/test_data/api/components-hello-weblate b/wlc/test_data/api/components-hello-weblate
index 36bdad2..fbee605 100644
--- a/wlc/test_data/api/components-hello-weblate
+++ b/wlc/test_data/api/components-hello-weblate
@@ -32,6 +32,7 @@
"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/"
diff --git a/wlc/test_data/api/components-hello-weblate-changes b/wlc/test_data/api/components-hello-weblate-changes
new file mode 100644
index 0000000..6c8281a
--- /dev/null
+++ b/wlc/test_data/api/components-hello-weblate-changes
@@ -0,0 +1,35 @@
+ {
+ "count": 2,
+ "next": null,
+ "previous": null,
+ "results": [
+ {
+ "unit": null,
+ "component": "http://127.0.0.1:8000/api/components/hello/android/",
+ "url": "http://127.0.0.1:8000/api/changes/1/",
+ "translation": null,
+ "dictionary": null,
+ "user": null,
+ "author": null,
+ "timestamp": "2016-11-18T10:47:01.355911Z",
+ "action": 20,
+ "target": "",
+ "id": 353,
+ "action_name": "Sloučen repozitář"
+ },
+ {
+ "unit": "http://127.0.0.1:8000/api/units/227/",
+ "component": "http://127.0.0.1:8000/api/components/hello/weblate/",
+ "url": "http://127.0.0.1:8000/api/changes/2/",
+ "translation": "http://127.0.0.1:8000/api/translations/hello/weblate/cs/",
+ "dictionary": null,
+ "user": 2,
+ "author": 2,
+ "timestamp": "2016-10-24T07:21:54.121348Z",
+ "action": 26,
+ "target": "",
+ "id": 350,
+ "action_name": "Odstraněn návrh"
+ }
+ ]
+ }
diff --git a/wlc/test_data/api/components-hello-weblate-repository--POST--operation=reset b/wlc/test_data/api/components-hello-weblate-repository--POST--operation=reset
new file mode 100644
index 0000000..37f3410
--- /dev/null
+++ b/wlc/test_data/api/components-hello-weblate-repository--POST--operation=reset
@@ -0,0 +1,3 @@
+{
+ "result": true
+}
diff --git a/wlc/test_data/api/projects-acl b/wlc/test_data/api/projects-acl
new file mode 100644
index 0000000..286c5b7
--- /dev/null
+++ b/wlc/test_data/api/projects-acl
@@ -0,0 +1,20 @@
+{
+ "components_list_url": "http://127.0.0.1:8000/api/projects/acl/components/",
+ "name": "ACL",
+ "repository_url": "http://127.0.0.1:8000/api/projects/acl/repository/",
+ "slug": "acl",
+ "source_language": {
+ "code": "en",
+ "direction": "ltr",
+ "name": "English",
+ "nplurals": 2,
+ "pluralequation": "n != 1",
+ "url": "http://127.0.0.1:8000/api/languages/en/",
+ "web_url": "http://127.0.0.1:8000/languages/en/"
+ },
+ "url": "http://127.0.0.1:8000/api/projects/acl/",
+ "statistics_url": "http://127.0.0.1:8000/api/projects/acl/statistics/",
+ "changes_list_url": "http://127.0.0.1:8000/api/projects/acl/changes/",
+ "web": "http://weblate.org/",
+ "web_url": "http://127.0.0.1:8000/projects/acl/"
+}
diff --git a/wlc/test_data/api/projects-empty b/wlc/test_data/api/projects-empty
new file mode 100644
index 0000000..d3146e8
--- /dev/null
+++ b/wlc/test_data/api/projects-empty
@@ -0,0 +1,20 @@
... 533 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/wlc.git
More information about the Python-modules-commits
mailing list