def CreateNew(cls, client, **vp_dict): """Creates the viewpoint specified by 'vp_dict' and creates a follower relation between the requesting user and the viewpoint with the ADMIN label. The caller is responsible for checking permission to do this, as well as ensuring that the viewpoint does not yet exist (or is just being identically rewritten). Returns a tuple containing the newly created objects: (viewpoint, follower). """ tasks = [] # Create the viewpoint. assert 'viewpoint_id' in vp_dict and 'user_id' in vp_dict and 'timestamp' in vp_dict, vp_dict viewpoint = Viewpoint.CreateFromKeywords(**vp_dict) viewpoint.last_updated = viewpoint.timestamp viewpoint.update_seq = 0 tasks.append(gen.Task(viewpoint.Update, client)) # Create the follower and give all permissions, since it's the owner. foll_dict = { 'user_id': viewpoint.user_id, 'viewpoint_id': viewpoint.viewpoint_id, 'timestamp': viewpoint.timestamp, 'labels': list(Follower.PERMISSION_LABELS), 'viewed_seq': 0 } if viewpoint.IsDefault(): foll_dict['labels'].append(Follower.PERSONAL) follower = Follower.CreateFromKeywords(**foll_dict) tasks.append(gen.Task(follower.Update, client)) # Create the corresponding Followed record. tasks.append( gen.Task(Followed.UpdateDateUpdated, client, viewpoint.user_id, viewpoint.viewpoint_id, old_timestamp=None, new_timestamp=viewpoint.last_updated)) yield tasks raise gen.Return((viewpoint, follower))
def testMissingActivities(self): """Verifies detection of missing activities.""" self._CreateTestViewpoint('vp1', self._user.user_id, [self._user2.user_id]) self._CreateTestEpisode('vp1', 'ep1', self._user.user_id) self._CreateTestEpisode('vp1', 'ep2', self._user.user_id) self._CreateTestEpisode('vp1', 'ep3', self._user.user_id) self._CreateTestViewpoint('vp2', self._user.user_id, [self._user2.user_id]) self._CreateTestEpisode('vp2', 'ep4', self._user.user_id) self._CreateTestComment('vp2', 'cm1', self._user.user_id, 'a comment') self._RunAsync(Activity.CreateShareNew, self._client, self._user.user_id, 'vp2', 'a1', time.time(), 0, [{'new_episode_id': 'ep4', 'photo_ids': []}], []) self._CreateTestEpisode(self._user.private_vp_id, 'ep5', self._user.user_id) # Create an episode that would be created by save_photos. ep_dict = {'episode_id': 'ep6', 'user_id': self._user.user_id, 'viewpoint_id': self._user.private_vp_id, 'parent_ep_id': 'ep4', 'publish_timestamp': time.time(), 'timestamp': time.time()} self._RunAsync(Episode.CreateNew, self._client, **ep_dict) # Create viewpoint that's missing a follower activity. self._CreateTestViewpoint('vp3', self._user.user_id, []) follower = Follower.CreateFromKeywords(user_id=self._user2.user_id, viewpoint_id='vp3') self._RunAsync(follower.Update, self._client) # Create viewpoint with a follower covered by merge_accounts (shouldn't be tagged as missing follower). self._CreateTestViewpoint('vp4', self._user.user_id, [self._user2.user_id]) self._RunAsync(Activity.CreateMergeAccounts, self._client, self._user.user_id, 'vp2', 'a1', time.time(), 0, self._user2.user_id, self._user.user_id) self._RunAsync(self._checker.CheckAllViewpoints) # Default viewpoints created by DBBaseTestCase are missing Followed records. corruption_text = \ ' ---- viewpoint v-F- ----\n' \ ' missing save_photos activity (1 instance)\n' \ ' missing upload_episode activity (1 instance)\n' \ '\n' \ ' ---- viewpoint vp4 ----\n' \ ' empty viewpoint (1 instance)\n' \ '\n' \ ' ---- viewpoint vp1 ----\n' \ ' missing share_existing activity (2 instances)\n' \ ' missing share_new activity (1 instance)\n' \ '\n' \ ' ---- viewpoint vp3 ----\n' \ ' missing followed (1 instance)\n' \ ' empty viewpoint (1 instance)\n' \ '\n' \ ' ---- viewpoint vp2 ----\n' \ ' missing post_comment activity (1 instance)\n' \ ' missing add_followers activity (1 instance)\n' \ '\n' \ 'python dbchk.py --devbox --repair=True --viewpoints=v-F-,vp4,vp1,vp3,vp2' self.assertEqual(self._checker._email_args['text'], 'Found corruption(s) in database:\n\n%s' % corruption_text) self._RunDbChk({'viewpoints': ['vp1', 'vp2', 'vp3', 'vp4', 'v-F-'], 'repair': True}) # Validate by checking again and finding no issues. self._RunAsync(self._checker.CheckAllViewpoints) self.assertIsNone(self._checker._email_args)