def test_json_replace_array(self):
     self.obj.attrs = JSONReplace(
         "attrs", {"$.arr": [1, "two", 3], "$.arr2": ["one", 2]}
     )
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs["arr"] == [1, "two", 3]
     assert "arr2" not in self.obj.attrs
 def test_json_replace_dict(self):
     self.obj.attrs = JSONReplace(
         "attrs", {"$.sub": {"paper": "drop"}, "$.sub2": {"int": 42, "foo": "bar"}}
     )
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs["sub"] == {"paper": "drop"}
     assert "sub2" not in self.obj.attrs
Beispiel #3
0
 def test_json_replace_array(self):
     self.obj.attrs = JSONReplace(
         'attrs',
         {'$.arr': [1, 'two', 3], '$.arr2': ['one', 2]},
     )
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs['arr'] == [1, 'two', 3]
     assert 'arr2' not in self.obj.attrs
Beispiel #4
0
 def test_json_replace_dict(self):
     self.obj.attrs = JSONReplace(
         'attrs',
         {'$.sub': {'paper': 'drop'}, '$.sub2': {'int': 42, 'foo': 'bar'}},
     )
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs['sub'] == {'paper': 'drop'}
     assert 'sub2' not in self.obj.attrs
Beispiel #5
0
 def test_json_replace_empty_data(self):
     with pytest.raises(ValueError) as excinfo:
         JSONReplace('attrs', {})
     assert '"data" cannot be empty' in str(excinfo.value)
Beispiel #6
0
 def test_json_replace_pairs(self):
     self.obj.attrs = JSONReplace('attrs', {'$.int': 101, '$.int2': 102})
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs['int'] == 101
     assert 'int2' not in self.obj.attrs
 def test_json_replace_pairs(self):
     self.obj.attrs = JSONReplace("attrs", {"$.int": 101, "$.int2": 102})
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs["int"] == 101
     assert "int2" not in self.obj.attrs