예제 #1
0
 def test_json_set_pairs(self):
     with print_all_queries():
         self.obj.attrs = JSONSet("attrs", {"$.int": 101, "$.int2": 102})
         self.obj.save()
         self.obj.refresh_from_db()
         assert self.obj.attrs["int"] == 101
         assert self.obj.attrs["int2"] == 102
예제 #2
0
 def test_json_set_array(self):
     self.obj.attrs = JSONSet(
         "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 self.obj.attrs["arr2"][0] == "one"
     assert self.obj.attrs["arr2"][1] == 2
예제 #3
0
 def test_json_set_dict(self):
     self.obj.attrs = JSONSet(
         "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 self.obj.attrs["sub2"]["int"] == 42
     assert self.obj.attrs["sub2"]["foo"] == "bar"
예제 #4
0
 def test_json_set_array(self):
     self.obj.attrs = JSONSet(
         '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 self.obj.attrs['arr2'][0] == 'one'
     assert self.obj.attrs['arr2'][1] == 2
예제 #5
0
 def test_json_set_dict(self):
     self.obj.attrs = JSONSet(
         '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 self.obj.attrs['sub2']['int'] == 42
     assert self.obj.attrs['sub2']['foo'] == 'bar'
예제 #6
0
 def test_json_set_complex_data(self):
     data = {
         'list': ['one', {'int': 2}, None],
         'dict': {
             'sub_list': [1, ['two', 3]],
             'sub_dict': {'paper': 'drop'},
             'sub_null': None,
         },
         'empty': [],
         'null': None,
         'value': 11,
     }
     self.obj.attrs = JSONSet('attrs', {'$.data': data})
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs['data'] == data
예제 #7
0
 def test_json_set_complex_data(self):
     data = {
         "list": ["one", {"int": 2}, None],
         "dict": {
             "sub_list": [1, ["two", 3]],
             "sub_dict": {"paper": "drop"},
             "sub_null": None,
         },
         "empty": [],
         "null": None,
         "value": 11,
     }
     self.obj.attrs = JSONSet("attrs", {"$.data": data})
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs["data"] == data
예제 #8
0
 def test_json_set_empty_data(self):
     with pytest.raises(ValueError) as excinfo:
         JSONSet('attrs', {})
     assert '"data" cannot be empty' in str(excinfo.value)
예제 #9
0
 def test_json_set_pairs(self):
     self.obj.attrs = JSONSet('attrs', {'$.int': 101, '$.int2': 102})
     self.obj.save()
     self.obj.refresh_from_db()
     assert self.obj.attrs['int'] == 101
     assert self.obj.attrs['int2'] == 102