From 16e0503ba2a65c7c48210d5c255db9c068cc92aa Mon Sep 17 00:00:00 2001
From: Corey Bryant <corey.bryant@canonical.com>
Date: Tue, 31 Jul 2018 17:10:20 -0400
Subject: [PATCH] Py3.7 compatibility

Handle StopIteration for Py3.7:

PEP 0479 Replace raise of StopIteration with return. PEP 0479,
https://www.python.org/dev/peps/pep-0479/, makes the following
change: "when StopIteration is raised inside a generator, it is
replaced it with RuntimeError". And states: "If raise StopIteration
occurs directly in a generator, simply replace it with return."

Also update expected dict ordering in test_update().

Closes-Bug: #1784714
---
 glareclient/tests/unit/v1/test_artifacts.py | 30 ++++++++++++++-------
 glareclient/v1/artifacts.py                 |  2 +-
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/glareclient/tests/unit/v1/test_artifacts.py b/glareclient/tests/unit/v1/test_artifacts.py
index 2fd0450..0a2499e 100644
--- a/glareclient/tests/unit/v1/test_artifacts.py
+++ b/glareclient/tests/unit/v1/test_artifacts.py
@@ -15,6 +15,7 @@
 
 import io
 import os
+import six
 import tempfile
 
 import mock
@@ -50,15 +51,26 @@ class TestController(testtools.TestCase):
         body = self.c.update('test-id', type_name='test_name',
                              remove_props=remove_props, update1=1, update2=2)
         self.assertEqual(self.mock_body, body)
-        patch_kwargs = {
-            'headers': {'Content-Type': 'application/json-patch+json'},
-            'json': [
-                {'path': '/remove1', 'value': None, 'op': 'replace'},
-                {'path': '/remove2', 'value': None, 'op': 'replace'},
-                {'path': '/update2', 'value': 2, 'op': 'add'},
-                {'path': '/update1', 'value': 1, 'op': 'add'}
-            ]
-        }
+        if six.PY3:
+            patch_kwargs = {
+                'headers': {'Content-Type': 'application/json-patch+json'},
+                'json': [
+                    {'op': 'replace', 'path': '/remove1', 'value': None},
+                    {'op': 'replace', 'path': '/remove2', 'value': None},
+                    {'op': 'add', 'path': '/update1', 'value': 1},
+                    {'op': 'add', 'path': '/update2', 'value': 2}
+                ]
+            }
+        else:
+            patch_kwargs = {
+                'headers': {'Content-Type': 'application/json-patch+json'},
+                'json': [
+                    {'path': '/remove1', 'value': None, 'op': 'replace'},
+                    {'path': '/remove2', 'value': None, 'op': 'replace'},
+                    {'path': '/update2', 'value': 2, 'op': 'add'},
+                    {'path': '/update1', 'value': 1, 'op': 'add'}
+                ]
+            }
         self.mock_http_client.patch.assert_called_once_with(
             '/artifacts/checked_name/test-id', **patch_kwargs)
         self.c._check_type_name.assert_called_once_with('test_name')
diff --git a/glareclient/v1/artifacts.py b/glareclient/v1/artifacts.py
index bfe549b..cf55975 100644
--- a/glareclient/v1/artifacts.py
+++ b/glareclient/v1/artifacts.py
@@ -171,7 +171,7 @@ class Controller(object):
                     if limit:
                         limit -= 1
                         if limit <= 0:
-                            raise StopIteration
+                            return
 
                 try:
                     next_url = body['next']
-- 
2.17.1

