def setUp(self) -> None: super(UserQueryServicesTests, self).setUp() self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.admin_user_id = (self.get_user_id_from_email( self.CURRICULUM_ADMIN_EMAIL)) # type: ignore[no-untyped-call] self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME ]) # type: ignore[no-untyped-call] self.signup(self.NEW_USER_EMAIL, self.NEW_USER_USERNAME) self.new_user_id = self.get_user_id_from_email( self.NEW_USER_EMAIL) # type: ignore[no-untyped-call] self.user_query_model_1 = user_models.UserQueryModel( id=self.USER_QUERY_1_ID, has_not_logged_in_for_n_days=20, submitter_id=self.admin_user_id, query_status=feconf.USER_QUERY_STATUS_COMPLETED, user_ids=[self.new_user_id, self.admin_user_id]) self.user_query_model_1.update_timestamps() self.user_query_model_1.put() self.user_query_model_2 = user_models.UserQueryModel( id=self.USER_QUERY_2_ID, inactive_in_last_n_days=20, submitter_id=self.admin_user_id, query_status=feconf.USER_QUERY_STATUS_ARCHIVED, user_ids=[self.new_user_id]) self.user_query_model_2.update_timestamps() self.user_query_model_2.put()
def _save_user_query(user_query: user_query_domain.UserQuery) -> str: """Save the user query into the datastore. Args: user_query: UserQuery. The user query to save. Returns: str. The ID of the user query that was saved. """ user_query.validate() user_query_dict = { 'submitter_id': user_query.submitter_id, 'query_status': user_query.status, 'user_ids': user_query.user_ids, 'sent_email_model_id': user_query.sent_email_model_id, 'deleted': user_query.deleted } user_query_dict.update(dict(user_query.params._asdict())) user_query_model = (user_models.UserQueryModel.get(user_query.id, strict=False)) if user_query_model is not None: user_query_model.populate(**user_query_dict) else: user_query_dict['id'] = user_query.id user_query_model = user_models.UserQueryModel(**user_query_dict) user_query_model.update_timestamps() user_query_model.put() return user_query_model.id
def test_message(self) -> None: model = user_models.UserQueryModel(id='test', submitter_id='submitter', created_on=self.YEAR_AGO, last_updated=self.YEAR_AGO) error = user_validation_errors.ModelExpiringError(model) self.assertEqual( error.stderr, 'ModelExpiringError in UserQueryModel(id="test"): mark model ' 'as deleted when older than %s days' % (feconf.PERIOD_TO_MARK_MODELS_AS_DELETED.days))
def test_model_not_marked_as_deleted_recently(self) -> None: model = user_models.UserQueryModel( id=self.VALID_USER_ID, submitter_id=self.SUBMITTER_ID, created_on=self.NOW - datetime.timedelta(weeks=1), last_updated=self.NOW - datetime.timedelta(weeks=1) ) output = ( self.pipeline | beam.Create([model]) | beam.ParDo(user_validation.ValidateOldModelsMarkedDeleted()) ) self.assert_pcoll_equal(output, [])
def test_model_not_archived_not_marked_deleted(self) -> None: model = user_models.UserQueryModel( id='123', submitter_id='111', created_on=self.NOW, last_updated=self.NOW, query_status=feconf.USER_QUERY_STATUS_PROCESSING ) output = ( self.pipeline | beam.Create([model]) | beam.ParDo(user_validation.ValidateArchivedModelsMarkedDeleted()) ) self.assert_pcoll_equal(output, [])
def test_message(self) -> None: model = user_models.UserQueryModel( id='test', submitter_id='submitter', created_on=self.NOW, last_updated=self.NOW, query_status=feconf.USER_QUERY_STATUS_ARCHIVED) error = user_validation_errors.ArchivedModelNotMarkedDeletedError( model) self.assertEqual( error.stderr, 'ArchivedModelNotMarkedDeletedError in ' 'UserQueryModel(id="test"): model is archived ' 'but not marked as deleted')
def test_model_not_marked_as_deleted_when_older_than_4_weeks(self) -> None: model = user_models.UserQueryModel( id=self.VALID_USER_ID, submitter_id=self.SUBMITTER_ID, created_on=self.NOW - datetime.timedelta(weeks=5), last_updated=self.NOW - datetime.timedelta(weeks=5) ) output = ( self.pipeline | beam.Create([model]) | beam.ParDo(user_validation.ValidateOldModelsMarkedDeleted()) ) self.assert_pcoll_equal(output, [ user_validation_errors.ModelExpiringError(model) ])