예제 #1
0
    def test_add_attr_to_session_with_default_value(self):
        name = r(10)
        self.assertEqual(self.session.get_attr("name", name), name)

        name1 = r(10)
        self.session.set_attr("name", name1)
        self.assertEqual(self.session.get_attr("name"), name1)
예제 #2
0
 def test_convert_dict_nested_dict_to_str(self):
     f1 = r(10)
     f2 = r(10)
     foo = {"foo": f1, "data": {"f2": f2}}
     expected1 = "\"foo\": \""+f1+"\""
     expected2 = "\"data\": {\"f2\": \""+f2+"\"}"
     target = cloud.convert_obj_to_str(foo)
     self.assertTrue(expected1 in target)
     self.assertTrue(expected2 in target)
예제 #3
0
 def test_param_in_path(self):
     data = _header
     foo = r(5)
     bar = r(5)
     uri = "/test?foo={0}&bar={1}".format(foo, bar)
     data["uri"] = uri
     h = Header(request_header.format(_header))
     self.assertEqual(h.p["foo"], foo)
     self.assertEqual(h.p["bar"], bar)
예제 #4
0
 def test_convert_obj_to_str(self):
     foo1 = r(10)
     foo2 = r(10)
     f1 = Foo(foo1)
     f2 = Foo(foo2)
     ret = '{"foo": "'+foo1+'"}'
     ret1 = '{"foo": "'+foo2+'"}'
     target = cloud.convert_obj_to_str([f1, f2])
     self.assertIn(ret, target)
     self.assertIn(ret1, target)
예제 #5
0
    def test_request_data_with_no_cmd(self):
        d1 = r(10)
        data1 = d1
        data = self.session.handle_request_data(data1)
        self.assertTrue(type(data) == dict)
        self.assertEqual(data["cmd"], "default")
        self.assertEqual(data["data"], d1)

        d2 = r(10)
        data2 = "{'data':'"+d2+"'}"
        data = self.session.handle_request_data(data2)
        self.assertTrue(type(data) == dict)
        self.assertEqual(data["cmd"], "default")
        self.assertEqual(data["data"], d2)
예제 #6
0
    def test_response_data_with_type_of_list(self):
        class Test:
            def __init__(self, name):
                self.name = name

        name1 = r(10)
        t1 = Test(name1)

        name2 = r(10)
        t2 = Test(name2)

        parsed_data = self.session.parse_response([t1, t2])
        c = "[{\"name\": \"" + name1 + "\"}, {\"name\": \"" + name2 + "\"}]"
        self.assertEqual(parsed_data, c)
예제 #7
0
 def test_convert_iter_obj_to_str(self):
     foo1 = r(10)
     foo2 = r(10)
     foo = r(5)
     f = Foo(foo1)
     f2 = Foo(foo2)
     d = dict()
     d[r(5)] = f
     d[r(5)] = f2
     ret = '"foo": "'+foo+'"'
     ret1 = '"foo": "'+foo1+'"'
     data = {"foo": foo, "data": d.values()}
     target = cloud.convert_obj_to_str(data)
     self.assertIn(ret, target)
     self.assertIn(ret1, target)
예제 #8
0
    def test_request_data_with_specified_cmd(self):
        cmd1 = r(5)
        d1 = r(10)
        data1 = "{'cmd': '"+cmd1+"', 'data':'"+d1+"'}"
        data = self.session.handle_request_data(data1)
        self.assertTrue(type(data) == dict)
        self.assertEqual(data["cmd"], cmd1)
        self.assertEqual(data["data"], d1)

        cmd2 = r(5)
        d2 = r(10)
        data2 = "{\"cmd\": \""+cmd2+"\", \"data\":\""+d2+"\"}"
        data = self.session.handle_request_data(data2)
        self.assertTrue(type(data) == dict)
        self.assertEqual(data["cmd"], cmd2)
        self.assertEqual(data["data"], d2)
예제 #9
0
    def test_get_attr_twice(self):
        foo = r(10)
        foolist = self.session.get_attr("foolist", {})
        foolist["foo"] = foo

        foolist = self.session.get_attr("foolist", {})
        self.assertTrue(len(foolist) > 0)
예제 #10
0
    def test_response_data_with_mutli_type(self):
        class Test:
            def __init__(self, name):
                self.name = name

        name1 = r(10)
        t1 = Test(name1)

        name2 = r(10)
        t2 = Test(name2)

        res = {"func": "addUser", "users": [t1, t2]}
        parsed_data = self.session.parse_response(res)
        c = "\"users\": [{\"name\": \""+name1+"\"}, {\"name\": \""+name2+"\"}]"
        c1 = "\"func\": \"addUser\""
        self.assertTrue(c in parsed_data)
        self.assertTrue(c1 in parsed_data)
예제 #11
0
    def test_get_app_scope_variable(self):
        project = self.config.projects[0]
        self.assertIsNotNone(project)
        foo = r(10)
        project.add_app("foo", foo)
        self.assertEqual(project.get_app("foo"), foo)

        project1 = self.config.projects[0]
        self.assertEqual(project1.get_app("foo"), foo)
예제 #12
0
    def test_add_attr_to_session(self):
        name = r(10)
        self.session.set_attr("name", name)
        self.assertEqual(self.session.get_attr("name"), name)

        data = {"name": name, "lang": "python"}
        self.session.set_attr(data)
        self.assertEqual(self.session.get_attr("name"), data["name"])
        self.assertEqual(self.session.get_attr("lang"), data["lang"])
예제 #13
0
 def test_get_attr_from_session(self):
     lang = "python"
     name = r(10)
     self.session.set_attr("name", name)
     self.session.set_attr("lang", lang)
     data = self.session.get_attr()
     self.assertIsInstance(data, dict)
     self.assertEqual(self.session.get_attr("name"), name)
     self.assertEqual(self.session.get_attr("lang"), lang)
예제 #14
0
    def test_response_data_with_type_of_object(self):
        class Test:
            def __init__(self, name):
                self.name = name

        name1 = r(10)
        t1 = Test(name1)

        parsed_data = self.session.parse_response(t1)
        self.assertEqual(parsed_data, "{\"name\": \"" + name1 + "\"}")
예제 #15
0
    def test_protocal_is_correct(self):
        myname = r(5)
        driver = self.driver
        driver.get(self.base_url + "/test/protocol.html")
        driver.find_element(by=By.ID, value="test").click()

        succeed = driver.find_element_by_css_selector("span.handshake")

        self.assertEqual("handshake success", succeed.get_attribute("class"))
        self.assertEqual("Success", succeed.text)
예제 #16
0
 def test_iterate_response_and_target_no_sendto(self):
     target_session_list = [self.session]
     for i in range(5):
         target_session_list.append(self.factory.create(self.potocol))
     response = r(10)
     num = 0
     _ids = [s.id for s in target_session_list]
     for (session, data) in self.session.iterate_response_data(response):
         self.assertIn(session.id, _ids)
         self.assertEqual(data, response)
         num += 1
     self.assertEqual(num, len(target_session_list))
예제 #17
0
 def __test_convert_dict_to_str(self):
     foo = r(10)
     f = Foo(foo)
     ret = '{"foo": "'+foo+'"}'
     self.assertIn(ret, cloud.convert_obj_to_str(f))