Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 13
0
 def _obj_to_json(cls, data_obj):
     return helpers.obj_to_json(data_obj)
Ejemplo n.º 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)
Ejemplo n.º 15
0
 def _obj_to_json(cls, data_obj):
     return helpers.obj_to_json(data_obj)
Ejemplo n.º 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)