Пример #1
0
 def testUpdateWithListOfChildren(self):
     model_json = '{"listofchildren": [{"name": "ishmael"}]}'
     model = SampleMutableParent.create(model_json)
     update_obj = model.to_obj()
     update_obj['listofchildren'][0]['name'] = "moby"
     update_json = helpers.obj_to_json(update_obj)
     model.update(update_json)
     self.assertEqual(model.listofchildren.first().name, 'moby')
Пример #2
0
 def testNullifyListOfChildren(self):
     model_json = '{"listofchildren": [{"name": "ishmael"}]}'
     model = SampleMutableParent.create(model_json)
     update_obj = model.to_obj()
     update_obj['listofchildren'] = []
     update_json = helpers.obj_to_json(update_obj)
     model.update(update_json)
     self.assertEqual(model.listofchildren.count(), 0)
Пример #3
0
 def testUpdateWithListOfChildren(self):
     model_json = '{"listofchildren": [{"name": "ishmael"}]}'
     model = SampleMutableParent.create(model_json)
     update_obj = model.to_obj()
     update_obj['listofchildren'][0]['name'] = "moby"
     update_json = helpers.obj_to_json(update_obj)
     model.update(update_json)
     self.assertEqual(model.listofchildren.first().name, 'moby')
Пример #4
0
 def testNullifyListOfChildren(self):
     model_json = '{"listofchildren": [{"name": "ishmael"}]}'
     model = SampleMutableParent.create(model_json)
     update_obj = model.to_obj()
     update_obj['listofchildren'] = []
     update_json = helpers.obj_to_json(update_obj)
     model.update(update_json)
     self.assertEqual(model.listofchildren.count(), 0)
Пример #5
0
    def test_create_verify_hash(self):
        model = SampleImmutableParent.create(self.parent_json)
        clean_json = helpers.obj_to_json(json.loads(self.parent_json))
        expected_hash = hashlib.sha256(clean_json).hexdigest()
        self.assertEqual(expected_hash, model._id)

        self.roundTripJson(model)
        self.roundTripObj(model)
Пример #6
0
    def testNullifyForeignKey(self):
        model_json = '{"singlechild": {"name": "ishmael"}}'
        model = SampleMutableParent.create(model_json)

        update_obj = model.to_obj()
        update_obj['singlechild'] = None
        update_json = helpers.obj_to_json(update_obj)
        model.update(update_json)
        self.assertEqual(model.singlechild, None)
Пример #7
0
    def testUpdateWithDictChild(self):
        model_json = '{"singlechild": {"name": "ishmael"}}'
        model = SampleMutableParent.create(model_json)

        update_obj = model.to_obj()
        update_obj['singlechild']['name'] = "moby"
        update_json = helpers.obj_to_json(update_obj)
        model.update(update_json)
        self.assertEqual(model.singlechild.name, 'moby')
Пример #8
0
 def testShortenListOfChildren(self):
     model_json = '{"listofchildren": [{"name": "ishmael"}, {"name": "moby"}]}'
     model = SampleMutableParent.create(model_json)
     self.assertEqual(model.listofchildren.count(), 2)
     update_obj = model.to_obj()
     update_obj['listofchildren'].pop()
     update_json = helpers.obj_to_json(update_obj)
     model.update(update_json)
     self.assertEqual(model.listofchildren.count(), 1)
Пример #9
0
    def testNullifyForeignKey(self):
        model_json = '{"singlechild": {"name": "ishmael"}}'
        model = SampleMutableParent.create(model_json)

        update_obj = model.to_obj()
        update_obj['singlechild'] = None
        update_json = helpers.obj_to_json(update_obj)
        model.update(update_json)
        self.assertEqual(model.singlechild, None)
Пример #10
0
    def testUpdateWithDictChild(self):
        model_json = '{"singlechild": {"name": "ishmael"}}'
        model = SampleMutableParent.create(model_json)

        update_obj = model.to_obj()
        update_obj['singlechild']['name'] = "moby"
        update_json = helpers.obj_to_json(update_obj)
        model.update(update_json)
        self.assertEqual(model.singlechild.name, 'moby')
Пример #11
0
 def testShortenListOfChildren(self):
     model_json = '{"listofchildren": [{"name": "ishmael"}, {"name": "moby"}]}'
     model = SampleMutableParent.create(model_json)
     self.assertEqual(model.listofchildren.count(), 2)
     update_obj = model.to_obj()
     update_obj['listofchildren'].pop()
     update_json = helpers.obj_to_json(update_obj)
     model.update(update_json)
     self.assertEqual(model.listofchildren.count(), 1)
Пример #12
0
    def test_create_verify_hash(self):
        model = SampleImmutableParent.create(self.parent_json)
        clean_json = helpers.obj_to_json(
            json.loads(self.parent_json)
            )
        expected_hash = hashlib.sha256(clean_json).hexdigest()
        self.assertEqual(expected_hash, model._id)

        self.roundTripJson(model)
        self.roundTripObj(model)
Пример #13
0
 def _obj_to_json(cls, data_obj):
     return helpers.obj_to_json(data_obj)
Пример #14
0
 def setUp(self):
     child_obj = {'name': 'one'}
     parent_obj = {'child': child_obj, 'name': 'one'}
     self.child_json = helpers.obj_to_json(child_obj)
     self.parent_json = helpers.obj_to_json(parent_obj)
Пример #15
0
 def _obj_to_json(cls, data_obj):
     return helpers.obj_to_json(data_obj)
Пример #16
0
 def setUp(self):
     child_obj = {'name': 'one'}
     parent_obj = {'child': child_obj, 'name': 'one'}
     self.child_json = helpers.obj_to_json(child_obj)
     self.parent_json = helpers.obj_to_json(parent_obj)