Ejemplo n.º 1
0
 def test_run_iters_dict_w_multiple_list(self):
     """Tests RHM._run_iters() w/ dict containing 2 lists."""
     _dict = {
         "a": ["ACTION_FIELD:var", "var2", "var3", ["ACTION_FIELD:var4"]]
     }
     res = rhm._run_iters(_dict, action_field)
     self.assertEqual(["var", "var2", "var3", ["var4"]], res.get("a"))
Ejemplo n.º 2
0
 def test_run_iters_global_iterators(self):
     """Tests _replace_iter by modifying _iterators global object."""
     u = str(uuid.uuid4()).replace("-", "")
     _iterators[u] = get_fake_generator()
     _str = "/v1/{0}/test".format(u)
     res = rhm._run_iters(_str, action_field)
     self.assertEqual("/v1/{0}/test".format(0), res)
Ejemplo n.º 3
0
 def test_run_iters_dict_w_multiple_list(self):
     """Tests RHM._run_iters() w/ dict containing 2 lists."""
     _dict = {
         "a": ["ACTION_FIELD:var", "var2", "var3", ["ACTION_FIELD:var4"]]
     }
     res = rhm._run_iters(_dict, action_field)
     self.assertEqual(["var", "var2", "var3", ["var4"]], res.get("a"))
Ejemplo n.º 4
0
 def test_run_iters_global_iterators(self):
     """Tests _replace_iter by modifying _iterators global object."""
     u = str(uuid.uuid4()).replace("-", "")
     _iterators[u] = get_fake_generator()
     _str = "/v1/{0}/test".format(u)
     res = rhm._run_iters(_str, action_field)
     self.assertEqual("/v1/{0}/test".format(0), res)
Ejemplo n.º 5
0
 def test_string_dat_valid_xml(self):
     """Tests RHM._string_data() with a valid XML object."""
     a = ElementTree.Element("a")
     b = ElementTree.Element("b")
     b.text = "hey"
     a.append(b)
     res = rhm._string_data(a)
     self.assertEqual("<a><b>hey</b></a>", res)
Ejemplo n.º 6
0
 def test_string_dat_valid_xml(self):
     """Tests RHM._string_data() with a valid XML object."""
     a = ElementTree.Element("a")
     b = ElementTree.Element("b")
     b.text = "hey"
     a.append(b)
     res = rhm._string_data(a, 'xml')
     self.assertEqual("<a><b>hey</b></a>", res)
Ejemplo n.º 7
0
 def test_string_dat_valid_xml_w_attrs(self):
     """Tests RHM._string_data() with a valid XML object."""
     a = ElementTree.Element("a")
     a.attrib = {"key": "val"}
     b = ElementTree.Element("b")
     b.text = "hey"
     a.append(b)
     res = rhm._string_data(a, 'xml')
     self.assertEqual('<a key="val"><b>hey</b></a>', res)
Ejemplo n.º 8
0
 def test_string_dat_valid_xml_w_attrs(self):
     """Tests RHM._string_data() with a valid XML object."""
     a = ElementTree.Element("a")
     a.attrib = {"key": "val"}
     b = ElementTree.Element("b")
     b.text = "hey"
     a.append(b)
     res = rhm._string_data(a)
     self.assertEqual('<a key="val"><b>hey</b></a>', res)
Ejemplo n.º 9
0
 def test_run_iters_xml(self):
     """Tests RHM._run_iters() w/ dict containing 2 lists."""
     root = ElementTree.Element("root")
     a = ElementTree.Element("a")
     a.attrib = {"ACTION_FIELD:attrib": "val"}
     a.text = "ACTION_FIELD:var"
     root.append(a)
     res = rhm._run_iters(root, action_field)
     res_text = ElementTree.tostring(res)
     if not six.PY2:
         res_text = res_text.decode("utf-8")
     self.assertEqual('<root><a attrib="val">var</a></root>', res_text)
