From 638c7f77077f5cbfb64590b122b8a3f78bb8aceb Mon Sep 17 00:00:00 2001
From: Qixiang Wan <qwan@redhat.com>
Date: Jan 10 2018 05:14:19 +0000
Subject: Replace Response.data with Response.get_data()


FIXES: #172

---

diff --git a/tests/test_views.py b/tests/test_views.py
index 6acda0f..a6dd5f3 100644
--- a/tests/test_views.py
+++ b/tests/test_views.py
@@ -139,7 +139,7 @@ class TestViews(unittest.TestCase):
 
     def test_query_build(self):
         resp = self.client.get('/api/1/builds/1')
-        data = json.loads(resp.data.decode('utf8'))
+        data = json.loads(resp.get_data(as_text=True))
         self.assertEqual(data['id'], 1)
         self.assertEqual(data['name'], 'ed')
         self.assertEqual(data['type'], ArtifactType.MODULE.value)
@@ -150,7 +150,7 @@ class TestViews(unittest.TestCase):
 
     def test_query_builds(self):
         resp = self.client.get('/api/1/builds/')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 3)
         for name in ['ed', 'mksh', 'bash']:
             self.assertIn(name, [b['name'] for b in builds])
@@ -167,58 +167,58 @@ class TestViews(unittest.TestCase):
         db.session.commit()
         db.session.expire_all()
         resp = self.client.get('/api/1/builds/')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 5)
         for id, build in zip([1, 2, 3, 8, 9], builds):
             self.assertEqual(id, build['id'])
 
     def test_query_builds_by_name(self):
         resp = self.client.get('/api/1/builds/?name=ed')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 1)
         self.assertEqual(builds[0]['name'], 'ed')
 
         resp = self.client.get('/api/1/builds/?name=mksh')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 1)
         self.assertEqual(builds[0]['name'], 'mksh')
 
         resp = self.client.get('/api/1/builds/?name=nonexist')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 0)
 
     def test_query_builds_by_type(self):
         resp = self.client.get('/api/1/builds/?type=0')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 0)
 
         resp = self.client.get('/api/1/builds/?type=1')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 0)
 
         resp = self.client.get('/api/1/builds/?type=2')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 3)
 
         resp = self.client.get('/api/1/builds/?type=module')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 3)
 
     def test_query_builds_by_invalid_type(self):
         resp = self.client.get('/api/1/builds/?type=100')
-        data = json.loads(resp.data.decode('utf8'))
+        data = json.loads(resp.get_data(as_text=True))
         self.assertEqual(data["status"], 400)
         self.assertEqual(data["message"],
                          "An invalid artifact type was supplied")
 
     def test_query_builds_by_state(self):
         resp = self.client.get('/api/1/builds/?state=0')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 3)
 
     def test_query_builds_by_invalid_state(self):
         resp = self.client.get('/api/1/builds/?state=100')
-        data = json.loads(resp.data.decode('utf8'))
+        data = json.loads(resp.get_data(as_text=True))
         self.assertEqual(data["status"], 400)
         self.assertEqual(data["message"],
                          "An invalid state was supplied")
@@ -243,42 +243,42 @@ class TestViews(unittest.TestCase):
         db.session.commit()
 
         resp = self.client.get('/api/1/builds/?event_type_id=%s' % models.EVENT_TYPES[events.TestingEvent])
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 3)
 
         resp = self.client.get('/api/1/builds/?event_type_id=%s' % models.EVENT_TYPES[events.GitModuleMetadataChangeEvent])
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 2)
 
         resp = self.client.get('/api/1/builds/?event_type_id=%s' % models.EVENT_TYPES[events.MBSModuleStateChangeEvent])
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 1)
 
         resp = self.client.get('/api/1/builds/?event_type_id=%s' % models.EVENT_TYPES[events.KojiTaskStateChangeEvent])
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 0)
 
     def test_query_build_by_event_search_key(self):
         resp = self.client.get('/api/1/builds/?event_search_key=RHSA-2018-101')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 3)
 
         resp = self.client.get('/api/1/builds/?event_search_key=RHSA-2018-102')
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 0)
 
     def test_query_build_by_event_type_id_and_search_key(self):
         resp = self.client.get('/api/1/builds/?event_type_id=%s&event_search_key=RHSA-2018-101' % models.EVENT_TYPES[events.TestingEvent])
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 3)
 
         resp = self.client.get('/api/1/builds/?event_type_id=%s&event_search_key=RHSA-2018-102' % models.EVENT_TYPES[events.TestingEvent])
-        builds = json.loads(resp.data.decode('utf8'))['items']
+        builds = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(builds), 0)
 
     def test_query_event(self):
         resp = self.client.get('/api/1/events/1')
-        data = json.loads(resp.data.decode('utf8'))
+        data = json.loads(resp.get_data(as_text=True))
         self.assertEqual(data['id'], 1)
         self.assertEqual(data['message_id'], '2017-00000000-0000-0000-0000-000000000001')
         self.assertEqual(data['search_key'], 'RHSA-2018-101')
@@ -287,74 +287,74 @@ class TestViews(unittest.TestCase):
 
     def test_query_events(self):
         resp = self.client.get('/api/1/events/')
