예제 #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
파일: models.py 프로젝트: nyetsche/loom
 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
파일: models.py 프로젝트: nyetsche/loom
 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)