- missing @pytest.yield_fixture in epel-6
- portable (Python 2.6) format strings
- to_json() hashes do not guarantee item order
---
 python/copr/client/client.py                  |  6 ++--
 python/copr/client_v2/common.py               |  6 ++--
 python/copr/client_v2/entities.py             | 25 ++++++++---------
 python/copr/client_v2/handlers.py             | 32 ++++++++++-----------
 python/copr/client_v2/net_client.py           | 10 +++----
 python/copr/client_v2/resources.py            |  4 +--
 python/copr/test/client_v2/test_entities.py   |  4 +--
 python/copr/test/client_v2/test_handlers.py   |  2 +-
 python/copr/test/client_v2/test_net_client.py | 40 ++++++++++++---------------
 python/docs/client_v1/Examples.rst            | 10 +++----
 python/run_tmp.py                             |  6 ++--
 11 files changed, 70 insertions(+), 75 deletions(-)

diff --git a/python/copr/client/client.py b/python/copr/client/client.py
index 01929b1..79f233f 100644
--- a/python/copr/client/client.py
+++ b/python/copr/client/client.py
@@ -93,7 +93,7 @@ class CoprClient(UnicodeMixin):
 
     def __unicode__(self):
         return (
-            u"<Copr client. username: {}, api url: {}, login presents: {}, 
token presents: {}>"
+            u"<Copr client. username: {0}, api url: {1}, login presents: {2}, 
token presents: {3}>"
             .format(self.username, self.api_url, bool(self.login), 
bool(self.token))
         )
 
@@ -211,8 +211,8 @@ class CoprClient(UnicodeMixin):
             output = json.loads(response.text)
         except ValueError:
             raise CoprUnknownResponseException(
-                "Unknown response from the server. Code: {}, raw response:"
-                " \n {}".format(response.status_code, response.text))
+                "Unknown response from the server. Code: {0}, raw response:"
+                " \n {1}".format(response.status_code, response.text))
         if response.status_code != 200:
             raise CoprRequestException(output["error"])
 
diff --git a/python/copr/client_v2/common.py b/python/copr/client_v2/common.py
index 2ccd3ec..bdfe0ba 100644
--- a/python/copr/client_v2/common.py
+++ b/python/copr/client_v2/common.py
@@ -19,7 +19,7 @@ class BuiltPackage(UnicodeMixin):
         self.version = version
 
     def __unicode__(self):
-        return u"{} {}".format(self.name, self.version)
+        return u"{0} {1}".format(self.name, self.version)
 
 
 class BuildStateValues(object):
@@ -33,7 +33,7 @@ class BuildStateValues(object):
     IMPORTING = "importing"
     UNKNOWN = "unknown"
 