-        evs = json.loads(resp.data.decode('utf8'))['items']
+        evs = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(evs), 2)
 
     def test_query_event_by_message_id(self):
         resp = self.client.get('/api/1/events/?message_id=2017-00000000-0000-0000-0000-000000000001')
-        evs = json.loads(resp.data.decode('utf8'))['items']
+        evs = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(evs), 1)
         self.assertEqual(evs[0]['message_id'], '2017-00000000-0000-0000-0000-000000000001')
 
     def test_query_event_by_search_key(self):
         resp = self.client.get('/api/1/events/?search_key=RHSA-2018-101')
-        evs = json.loads(resp.data.decode('utf8'))['items']
+        evs = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(evs), 1)
         self.assertEqual(evs[0]['search_key'], 'RHSA-2018-101')
 
     def test_query_event_types(self):
         resp = self.client.get('/api/1/event-types/')
-        event_types = json.loads(resp.data.decode('utf8'))['items']
+        event_types = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(event_types), len(models.EVENT_TYPES))
 
     def test_query_event_type(self):
         for cls, val in six.iteritems(models.EVENT_TYPES):
             resp = self.client.get('/api/1/event-types/%s' % val)
-            event = json.loads(resp.data.decode('utf8'))
+            event = json.loads(resp.get_data(as_text=True))
             self.assertEqual(event['id'], val)
             self.assertEqual(event['name'], cls.__name__)
 
     def test_query_nonexist_event_type(self):
         resp = self.client.get('/api/1/event-types/99999')
-        data = json.loads(resp.data.decode('utf8'))
+        data = json.loads(resp.get_data(as_text=True))
         self.assertEqual(data['status'], 404)
         self.assertEqual(data['error'], 'Not Found')
         self.assertEqual(data['message'], 'No such event type found.')
 
     def test_query_build_types(self):
         resp = self.client.get('/api/1/build-types/')
-        build_types = json.loads(resp.data.decode('utf8'))['items']
+        build_types = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(build_types), len(list(ArtifactType)))
 
     def test_query_build_type(self):
         for t in list(ArtifactType):
             resp = self.client.get('/api/1/build-types/%s' % t.value)
-            build_type = json.loads(resp.data.decode('utf8'))
+            build_type = json.loads(resp.get_data(as_text=True))
             self.assertEqual(build_type['id'], t.value)
             self.assertEqual(build_type['name'], t.name)
 
     def test_query_nonexist_build_type(self):
         resp = self.client.get('/api/1/build-types/99999')
-        data = json.loads(resp.data.decode('utf8'))
+        data = json.loads(resp.get_data(as_text=True))
         self.assertEqual(data['status'], 404)
         self.assertEqual(data['error'], 'Not Found')
         self.assertEqual(data['message'], 'No such build type found.')
 
     def test_query_build_states(self):
         resp = self.client.get('/api/1/build-states/')
-        build_types = json.loads(resp.data.decode('utf8'))['items']
+        build_types = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(build_types), len(list(ArtifactBuildState)))
 
     def test_query_build_state(self):
         for t in list(ArtifactBuildState):
             resp = self.client.get('/api/1/build-states/%s' % t.value)
-            build_type = json.loads(resp.data.decode('utf8'))
+            build_type = json.loads(resp.get_data(as_text=True))
             self.assertEqual(build_type['id'], t.value)
             self.assertEqual(build_type['name'], t.name)
 
     def test_query_nonexist_build_state(self):
         resp = self.client.get('/api/1/build-states/99999')
-        data = json.loads(resp.data.decode('utf8'))
+        data = json.loads(resp.get_data(as_text=True))
         self.assertEqual(data['status'], 404)
         self.assertEqual(data['error'], 'Not Found')
         self.assertEqual(data['message'], 'No such build state found.')
@@ -394,14 +394,14 @@ class TestViewsMultipleFilterValues(unittest.TestCase):
     def test_query_event_multiple_states(self):
         resp = self.client.get('/api/1/events/?state=%d&state=%d' % (
             EventState.SKIPPED.value, EventState.BUILDING.value))
-        evs = json.loads(resp.data.decode('utf8'))['items']
+        evs = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(evs), 2)
 
     def test_query_event_multiple_event_type_ids(self):
         resp = self.client.get('/api/1/events/?event_type_id=%d&event_type_id=%d' % (
             models.EVENT_TYPES[events.TestingEvent],
             models.EVENT_TYPES[events.GitModuleMetadataChangeEvent]))
-        evs = json.loads(resp.data.decode('utf8'))['items']
+        evs = json.loads(resp.get_data(as_text=True))['items']
         self.assertEqual(len(evs), 2)
 
 
@@ -425,7 +425,7 @@ class TestManualTriggerRebuild(unittest.TestCase):
         resp = self.client.post('/api/1/builds/',
                                 data=json.dumps({'errata_id': 1}),
                                 content_type='application/json')
-        data = json.loads(resp.data.decode('utf-8'))
+        data = json.loads(resp.get_data(as_text=True))
 
         self.assertEqual(data["errata_id"], 1)
         publish.assert_called_once_with('manual.rebuild', {u'errata_id': 1})

