def test_json_insert_array(self): self.obj.attrs = JSONInsert( "attrs", {"$.arr": [1, "two", 3], "$.arr2": ["one", 2]} ) self.obj.save() self.obj.refresh_from_db() assert self.obj.attrs["arr"] == ["dee", "arr", "arr"] assert self.obj.attrs["arr2"][0] == "one" assert self.obj.attrs["arr2"][1] == 2
def test_json_insert_dict(self): self.obj.attrs = JSONInsert( "attrs", {"$.sub": {"paper": "drop"}, "$.sub2": {"int": 42, "foo": "bar"}} ) self.obj.save() self.obj.refresh_from_db() assert self.obj.attrs["sub"] == {"document": "store"} assert self.obj.attrs["sub2"]["int"] == 42 assert self.obj.attrs["sub2"]["foo"] == "bar"
def test_json_insert_array(self): self.obj.attrs = JSONInsert( 'attrs', {'$.arr': [1, 'two', 3], '$.arr2': ['one', 2]}, ) self.obj.save() self.obj.refresh_from_db() assert self.obj.attrs['arr'] == ['dee', 'arr', 'arr'] assert self.obj.attrs['arr2'][0] == 'one' assert self.obj.attrs['arr2'][1] == 2
def test_json_insert_dict(self): self.obj.attrs = JSONInsert( 'attrs', {'$.sub': {'paper': 'drop'}, '$.sub2': {'int': 42, 'foo': 'bar'}}, ) self.obj.save() self.obj.refresh_from_db() assert self.obj.attrs['sub'] == {'document': 'store'} assert self.obj.attrs['sub2']['int'] == 42 assert self.obj.attrs['sub2']['foo'] == 'bar'
def test_json_insert_empty_data(self): with pytest.raises(ValueError) as excinfo: JSONInsert('attrs', {}) assert '"data" cannot be empty' in str(excinfo.value)
def test_json_insert(self): self.obj.attrs = JSONInsert('attrs', {'$.int': 99, '$.int2': 102}) self.obj.save() self.obj.refresh_from_db() assert self.obj.attrs['int'] == 88 assert self.obj.attrs['int2'] == 102
def test_json_insert(self): self.obj.attrs = JSONInsert("attrs", {"$.int": 99, "$.int2": 102}) self.obj.save() self.obj.refresh_from_db() assert self.obj.attrs["int"] == 88 assert self.obj.attrs["int2"] == 102
def test_json_insert_expression(self): self.obj.attrs = JSONInsert("attrs", {Value("$.int"): Value(99)}) self.obj.save() self.obj.refresh_from_db() assert self.obj.attrs["int"] == 88