-ALLOWED_BUILD_STATES = {
+ALLOWED_BUILD_STATES = set([
     BuildStateValues.FAILED,
     BuildStateValues.SUCCEEDED,
     BuildStateValues.CANCELED,
@@ -43,4 +43,4 @@ ALLOWED_BUILD_STATES = {
     BuildStateValues.STARTING,
     BuildStateValues.IMPORTING,
     BuildStateValues.UNKNOWN,
-}
+])
diff --git a/python/copr/client_v2/entities.py 
b/python/copr/client_v2/entities.py
index 9750338..de0ae49 100644
--- a/python/copr/client_v2/entities.py
+++ b/python/copr/client_v2/entities.py
@@ -11,15 +11,14 @@ class Link(UnicodeMixin):
         self.href = href
 
     def __unicode__(self):
-        return u"<Link: role: {}, href: {}".format(self.role, self.href)
+        return u"<Link: role: {0}, href: {1}".format(self.role, self.href)
 
     @classmethod
     def from_dict(cls, data_dict):
-        return {
-            role_name:
-                cls(role_name, definition["href"])
-            for role_name, definition in data_dict.items()
-        }
+        retval = {}
+        for role_name, definition in data_dict.items():
+            retval[role_name] = cls(role_name, definition["href"])
+        return retval
 
 
 # pylint: disable=E1101
@@ -46,21 +45,21 @@ class ProjectEntity(Entity):
     _schema = ProjectSchema(strict=True)
 
     def __unicode__(self):
-        return "<Project #{}: {}/{}>".format(self.id, self.owner, self.name)
+        return "<Project #{0}: {1}/{2}>".format(self.id, self.owner, self.name)
 
 
 class ProjectCreateEntity(Entity):
     _schema = ProjectCreateSchema(strict=True)
 
     def __unicode__(self):
-        return "<New project {}/{}>".format(self.owner, self.name)
+        return "<New project {0}/{1}>".format(self.owner, self.name)
 
 class ProjectChrootEntity(Entity):
     _schema = ProjectChrootSchema(strict=True)
 
     def __unicode__(self):
-        return "<Project chroot: {}, additional " \
-               "packages: {}, comps size if any: {}>"\
+        return "<Project chroot: {0}, additional " \
+               "packages: {1}, comps size if any: {2}>"\
             .format(self.name, self.buildroot_pkgs, self.comps_len,)
 
 
@@ -68,7 +67,7 @@ class BuildEntity(Entity):
     _schema = BuildSchema(strict=True)
 
     def __unicode__(self):
-        return "<Build #{} state: {}>".format(self.id, self.state)
+        return "<Build #{0} state: {1}>".format(self.id, self.state)
 
     def is_finished(self):
         """
@@ -87,7 +86,7 @@ class BuildTaskEntity(Entity):
     _schema = BuildTaskSchema(strict=True)
 
     def __unicode__(self):
-        return "<Build task #{}-{}, state: {}>".format(
+        return "<Build task #{0}-{1}, state: {2}>".format(
             self.build_id, self.chroot_name, self.state
         )
 
@@ -96,6 +95,6 @@ class MockChrootEntity(Entity):
     _schema = MockChrootSchema(strict=True)
 
     def __unicode__(self):
-        return "<Mock chroot: {} is active: {}>".format(
+        return "<Mock chroot: {0} is active: {1}>".format(
             self.name, self.is_active
         )
diff --git a/python/copr/client_v2/handlers.py 
b/python/copr/client_v2/handlers.py
index ee745d9..da9fa07 100644
--- a/python/copr/client_v2/handlers.py
+++ b/python/copr/client_v2/handlers.py
@@ -32,7 +32,7 @@ class BuildHandle(AbstractHandle):
     def __init__(self, client, nc, root_url, builds_href):
         super(BuildHandle, self).__init__(client, nc, root_url)
         self.builds_href = builds_href
-        self._base_url = "{}{}".format(self.root_url, builds_href)
+        self._base_url = "{0}{1}".format(self.root_url, builds_href)
 
     def get_base_url(self):
         return self._base_url
@@ -45,7 +45,7 @@ class BuildHandle(AbstractHandle):
         """
 
         options = {"build_id": build_id}
-        url = "{}/{}".format(self.get_base_url(), build_id)
+        url = "{0}/{1}".format(self.get_base_url(), build_id)
         response = self.nc.request(url)
         return Build.from_response(
             handle=self,
@@ -85,7 +85,7 @@ class BuildHandle(AbstractHandle):
         build_id = build_entity.id
         build_entity.state = "canceled"
 
-        url = "{}/{}".format(self.get_base_url(), build_id)
+        url = "{0}/{1}".format(self.get_base_url(), build_id)
         response = self.nc.request(url, data=build_entity.to_json(), 
method="PUT", do_auth=True)
         return OperationResult(self, response)
 
@@ -97,7 +97,7 @@ class BuildHandle(AbstractHandle):
         :rtype: :py:class:`.OperationResult`
         """
 
-        url = "{}/{}".format(self.get_base_url(), build_id)
+        url = "{0}/{1}".format(self.get_base_url(), build_id)
         response = self.nc.request(url, method="delete", do_auth=True)
         return OperationResult(self, response, expected_status=204)
 
@@ -212,7 +212,7 @@ class BuildTaskHandle(AbstractHandle):
     def __init__(self, client, nc, root_url, build_tasks_href):
         super(BuildTaskHandle, self).__init__(client, nc, root_url)
         self.build_tasks_href = build_tasks_href
-        self._base_url = "{}{}".format(self.root_url, build_tasks_href)
+        self._base_url = "{0}{1}".format(self.root_url, build_tasks_href)
 
     def get_base_url(self):
         return self._base_url
@@ -256,7 +256,7 @@ class BuildTaskHandle(AbstractHandle):
         :rtype:  :py:class:`~.resources.BuildTask`
         """
 
-        url = "{}/{}/{}".format(self.get_base_url(), build_id, chroot_name)
+        url = "{0}/{1}/{2}".format(self.get_base_url(), build_id, chroot_name)
         response = self.nc.request(url)
         return BuildTask.from_response(
             handle=self,
@@ -270,7 +270,7 @@ class ProjectHandle(AbstractHandle):
     def __init__(self, client, nc, root_url, projects_href):
         super(ProjectHandle, self).__init__(client, nc, root_url)
         self.projects_href = projects_href
-        self._base_url = "{}{}".format(self.root_url, projects_href)
+        self._base_url = "{0}{1}".format(self.root_url, projects_href)
 
     def get_base_url(self):
         return self._base_url
@@ -309,7 +309,7 @@ class ProjectHandle(AbstractHandle):
             # "show_chroots": show_chroots
         }
 
-        url = "{}/{}".format(self.get_base_url(), project_id)
+        url = "{0}/{1}".format(self.get_base_url(), project_id)
         response = self.nc.request(url, query_params=query_params)
         return Project.from_response(
             handle=self,
@@ -374,7 +374,7 @@ class ProjectHandle(AbstractHandle):
         :type project_entity: :py:class:`~.ProjectEntity`
         :rtype: OperationResult
         """
-        url = "{}/{}".format(self.get_base_url(), project_entity.id)
+        url = "{0}/{1}".format(self.get_base_url(), project_entity.id)
         data = project_entity.to_json()
 
         response = self.nc.request(url, method="put", data=data, do_auth=True)
@@ -386,7 +386,7 @@ class ProjectHandle(AbstractHandle):
         :param int project_id: project identifier
         :rtype: OperationResult
         """
-        url = "{}/{}".format(self.get_base_url(), project_id)
+        url = "{0}/{1}".format(self.get_base_url(), project_id)
         response = self.nc.request(url, method="delete", do_auth=True)
         return OperationResult(self, response, expected_status=204)
 
@@ -415,7 +415,7 @@ class ProjectChrootHandle(AbstractHandle):
         """
         :type project: copr.client_v2.resources.Project
         """
-        return "{}{}".format(self.root_url, 
project.get_href_by_name("chroots"))
+        return "{0}{1}".format(self.root_url, 
project.get_href_by_name("chroots"))
 
     def get_one(self, project, name):
         """ Retrieves project chroot object.
@@ -427,7 +427,7 @@ class ProjectChrootHandle(AbstractHandle):
         :rtype: :py:class:`~copr.client_v2.resources.ProjectChroot`
         """
 
-        url = "{}/{}".format(self.get_base_url(project), name)
+        url = "{0}/{1}".format(self.get_base_url(project), name)
         response = self.nc.request(url)
 
         return ProjectChroot.from_response(
@@ -460,7 +460,7 @@ class ProjectChrootHandle(AbstractHandle):
 
         :param str name: chroot name to disable
         """
-        url = "{}/{}".format(self.get_base_url(project), name)
+        url = "{0}/{1}".format(self.get_base_url(project), name)
         response = self.nc.request(url, method="DELETE", do_auth=True)
         return OperationResult(self, response)
 
@@ -498,7 +498,7 @@ class ProjectChrootHandle(AbstractHandle):
 
         :rtype: :py:class:`.OperationResult`
         """
-        url = "{}/{}".format(self.get_base_url(project), chroot_entity.name)
+        url = "{0}/{1}".format(self.get_base_url(project), chroot_entity.name)
         response = self.nc.request(
             url,
             method="PUT",
@@ -513,7 +513,7 @@ class MockChrootHandle(AbstractHandle):
     def __init__(self, client, nc, root_url, href):
         super(MockChrootHandle, self).__init__(client, nc, root_url)
         self._href = href
-        self._base_url = "{}{}".format(self.root_url, href)
+        self._base_url = "{0}{1}".format(self.root_url, href)
 
     def get_base_url(self):
         return self._base_url
@@ -525,7 +525,7 @@ class MockChrootHandle(AbstractHandle):
 
         :rtype: :py:class:`~copr.client_v2.resources.MockChroot`
         """
-        url = "{}/{}".format(self.get_base_url(), name)
+        url = "{0}/{1}".format(self.get_base_url(), name)
         response = self.nc.get(url)
         return MockChroot.from_response(
             handle=self,
diff --git a/python/copr/client_v2/net_client.py 
b/python/copr/client_v2/net_client.py
index f44073d..369b651 100644
--- a/python/copr/client_v2/net_client.py
+++ b/python/copr/client_v2/net_client.py
@@ -34,7 +34,7 @@ class RequestError(Exception, UnicodeMixin):
             except (ValueError, AttributeError):
                 raise ValueError(
                     "Malformed response, couldn't "
-                    "get json content, raw:\n{}"
+                    "get json content, raw:\n{0}"
                     .format(self.response.text)
                 )
 
@@ -43,10 +43,10 @@ class RequestError(Exception, UnicodeMixin):
             return None
 
     def __unicode__(self):
-        res = "Error occurred while accessing {}: {}\n".format(
+        res = "Error occurred while accessing {0}: {1}\n".format(
             self.url, self.msg)
         if self.response is not None:
-            res += "code {}: {}\n".format(self.response.status_code, 
self.response_json["message"])
+            res += "code {0}: {1}\n".format(self.response.status_code, 
self.response_json["message"])
         return res
 
 
@@ -58,7 +58,7 @@ class NetworkError(RequestError):
 
     def __unicode__(self):
         res = super(NetworkError, self).__unicode__()
-        res += u"Original error: {}\n".format(self.requests_error)
+        res += u"Original error: {0}\n".format(self.requests_error)
         return res
 
 
@@ -134,7 +134,7 @@ class NetClient(object):
         if method is None:
             method = "get"
         elif method.lower() not in ["get", "post", "delete", "put"]:
-            raise RequestError("Method {} not allowed".format(method), url)
+            raise RequestError("Method {0} not allowed".format(method), url)
 
         kwargs = {}
         headers = headers or {}
diff --git a/python/copr/client_v2/resources.py 
b/python/copr/client_v2/resources.py
index b4abcc4..b60f207 100644
--- a/python/copr/client_v2/resources.py
+++ b/python/copr/client_v2/resources.py
@@ -116,7 +116,7 @@ class Root(IndividualResource):
         """
         :param str resource_name:
         """
-        return "{}{}".format(self.root_url, 
self.get_href_by_name(resource_name))
+        return "{0}{1}".format(self.root_url, 
self.get_href_by_name(resource_name))
 
     @classmethod
     def from_response(cls, response, root_url):
@@ -412,7 +412,7 @@ class OperationResult(IndividualResource):
     def __unicode__(self):
         out = u"<Result: "
         if self._response:
-            out += u" status: {}".format(self._response.status_code)
+            out += u" status: {0}".format(self._response.status_code)
         out += u">"
 
         return out
diff --git a/python/copr/test/client_v2/test_entities.py 
b/python/copr/test/client_v2/test_entities.py
index 44b008d..ff00c79 100644
--- a/python/copr/test/client_v2/test_entities.py
+++ b/python/copr/test/client_v2/test_entities.py
@@ -35,6 +35,6 @@ class TestEntities(object):
                set([("foo", "baz"), ("bar", 123)])
 
     def test_to_json(self):
-        assert self.entity.to_json() == \
-               '{"foo": "baz", "bar": 123}'
+        assert self.entity.to_json() == '{"foo": "baz", "bar": 123}' \
+            or self.entity.to_json() == '{"bar": 123, "foo": "baz"}'
 
diff --git a/python/copr/test/client_v2/test_handlers.py 
b/python/copr/test/client_v2/test_handlers.py
index 8af03ba..73a4fe3 100644
--- a/python/copr/test/client_v2/test_handlers.py
+++ b/python/copr/test/client_v2/test_handlers.py
@@ -210,4 +210,4 @@ class TestProjectHandle(TestHandleBase):
         ca = self.nc.request.call_args
 
         assert ca[1]["method"] == "delete"
-        assert ca[0][0] == self.root_url + 
"/api_2/projects/{}".format(self.project_1_id)
+        assert ca[0][0] == self.root_url + 
"/api_2/projects/{0}".format(self.project_1_id)
diff --git a/python/copr/test/client_v2/test_net_client.py 
b/python/copr/test/client_v2/test_net_client.py
index 826452f..80470a1 100644
--- a/python/copr/test/client_v2/test_net_client.py
+++ b/python/copr/test/client_v2/test_net_client.py
@@ -14,12 +14,6 @@ import pytest
 from copr.client_v2.net_client import NetClient, RequestError
 
 
[email protected]_fixture
-def mc_request():
-    with mock.patch('copr.client_v2.net_client.request') as handle:
-        yield handle
-
-
 class TestNetClient(object):
 
     def setup_method(self, method):
@@ -42,20 +36,22 @@ class TestNetClient(object):
         self.nc = NetClient()
         self.nc_with_auth = NetClient(self.login, self.password)
 
-    def test_get_simple(self, mc_request):
-        mc_request.return_value = self.base_response
-        res = self.nc.request(self.base_url)
-        # import ipdb; ipdb.set_trace()
-        assert res.status_code == self.base_response.status_code
-        assert res.json == self.content
-        assert res.headers == self.base_response.headers
-
-    def test_unsupported_method(self, mc_request):
-        with pytest.raises(RequestError) as exc_info:
-            self.nc.request(self.base_url, method="non_existing_method")
-
-        # some coverage for Request error
-        assert str(exc_info.value) is not None
-        with pytest.raises(ValueError):
+    def test_get_simple(self):
+        with mock.patch('copr.client_v2.net_client.request') as mc_request:
+            mc_request.return_value = self.base_response
+            res = self.nc.request(self.base_url)
             # import ipdb; ipdb.set_trace()
-            assert exc_info.value.response_json
+            assert res.status_code == self.base_response.status_code
+            assert res.json == self.content
+            assert res.headers == self.base_response.headers
+
+    def test_unsupported_method(self):
+        with mock.patch('copr.client_v2.net_client.request') as mc_request:
+            with pytest.raises(RequestError) as exc_info:
+                self.nc.request(self.base_url, method="non_existing_method")
+
+            # some coverage for Request error
+            assert str(exc_info.value) is not None
+            with pytest.raises(ValueError):
+                # import ipdb; ipdb.set_trace()
+                assert exc_info.value.response_json
diff --git a/python/docs/client_v1/Examples.rst 
b/python/docs/client_v1/Examples.rst
index 37171e2..d298a8b 100644
--- a/python/docs/client_v1/Examples.rst
+++ b/python/docs/client_v1/Examples.rst
@@ -73,7 +73,7 @@ Work with builds
 
     # retrieve build statuses
     for bw in result.builds_list:
-        print("{}:{}".format(bw.build_id, 
bw.handle.get_build_details().status))
+        print("{0}:{1}".format(bw.build_id, 
bw.handle.get_build_details().status))
 
     # cancel all created build
     for bw in result.builds_list:
@@ -81,21 +81,21 @@ Work with builds
 
     # get build status for each chroot
     for bw in result.builds_list:
-        print("build: {}".format(bw.build_id))
+        print("build: {0}".format(bw.build_id))
         for ch, status in 
bw.handle.get_build_details().data["chroots"].items():
-            print("\t chroot {}:\t {}".format(ch, status))
+            print("\t chroot {0}:\t {1}".format(ch, status))
 
     # simple build progress:
     import time, datetime
     watched = set(result.builds_list)
     done = set()
     while watched != done:
-        print("time: {}".format(datetime.datetime.now()))
+        print("time: {0}".format(datetime.datetime.now()))
         for bw in watched:
             if bw in done:
                 continue
             status = bw.handle.get_build_details().status
-            print("{}: {}".format(bw.build_id, status))
+            print("{0}: {1}".format(bw.build_id, status))
             if status in ["skipped", "failed", "succeeded"]:
                 done.add(bw)
         time.sleep(10)
diff --git a/python/run_tmp.py b/python/run_tmp.py
index 780db44..de0d827 100644
--- a/python/run_tmp.py
+++ b/python/run_tmp.py
@@ -23,7 +23,7 @@ def main():
     )
 
     def pp(project):
-        print("Project: {} id {}, {}\n {}\n{}".format(
+        print("Project: {0} id {1}, {2}\n {3}\n{4}".format(
             project.name,
             project.id,
             project.description,
@@ -145,9 +145,9 @@ if __name__ == "__main__":
         main()
     except RequestError as err:
         log.exception(err)
-        log.error("error occurred while fetching: {}, with params: {}"
+        log.error("error occurred while fetching: {0}, with params: {1}"
                   .format(err.url, err.request_kwargs))
-        log.error("status code: {}, message: {} {}"
+        log.error("status code: {0}, message: {1} {2}"
                   .format(err.response.status_code, err.msg, 
err.response_json))
     except Exception:
         log.exception("something went wrong")
-- 
2.5.0
_______________________________________________
copr-devel mailing list
[email protected]
https://lists.fedorahosted.org/admin/lists/[email protected]

Reply via email to