Ejemplo n.º 1
0
    def test_roundtrip(self):
        field = JSONDictField(use_header=False)
        result_to_mongo = field.to_mongo(MOCK_DATA_DICT)
        result_to_python = field.to_python(result_to_mongo)

        self.assertEqual(result_to_python, MOCK_DATA_DICT)

        # sets get serialized to a list
        input_dict = {"a": 1, "set": {1, 2, 3, 4, 4, 4, 5, 5}}
        result = {"a": 1, "set": [1, 2, 3, 4, 5]}

        field = JSONDictField(use_header=False)
        result_to_mongo = field.to_mongo(input_dict)
        result_to_python = field.to_python(result_to_mongo)

        self.assertEqual(result_to_python, result)
Ejemplo n.º 2
0
    def test_to_python(self):
        field = JSONDictField(use_header=False)

        data = orjson.dumps(MOCK_DATA_DICT)
        result = field.to_python(data)

        self.assertTrue(isinstance(result, dict))
        self.assertEqual(result, MOCK_DATA_DICT)
Ejemplo n.º 3
0
    def test_to_python_no_compression(self):
        field = JSONDictField(use_header=True)

        serialized_data = field.to_mongo(MOCK_DATA_DICT)

        self.assertTrue(isinstance(serialized_data, bytes))
        split = serialized_data.split(b":", 2)
        self.assertEqual(split[0], JSONDictFieldCompressionAlgorithmEnum.NONE.value)
        self.assertEqual(split[1], JSONDictFieldSerializationFormatEnum.ORJSON.value)

        desserialized_data = field.to_python(serialized_data)
        self.assertEqual(desserialized_data, MOCK_DATA_DICT)
Ejemplo n.º 4
0
    def test_roundtrip(self):
        field = JSONDictField(use_header=False)
        result_to_mongo = field.to_mongo(MOCK_DATA_DICT)
        result_to_python = field.to_python(result_to_mongo)

        self.assertEqual(result_to_python, MOCK_DATA_DICT)