コード例 #1
0
    def test_err_with_string(self):
        """
        Testcase with simple string.
        """
        status = Status.err("Hello World")
        string = '{"status": "err", "payload": "Hello World", \
            "uuid": "' + status.uuid + '"}'
        status_string = Status.from_json(string)
        status_new = Status.from_json(status.to_json())

        self.assertEqual(status, status_string)
        self.assertEqual(status, status_new)
        self.assertEqual(status_string, status_new)
コード例 #2
0
    def test_err_with_array_of_strings(self):
        """
        Testcase with simple array of string.
        """
        status = Status.err(["Hello World", "Bye"])
        string = '{"status": "err", "payload": ["Hello World", "Bye"],\
             "uuid": "' + status.uuid + '"}'
        status_string = Status.from_json(string)
        status_new = Status.from_json(status.to_json())

        self.assertEqual(status, status_string)
        self.assertEqual(status, status_new)
        self.assertEqual(status_string, status_new)
コード例 #3
0
    def test_ok_with_array_of_integer(self):
        """
        Testcase with simple array of integer.
        """
        status = Status.ok([0, 1, 2, 3])
        string = '{"status": "ok", "payload": [0, 1, 2, 3],\
            "uuid": "' + status.uuid + '"}'
        status_string = Status.from_json(string)
        status_new = Status.from_json(status.to_json())

        self.assertEqual(status, status_string)
        self.assertEqual(status, status_new)
        self.assertEqual(status_string, status_new)
コード例 #4
0
    def test_ok_with_map_mixed(self):
        """
        Testcase with map with mixed objects.
        """
        status = Status.ok({"Hello World": "Bye", "Integer": 0})
        string = '{"status": "ok", "payload": \
            {"Hello World": "Bye", "Integer": 0}, \
            "uuid": "' + status.uuid + '"}'
        status_string = Status.from_json(string)
        status_new = Status.from_json(status.to_json())

        self.assertEqual(status, status_string)
        self.assertEqual(status, status_new)
        self.assertEqual(status_string, status_new)
コード例 #5
0
 def test_err_with_no_serializable(self):
     """
     Tests if to_json() of Status.ok returns an exception, if the payload is
     not serializable.
     """
     status = Status.err(ValueError("This is a value error."))
     self.assertRaises(
         TypeError, "Object of type 'ValueError' is not JSON serializable",
         status.to_json)
コード例 #6
0
 def test_as_js(self):  # pylint: disable=R0201
     """
     Tests if Status.as_js() returns a string
     """
     isinstance(Status.as_js(), str)
コード例 #7
0
 def test_status_is_err(self):
     """
     Tests if a status that contains an error returns true on
     is_err()
     """
     self.assertTrue(Status(Status.ID_ERR, "").is_err())
コード例 #8
0
 def test_status_is_ok(self):
     """
     Tests if a status that has no error returns true on
     is_ok()
     """
     self.assertTrue(Status(Status.ID_OK, "").is_ok())
コード例 #9
0
 def test_repr_str(self):
     """
     Test if the __repr__ == __str__.
     """
     status = Status.ok("Test")
     self.assertEqual(repr(status), str(status))