Ejemplo n.º 10
0
 def test_run_iters_xml(self):
     """Tests RHM._run_iters() w/ dict containing 2 lists."""
     root = ElementTree.Element("root")
     a = ElementTree.Element("a")
     a.attrib = {"ACTION_FIELD:attrib": "val"}
     a.text = "ACTION_FIELD:var"
     root.append(a)
     res = rhm._run_iters(root, action_field)
     res_text = ElementTree.tostring(res)
     if not six.PY2:
         res_text = res_text.decode("utf-8")
     self.assertEqual('<root><a attrib="val">var</a></root>', res_text)
Ejemplo n.º 11
0
 def test_string_dat_valid_dict(self):
     """Tests RHM._string_data() with a valid dict."""
     _dict = {"a": "val", "b": "val2"}
     res = rhm._string_data(_dict, 'json')
     j_dat = json.loads(res)
     self.assertEqual(_dict, j_dat)
Ejemplo n.º 12
0
 def test_remove_attrib_then_braces(self):
     """Tests RHM._remove_braces() and RHM._remove_attr_names()."""
     res = rhm._remove_attr_names("{id:123}/user/{user_id:1234}")
     self.assertEqual("{123}/user/{1234}", res)
     res = rhm._remove_braces(res)
     self.assertEqual("123/user/1234", res)
Ejemplo n.º 13
0
 def test_remove_braces_multi_vars(self):
     """Tests RequestHelperMixin._remove_braces() with multiple vars."""
     res = rhm._remove_braces("{id:123}/user/{user_id:1234}")
     self.assertEqual("id:123/user/user_id:1234", res)
Ejemplo n.º 14
0
 def test_remove_braces_double_braces(self):
     """Tests RequestHelperMixin._remove_braces() with double braces."""
     res = rhm._remove_braces("{{id:123}}")
     self.assertEqual("{id:123}", res)
Ejemplo n.º 15
0
 def test_remove_braces_named(self):
     """Tests RequestHelperMixin._remove_braces() with a named var."""
     res = rhm._remove_braces("{id:123}")
     self.assertEqual("id:123", res)
Ejemplo n.º 16
0
 def test_run_iters_dict_w_list_w_dict(self):
     """Tests RHM._run_iters() w/ dict w/ a list containing a dict."""
     _dict = {"a": [{"ACTION_FIELD:b": "c"}]}
     res = rhm._run_iters(_dict, action_field)
     self.assertEqual({"b": "c"}, res.get("a")[0])
Ejemplo n.º 17
0
 def test_run_iters_dict_w_list_w_dict(self):
     """Tests RHM._run_iters() w/ dict w/ a list containing a dict."""
     _dict = {"a": [{"ACTION_FIELD:b": "c"}]}
     res = rhm._run_iters(_dict, action_field)
     self.assertEqual({"b": "c"}, res.get("a")[0])
Ejemplo n.º 18
0
 def test_remove_braces_named(self):
     """Tests RequestHelperMixin._remove_braces() with a named var."""
     res = rhm._remove_braces("{id:123}")
     self.assertEqual("id:123", res)
Ejemplo n.º 19
0
 def test_remove_braces_double_braces(self):
     """Tests RequestHelperMixin._remove_braces() with double braces."""
     res = rhm._remove_braces("{{id:123}}")
     self.assertEqual("{id:123}", res)
Ejemplo n.º 20
0
 def test_string_dat_valid_dict(self):
     """Tests RHM._string_data() with a valid dict."""
     _dict = {"a": "val", "b": "val2"}
     res = rhm._string_data(_dict)
     j_dat = json.loads(res)
     self.assertEqual(_dict, j_dat)
Ejemplo n.º 21
0
 def test_remove_attrib_then_braces(self):
     """Tests RHM._remove_braces() and RHM._remove_attr_names()."""
     res = rhm._remove_attr_names("{id:123}/user/{user_id:1234}")
     self.assertEqual("{123}/user/{1234}", res)
     res = rhm._remove_braces(res)
     self.assertEqual("123/user/1234", res)
Ejemplo n.º 22
0
 def test_remove_braces_multi_vars(self):
     """Tests RequestHelperMixin._remove_braces() with multiple vars."""
     res = rhm._remove_braces("{id:123}/user/{user_id:1234}")
     self.assertEqual("id:123/user/user_id:1234", res)