Exemple #1
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)
Exemple #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)
Exemple #3
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)
Exemple #4
0
    def test_err_with_array_of_integer(self):
        """
        Testcase with simple array of integer.
        """
        status = Status.err([0, 1, 2, 3])
        string = '{"status": "err", "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)
Exemple #5
0
    def test_err_with_map_mixed(self):
        """
        Testcase with map with mixed objects.
        """
        status = Status.err({"Hello World": "Bye", "Integer": 0})
        string = '{"status": "err", "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)