Ejemplo n.º 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
Ejemplo n.º 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"
Ejemplo n.º 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
Ejemplo n.º 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'
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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