def setUp(self) -> None: """Set up user models in datastore for use in testing.""" super(FeedbackThreadModelTest, self).setUp() user_models.UserSettingsModel( id=self.NEW_USER_1_ID, email='*****@*****.**' ).put() user_models.UserSettingsModel( id=self.NEW_USER_2_ID, email='*****@*****.**' ).put() self.feedback_thread_model = feedback_models.GeneralFeedbackThreadModel( id='%s.%s.%s' % (self.ENTITY_TYPE, self.ENTITY_ID, 'random'), entity_type=self.ENTITY_TYPE, entity_id=self.ENTITY_ID, original_author_id=self.USER_ID, status=self.STATUS, subject=self.SUBJECT, has_suggestion=self.HAS_SUGGESTION, summary=self.SUMMARY, message_count=self.MESSAGE_COUNT ) self.feedback_thread_model.update_timestamps() self.feedback_thread_model.put()
def setUp(self) -> None: super(ExpSummaryModelUnitTest, self).setUp() user_models.UserSettingsModel(id=self.USER_ID_1_NEW, email='*****@*****.**', roles=[feconf.ROLE_ID_COLLECTION_EDITOR ]).put() user_models.UserSettingsModel(id=self.USER_ID_2_NEW, email='*****@*****.**', roles=[feconf.ROLE_ID_COLLECTION_EDITOR ]).put()
def setUp(self) -> None: super(CollectionSummaryModelUnitTest, self).setUp() # type: ignore[no-untyped-call] user_models.UserSettingsModel(id=self.USER_ID_1_NEW, email='*****@*****.**', roles=[feconf.ROLE_ID_COLLECTION_EDITOR ]).put() user_models.UserSettingsModel(id=self.USER_ID_2_NEW, email='*****@*****.**', roles=[feconf.ROLE_ID_COLLECTION_EDITOR ]).put()
def test_export_data_nontrivial(self) -> None: user_auth_model = (auth_models.UserAuthDetailsModel.get_by_id( self.PROFILE_2_ID)) self.assertIsNotNone(user_auth_model) # The parent_user_id should exist to fetch the # parent_model further on in the test. self.assertIsNotNone(user_auth_model.parent_user_id) self.assertEqual(user_auth_model.parent_user_id, self.USER_ID) # Create the model instance to be fetched using # user_auth_model.parent_user_id. The fetched # parent_model will provide the username to be # returned by .export_data(). user_models.UserSettingsModel(id=self.USER_ID, email='*****@*****.**', roles=[feconf.ROLE_ID_CURRICULUM_ADMIN], banned=False, username='******').put() exported_dict = (auth_models.UserAuthDetailsModel.export_data( self.PROFILE_2_ID)) expected_dict = {'parent_username': '******'} self.assertEqual(expected_dict, exported_dict)
def test_process_reports_nothing_for_valid_uid(self) -> None: valid_user_id = 'uid_%s' % ('a' * feconf.USER_ID_RANDOM_PART_LENGTH) model_with_valid_id = user_models.UserSettingsModel( id=valid_user_id, email='*****@*****.**', created_on=self.NOW, last_updated=self.NOW) output = ( self.pipeline | beam.Create([model_with_valid_id]) | beam.ParDo(user_validation.ValidateModelWithUserId()) ) self.assert_pcoll_equal(output, [])
def test_process_reports_error_for_invalid_uid(self) -> None: model_with_invalid_id = user_models.UserSettingsModel( id='123', email='*****@*****.**', created_on=self.NOW, last_updated=self.NOW) output = ( self.pipeline | beam.Create([model_with_invalid_id]) | beam.ParDo(user_validation.ValidateModelWithUserId()) ) self.assert_pcoll_equal(output, [ base_validation_errors.ModelIdRegexError( model_with_invalid_id, feconf.USER_ID_REGEX), ])
def setUp(self) -> None: super(CollectionRightsModelUnitTest, self).setUp() # type: ignore[no-untyped-call] user_models.UserSettingsModel(id=self.USER_ID_1, email='*****@*****.**', roles=[feconf.ROLE_ID_COLLECTION_EDITOR ]).put() user_models.UserSettingsModel(id=self.USER_ID_2, email='*****@*****.**', roles=[feconf.ROLE_ID_COLLECTION_EDITOR ]).put() collection_models.CollectionRightsModel( id=self.COLLECTION_ID_1, owner_ids=[self.USER_ID_1], editor_ids=[self.USER_ID_1], voice_artist_ids=[self.USER_ID_1], viewer_ids=[self.USER_ID_2], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.1).save( self.USER_ID_COMMITTER, 'Created new collection right', [{ 'cmd': rights_domain.CMD_CREATE_NEW }]) collection_models.CollectionRightsModel( id=self.COLLECTION_ID_2, owner_ids=[self.USER_ID_1], editor_ids=[self.USER_ID_1], voice_artist_ids=[self.USER_ID_1], viewer_ids=[self.USER_ID_1], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.2).save( self.USER_ID_COMMITTER, 'Created new collection right', [{ 'cmd': rights_domain.CMD_CREATE_NEW }]) collection_models.CollectionRightsModel( id=self.COLLECTION_ID_3, owner_ids=[self.USER_ID_1], editor_ids=[self.USER_ID_1], voice_artist_ids=[self.USER_ID_2], viewer_ids=[self.USER_ID_2], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.3).save( self.USER_ID_COMMITTER, 'Created new collection right', [{ 'cmd': rights_domain.CMD_CREATE_NEW }]) collection_models.CollectionRightsModel( id=self.COLLECTION_ID_4, owner_ids=[self.USER_ID_4], editor_ids=[self.USER_ID_4], voice_artist_ids=[self.USER_ID_4], viewer_ids=[self.USER_ID_4], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.4).save( self.USER_ID_COMMITTER, 'Created new collection right', [{ 'cmd': rights_domain.CMD_CREATE_NEW }]) self.col_1_dict = (collection_models.CollectionRightsModel.get_by_id( self.COLLECTION_ID_1).to_dict())