Esempio n. 1
0
 def test_ok_with_no_serializable(self):
     """
     Tests if to_json() of Status.ok returns an exception, if the payload
     is not serializable.
     """
     status = Status.ok(ValueError("This is a value error."))
     self.assertRaises(
         TypeError, "Object of type 'ValueError' is not JSON serializable",
         status.to_json)
Esempio n. 2
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)
Esempio n. 3
0
    def test_ok_with_array_of_strings(self):
        """
        Testcase with simple array of string.
        """
        status = Status.ok(["Hello World", "Bye"])
        string = '{"status": "ok", "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)
Esempio n. 4
0
    def test_ok_with_string(self):
        """
        Testcase with simple string.
        """
        status = Status.ok("Hello World")
        string = '{"status": "ok", "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)
Esempio n. 5
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)
Esempio n. 6
0
 def test_repr_str(self):
     """
     Test if the __repr__ == __str__.
     """
     status = Status.ok("Test")
     self.assertEqual(repr(status), str(status))