예제 #1
0
 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
예제 #2
0
 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"
예제 #3
0
 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
예제 #4
0
 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'
예제 #5
0
 def test_json_insert_empty_data(self):
     with pytest.raises(ValueError) as excinfo:
         JSONInsert('attrs', {})
     assert '"data" cannot be empty' in str(excinfo.value)
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
 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