def test_exploration_rights_change_object_with_invalid_role(self): with self.assertRaisesRegexp(utils.ValidationError, ('Value for new_role in cmd change_role: ' 'invalid is not allowed')): rights_domain.ExplorationRightsChange({ 'cmd': 'change_role', 'assignee_id': 'assignee_id', 'old_role': rights_domain.ROLE_OWNER, 'new_role': 'invalid', })
def test_exploration_rights_change_object_with_invalid_status(self): with self.assertRaisesRegexp( utils.ValidationError, ('Value for new_status in cmd change_exploration_status: ' 'invalid is not allowed')): rights_domain.ExplorationRightsChange({ 'cmd': 'change_exploration_status', 'old_status': rights_domain.ACTIVITY_STATUS_PRIVATE, 'new_status': 'invalid' })
def test_exploration_rights_change_object_with_missing_attribute_in_cmd( self): with self.assertRaisesRegexp( utils.ValidationError, ('The following required attributes are missing: ' 'new_role, old_role')): rights_domain.ExplorationRightsChange({ 'cmd': 'change_role', 'assignee_id': 'assignee_id', })
def test_to_dict(self): exploration_rights_change_dict = { 'cmd': 'change_private_viewability', 'old_viewable_if_private': 'old_viewable_if_private', 'new_viewable_if_private': 'new_viewable_if_private' } exploration_rights_change_object = ( rights_domain.ExplorationRightsChange( exploration_rights_change_dict)) self.assertEqual(exploration_rights_change_object.to_dict(), exploration_rights_change_dict)
def test_exploration_rights_change_object_with_extra_attribute_in_cmd( self): with self.assertRaisesRegexp( utils.ValidationError, ('The following extra attributes are present: invalid')): rights_domain.ExplorationRightsChange({ 'cmd': 'change_private_viewability', 'old_viewable_if_private': 'old_viewable_if_private', 'new_viewable_if_private': 'new_viewable_if_private', 'invalid': 'invalid' })
def test_exploration_rights_change_object_with_change_exploration_status( self) -> None: exploration_rights_change_object = ( rights_domain.ExplorationRightsChange( { # type: ignore[no-untyped-call] 'cmd': 'change_exploration_status', 'old_status': rights_domain.ACTIVITY_STATUS_PRIVATE, 'new_status': rights_domain.ACTIVITY_STATUS_PUBLIC })) self.assertEqual(exploration_rights_change_object.cmd, 'change_exploration_status') self.assertEqual(exploration_rights_change_object.old_status, rights_domain.ACTIVITY_STATUS_PRIVATE) self.assertEqual(exploration_rights_change_object.new_status, rights_domain.ACTIVITY_STATUS_PUBLIC)
def test_exploration_rights_change_object_with_change_role(self) -> None: exploration_rights_change_object = ( rights_domain.ExplorationRightsChange( { # type: ignore[no-untyped-call] 'cmd': 'change_role', 'assignee_id': 'assignee_id', 'old_role': rights_domain.ROLE_OWNER, 'new_role': rights_domain.ROLE_VIEWER })) self.assertEqual(exploration_rights_change_object.cmd, 'change_role') self.assertEqual(exploration_rights_change_object.assignee_id, 'assignee_id') self.assertEqual(exploration_rights_change_object.old_role, rights_domain.ROLE_OWNER) self.assertEqual(exploration_rights_change_object.new_role, rights_domain.ROLE_VIEWER)
def test_exploration_rights_change_object_with_update_first_published_msec( self) -> None: exploration_rights_change_object = ( rights_domain.ExplorationRightsChange( { # type: ignore[no-untyped-call] 'cmd': 'update_first_published_msec', 'old_first_published_msec': 'old_first_published_msec', 'new_first_published_msec': 'new_first_published_msec' })) self.assertEqual(exploration_rights_change_object.cmd, 'update_first_published_msec') self.assertEqual( exploration_rights_change_object.old_first_published_msec, 'old_first_published_msec') self.assertEqual( exploration_rights_change_object.new_first_published_msec, 'new_first_published_msec')
def test_exploration_rights_change_object_with_change_private_viewability( self): exploration_rights_change_object = ( rights_domain.ExplorationRightsChange({ 'cmd': 'change_private_viewability', 'old_viewable_if_private': 'old_viewable_if_private', 'new_viewable_if_private': 'new_viewable_if_private' }) ) self.assertEqual( exploration_rights_change_object.cmd, 'change_private_viewability') self.assertEqual( exploration_rights_change_object.old_viewable_if_private, 'old_viewable_if_private') self.assertEqual( exploration_rights_change_object.new_viewable_if_private, 'new_viewable_if_private')
def test_exploration_rights_change_object_with_change_private_viewability( self) -> None: exploration_rights_change_object = ( rights_domain.ExplorationRightsChange( { # type: ignore[no-untyped-call] 'cmd': 'change_private_viewability', 'old_viewable_if_private': 'old_viewable_if_private', 'new_viewable_if_private': 'new_viewable_if_private' })) self.assertEqual(exploration_rights_change_object.cmd, 'change_private_viewability') self.assertEqual( exploration_rights_change_object.old_viewable_if_private, 'old_viewable_if_private') self.assertEqual( exploration_rights_change_object.new_viewable_if_private, 'new_viewable_if_private')
def test_exploration_rights_change_object_with_update_first_published_msec( self): exploration_rights_change_object = ( rights_domain.ExplorationRightsChange({ 'cmd': 'update_first_published_msec', 'old_first_published_msec': 'old_first_published_msec', 'new_first_published_msec': 'new_first_published_msec' }) ) self.assertEqual( exploration_rights_change_object.cmd, 'update_first_published_msec') self.assertEqual( exploration_rights_change_object.old_first_published_msec, 'old_first_published_msec') self.assertEqual( exploration_rights_change_object.new_first_published_msec, 'new_first_published_msec')
def test_exploration_rights_change_object_with_create_new(self): exploration_rights_change_object = ( rights_domain.ExplorationRightsChange({'cmd': 'create_new'})) self.assertEqual(exploration_rights_change_object.cmd, 'create_new')
def test_exploration_rights_change_object_with_invalid_cmd(self): with self.assertRaisesRegexp(utils.ValidationError, 'Command invalid is not allowed'): rights_domain.ExplorationRightsChange({'cmd': 'invalid'})
def test_exploration_rights_change_object_with_missing_cmd(self): with self.assertRaisesRegexp(utils.ValidationError, 'Missing cmd key in change dict'): rights_domain.ExplorationRightsChange({'invalid': 'data'})
def test_exploration_rights_change_object_with_invalid_cmd(self) -> None: with self.assertRaisesRegex( # type: ignore[no-untyped-call] utils.ValidationError, 'Command invalid is not allowed'): rights_domain.ExplorationRightsChange({'cmd': 'invalid'})
def test_exploration_rights_change_object_with_missing_cmd(self) -> None: with self.assertRaisesRegex( # type: ignore[no-untyped-call] utils.ValidationError, 'Missing cmd key in change dict'): rights_domain.ExplorationRightsChange({'invalid': 'data'})
def test_exploration_rights_change_object_with_create_new(self) -> None: exploration_rights_change_object = ( rights_domain.ExplorationRightsChange({'cmd': 'create_new'}) ) # type: ignore[no-untyped-call] self.assertEqual(exploration_rights_change_object.cmd, 'create_new')