def _create_two_users_to_deserialize(self): user = MyUser(username="******", password="******") user2 = MyUser(username="******", password="******") user.save() user2.save() self.mc.serialize_into_store() user.username = "******" user2.username = "******" Store.objects.filter(id=user.id).update(serialized=json.dumps(user.serialize()), dirty_bit=True) Store.objects.filter(id=user2.id).update(serialized=json.dumps(user2.serialize()), dirty_bit=True) return user, user2
def test_hard_deleted_model_propagates_to_store_record(self): """ It could be the case that we have two store records, one that is hard deleted and the other that has a fk pointing to the hard deleted record. When we deserialize, we want to ensure that the record with the fk pointer also gets the hard deleted flag set, while also not deserializing the data into a model. """ # user will be deleted user = MyUser(username='******') user.save(update_dirty_bit_to=False) # log may be synced in from other device log = SummaryLog(user_id=user.id) log.id = log.calculate_uuid() StoreModelFacilityFactory(model_name="user", id=user.id, serialized=json.dumps(user.serialize()), deleted=True, hard_deleted=True) StoreModelFacilityFactory(model_name="contentsummarylog", id=log.id, serialized=json.dumps(log.serialize())) # make sure delete propagates to store due to deleted foreign key self.mc.deserialize_from_store() # have to serialize to update deleted models self.mc.serialize_into_store() self.assertFalse(SummaryLog.objects.filter(id=log.id).exists()) self.assertTrue(Store.objects.get(id=log.id).hard_deleted)
def test_invalid_model_leaves_store_dirty_bit(self): user = MyUser(username='******' * 21) st = StoreModelFacilityFactory(model_name="user", id=uuid.uuid4().hex, serialized=json.dumps(user.serialize())) self.mc.deserialize_from_store() st.refresh_from_db() self.assertTrue(st.dirty_bit)
def test_regular_model_deserialization(self): # deserialization should be able to handle multiple records user = MyUser(username='******', password='******') user2 = MyUser(username='******', password='******') user.save(update_dirty_bit_to=False) user2.save(update_dirty_bit_to=False) user.username = '******' user2.username = '******' StoreModelFacilityFactory(id=user.id, serialized=json.dumps(user.serialize()), model_name="user") StoreModelFacilityFactory(id=user2.id, serialized=json.dumps(user2.serialize()), model_name="user") self.mc.deserialize_from_store() self.assertFalse(MyUser.objects.filter(username='******').exists()) self.assertFalse(MyUser.objects.filter(username='******').exists()) self.assertTrue(MyUser.objects.filter(username='******').exists()) self.assertTrue(MyUser.objects.filter(username='******').exists())
def test_store_hard_delete_propagates(self): user = MyUser(username='******') user.save(update_dirty_bit_to=False) log = SummaryLog(user=user) log.save(update_dirty_bit_to=False) StoreModelFacilityFactory(model_name="user", id=user.id, serialized=json.dumps(user.serialize()), hard_deleted=True, deleted=True) # make sure hard_deleted propagates to related models even if they are not hard_deleted self.mc.deserialize_from_store() self.assertTrue(HardDeletedModels.objects.filter(id=log.id).exists())