Repository: zhmcclient/python-zhmcclient

Issue:
zhmcclient_mock/_urihandler.py:315: TypeError

[test_27.log.txt](https://github.com/zhmcclient/python-zhmcclient/files/1309064/test_27.log.txt)

### Actual behavior
MetricsContextHandlersTests.test_create_get_delete_context fails due to a TypeError in file zhmcclient_mock/_urihandler.py, line 315.

This unit test error avoids to run successfully in Travis for master branch.

### Expected behavior


### Execution environment

* zhmcclient version: master



Discussion:

Patch:
diff --git a/zhmcclient_mock/_urihandler.py b/zhmcclient_mock/_urihandler.py
index 3124ff2..d703b52 100644
--- a/zhmcclient_mock/_urihandler.py
+++ b/zhmcclient_mock/_urihandler.py
@@ -503,10 +503,11 @@ class CpcExportPortNamesListHandler(object):
 class MetricsContextsHandler(object):
 
     @staticmethod
-    def post(hmc, uri, uri_parms, body, logon_required, wait_for_completion):
+    def post(method, hmc, uri, uri_parms, body, logon_required,
+             wait_for_completion):
         """Operation: Create Metrics Context."""
         assert wait_for_completion is True  # always synchronous
-        check_required_fields('POST', uri, body,
+        check_required_fields(method, uri, body,
                               ['anticipated-frequency-seconds'])
         new_metrics_context = hmc.metrics_contexts.add(body)
         result = {
@@ -519,21 +520,21 @@ class MetricsContextsHandler(object):
 class MetricsContextHandler(object):
 
     @staticmethod
-    def delete(hmc, uri, uri_parms, logon_required):
+    def delete(method, hmc, uri, uri_parms, logon_required):
         """Operation: Delete Metrics Context."""
         try:
             metrics_context = hmc.lookup_by_uri(uri)
         except KeyError:
-            raise InvalidResourceError('DELETE', uri)
+            raise InvalidResourceError(method, uri)
         hmc.metrics_contexts.remove(metrics_context.oid)
 
     @staticmethod
-    def get(hmc, uri, uri_parms, logon_required):
+    def get(method, hmc, uri, uri_parms, logon_required):
         """Operation: Get Metrics."""
         try:
             metrics_context = hmc.lookup_by_uri(uri)
         except KeyError:
-            raise InvalidResourceError('GET', uri)
+            raise InvalidResourceError(method, uri)
         result = metrics_context.get_metric_values_response()
         return result
 


Test patch:
diff --git a/tests/unit/zhmcclient_mock/test_urihandler.py b/tests/unit/zhmcclient_mock/test_urihandler.py
index 7c23cd4..324a9b5 100755
--- a/tests/unit/zhmcclient_mock/test_urihandler.py
+++ b/tests/unit/zhmcclient_mock/test_urihandler.py
@@ -21,12 +21,11 @@ from __future__ import absolute_import, print_function
 
 import requests.packages.urllib3
 import unittest
-# from datetime import datetime
+from datetime import datetime
 from mock import MagicMock
 
-# from zhmcclient_mock._hmc import FakedHmc, FakedMetricGroupDefinition, \
-#    FakedMetricObjectValues
-from zhmcclient_mock._hmc import FakedHmc
+from zhmcclient_mock._hmc import FakedHmc, FakedMetricGroupDefinition, \
+    FakedMetricObjectValues
 
 from zhmcclient_mock._urihandler import HTTPError, InvalidResourceError, \
     InvalidMethodError, CpcNotInDpmError, CpcInDpmError, \
@@ -1033,134 +1032,134 @@ class MetricsContextHandlersTests(unittest.TestCase):
         )
         self.urihandler = UriHandler(self.uris)
 
-#    def test_create_get_delete_context(self):
-#
-#        mc_mgr = self.hmc.metrics_contexts
-#
-#        # Prepare faked metric group definitions
-#
-#        mg_name = 'partition-usage'
-#        mg_def = FakedMetricGroupDefinition(
-#            name=mg_name,
-#            types=[
-#                ('metric-1', 'string-metric'),
-#                ('metric-2', 'integer-metric'),
-#            ])
-#        mg_info = {
-#            'group-name': mg_name,
-#            'metric-infos': [
-#                {
-#                    'metric-name': 'metric-1',
-#                    'metric-type': 'string-metric',
-#                },
-#                {
-#                    'metric-name': 'metric-2',
-#                    'metric-type': 'integer-metric',
-#                },
-#            ],
-#        }
-#        mc_mgr.add_metric_group_definition(mg_def)
-#
-#        mg_name2 = 'cpc-usage'
-#        mg_def2 = FakedMetricGroupDefinition(
-#            name=mg_name2,
-#            types=[
-#                ('metric-3', 'string-metric'),
-#                ('metric-4', 'integer-metric'),
-#            ])
-#        mg_info2 = {
-#            'group-name': mg_name2,
-#            'metric-infos': [
-#                {
-#                    'metric-name': 'metric-3',
-#                    'metric-type': 'string-metric',
-#                },
-#                {
-#                    'metric-name': 'metric-4',
-#                    'metric-type': 'integer-metric',
-#                },
-#            ],
-#        }
-#        mc_mgr.add_metric_group_definition(mg_def2)
-#
-#        # Prepare faked metric values
-#
-#        mo_val1_input = FakedMetricObjectValues(
-#            group_name=mg_name,
-#            resource_uri='/api/partitions/fake-oid',
-#            timestamp=datetime(2017, 9, 5, 12, 13, 10, 0),
-#            values=[
-#                ('metric-1', "a"),
-#                ('metric-2', 5),
-#            ])
-#        mc_mgr.add_metric_values(mo_val1_input)
-#
-#        mo_val2_input = FakedMetricObjectValues(
-#            group_name=mg_name,
-#            resource_uri='/api/partitions/fake-oid',
-#            timestamp=datetime(2017, 9, 5, 12, 13, 20, 0),
-#            values=[
-#                ('metric-1', "b"),
-#                ('metric-2', -7),
-#            ])
-#        mc_mgr.add_metric_values(mo_val2_input)
-#
-#        mo_val3_input = FakedMetricObjectValues(
-#            group_name=mg_name2,
-#            resource_uri='/api/cpcs/fake-oid',
-#            timestamp=datetime(2017, 9, 5, 12, 13, 10, 0),
-#            values=[
-#                ('metric-1', "c"),
-#                ('metric-2', 0),
-#            ])
-#        mc_mgr.add_metric_values(mo_val3_input)
-#
-#        body = {
-#            'anticipated-frequency-seconds': '10',
-#            'metric-groups': [mg_name, mg_name2],
-#        }
-#
-#        # the create function to be tested:
-#        resp = self.urihandler.post(self.hmc, '/api/services/metrics/context',
-#                                    body, True, True)
-#
-#        self.assertIsInstance(resp, dict)
-#        self.assertIn('metrics-context-uri', resp)
-#        uri = resp['metrics-context-uri']
-#        self.assertTrue(uri.startswith('/api/services/metrics/context/'))
-#        self.assertIn('metric-group-infos', resp)
-#        mg_infos = resp['metric-group-infos']
-#        self.assertEqual(mg_infos, [mg_info, mg_info2])
-#
-#        # the get function to be tested:
-#        mv_resp = self.urihandler.get(self.hmc, uri, True)
-#
-#        exp_mv_resp = '''"partition-usage"
-# "/api/partitions/fake-oid"
-# 1504613590000
-# "a",5
-#
-# "/api/partitions/fake-oid"
-# 1504613600000
-# "b",-7
-#
-#
-# "cpc-usage"
-# "/api/cpcs/fake-oid"
-# 1504613590000
-# "c",0
-#
-#
-#
-# '''
-#        self.assertEqual(
-#            mv_resp, exp_mv_resp,
-#            "Actual response string:\n{!r}\n"
-#            "Expected response string:\n{!r}\n".
-#            format(mv_resp, exp_mv_resp))
-#
-#        # the delete function to be tested:
-#        self.urihandler.delete(self.hmc, uri, True)
+    def test_create_get_delete_context(self):
+
+        mc_mgr = self.hmc.metrics_contexts
+
+        # Prepare faked metric group definitions
+
+        mg_name = 'partition-usage'
+        mg_def = FakedMetricGroupDefinition(
+            name=mg_name,
+            types=[
+                ('metric-1', 'string-metric'),
+                ('metric-2', 'integer-metric'),
+            ])
+        mg_info = {
+            'group-name': mg_name,
+            'metric-infos': [
+                {
+                    'metric-name': 'metric-1',
+                    'metric-type': 'string-metric',
+                },
+                {
+                    'metric-name': 'metric-2',
+                    'metric-type': 'integer-metric',
+                },
+            ],
+        }
+        mc_mgr.add_metric_group_definition(mg_def)
+
+        mg_name2 = 'cpc-usage'
+        mg_def2 = FakedMetricGroupDefinition(
+            name=mg_name2,
+            types=[
+                ('metric-3', 'string-metric'),
+                ('metric-4', 'integer-metric'),
+            ])
+        mg_info2 = {
+            'group-name': mg_name2,
+            'metric-infos': [
+                {
+                    'metric-name': 'metric-3',
+                    'metric-type': 'string-metric',
+                },
+                {
+                    'metric-name': 'metric-4',
+                    'metric-type': 'integer-metric',
+                },
+            ],
+        }
+        mc_mgr.add_metric_group_definition(mg_def2)
+
+        # Prepare faked metric values
+
+        mo_val1_input = FakedMetricObjectValues(
+            group_name=mg_name,
+            resource_uri='/api/partitions/fake-oid',
+            timestamp=datetime(2017, 9, 5, 12, 13, 10, 0),
+            values=[
+                ('metric-1', "a"),
+                ('metric-2', 5),
+            ])
+        mc_mgr.add_metric_values(mo_val1_input)
+
+        mo_val2_input = FakedMetricObjectValues(
+            group_name=mg_name,
+            resource_uri='/api/partitions/fake-oid',
+            timestamp=datetime(2017, 9, 5, 12, 13, 20, 0),
+            values=[
+                ('metric-1', "b"),
+                ('metric-2', -7),
+            ])
+        mc_mgr.add_metric_values(mo_val2_input)
+
+        mo_val3_input = FakedMetricObjectValues(
+            group_name=mg_name2,
+            resource_uri='/api/cpcs/fake-oid',
+            timestamp=datetime(2017, 9, 5, 12, 13, 10, 0),
+            values=[
+                ('metric-1', "c"),
+                ('metric-2', 0),
+            ])
+        mc_mgr.add_metric_values(mo_val3_input)
+
+        body = {
+            'anticipated-frequency-seconds': '10',
+            'metric-groups': [mg_name, mg_name2],
+        }
+
+        # the create function to be tested:
+        resp = self.urihandler.post(self.hmc, '/api/services/metrics/context',
+                                    body, True, True)
+
+        self.assertIsInstance(resp, dict)
+        self.assertIn('metrics-context-uri', resp)
+        uri = resp['metrics-context-uri']
+        self.assertTrue(uri.startswith('/api/services/metrics/context/'))
+        self.assertIn('metric-group-infos', resp)
+        mg_infos = resp['metric-group-infos']
+        self.assertEqual(mg_infos, [mg_info, mg_info2])
+
+        # the get function to be tested:
+        mv_resp = self.urihandler.get(self.hmc, uri, True)
+
+        exp_mv_resp = '''"partition-usage"
+"/api/partitions/fake-oid"
+1504613590000
+"a",5
+
+"/api/partitions/fake-oid"
+1504613600000
+"b",-7
+
+
+"cpc-usage"
+"/api/cpcs/fake-oid"
+1504613590000
+"c",0
+
+
+
+'''
+        self.assertEqual(
+            mv_resp, exp_mv_resp,
+            "Actual response string:\n{!r}\n"
+            "Expected response string:\n{!r}\n".
+            format(mv_resp, exp_mv_resp))
+
+        # the delete function to be tested:
+        self.urihandler.delete(self.hmc, uri, True)
 
 
 class AdapterHandlersTests(unittest.TestCase):