def test_doc_delete_nested(self): doc = OJAIDocument().set_id('121212') \ .set('test_int', 123) \ .set('first.test_int', 1235) \ .set('first.test_float', 12.2) \ .set('test_float', 11.1) self.assertEqual( doc.as_dictionary(), { '_id': '121212', 'test_int': 123, 'first': { 'test_float': 12.2, 'test_int': 1235 }, 'test_float': 11.1 }) doc.delete('first.test_int') self.assertEqual( doc.as_dictionary(), { '_id': '121212', 'test_int': 123, 'first': { 'test_float': 12.2 }, 'test_float': 11.1 }) doc.delete('first.test_float') self.assertEqual(doc.as_dictionary(), { '_id': '121212', 'test_int': 123, 'first': {}, 'test_float': 11.1 })
def test_delete_by_index(self): doc = OJAIDocument().set('test_list', [1, 2, 3, 4, 5, 6, 7]) self.assertEqual({'test_list': [1, 2, 3, 4, 5, 6, 7]}, doc.as_dictionary()) doc.delete('test_list[3]') self.assertEqual({'test_list': [1, 2, 3, 5, 6, 7]}, doc.as_dictionary())
def test_doc_delete_first_level(self): doc = OJAIDocument().set_id('121212') \ .set('test_int', 123) \ .set('test_timestamp', OTimestamp(millis_since_epoch=29877132000)) \ .set('test_float', 11.1) self.assertEqual(doc.as_json_str(), json.dumps({"_id": "121212", "test_int": {"$numberLong": 123}, "test_timestamp": {"$date": "1970-12-12T19:12:12.000000Z"}, "test_float": {"$numberFloat": 11.1}})) doc.delete('test_timestamp') self.assertEqual(doc.as_json_str(), json.dumps({"_id": "121212", "test_int": {"$numberLong": 123}, "test_float": {"$numberFloat": 11.1}}))
def test_doc_delete_first_level(self): doc = OJAIDocument().set_id('121212') \ .set('test_int', 123) \ .set('test_float', 11.1) self.assertEqual(doc.as_dictionary(), { '_id': '121212', 'test_int': 123, 'test_float': 11.1 }) doc.delete('test_timestamp') self.assertEqual(doc.as_dictionary(), { '_id': '121212', 'test_int': 123, 'test_float': 11.1 })