def test_unit__rename_content__ok(self): provider = self._get_provider(self.app_config) environ = self._get_environ( provider, '*****@*****.**', ) pie = provider.getResourceInst( '/Recipes/Desserts/Apple_Pie.txt', environ, ) content_pie = self.session.query(ContentRevisionRO) \ .filter(Content.label == 'Apple_Pie') \ .one() # It must exist only one revision, cf fixtures assert content_pie, 'Apple_Pie should be exist' content_pie_id = content_pie.content_id pie.moveRecursive('/Recipes/Desserts/Apple_Pie_RENAMED.txt') # Database content is renamed content_pie = self.session.query(ContentRevisionRO) \ .filter(ContentRevisionRO.content_id == content_pie_id) \ .order_by(ContentRevisionRO.revision_id.desc()) \ .first() eq_('Apple_Pie_RENAMED', content_pie.label, msg='File should be labeled Apple_Pie_RENAMED, not {0}'.format( content_pie.label))
def test_unit__move_content__ok(self): provider = self._get_provider(self.app_config) environ = self._get_environ( provider, '*****@*****.**', ) pie = provider.getResourceInst( '/Recipes/Desserts/Apple_Pie.txt', environ, ) content_pie = self.session.query(ContentRevisionRO) \ .filter(Content.label == 'Apple_Pie') \ .one() # It must exist only one revision, cf fixtures assert content_pie, 'Apple_Pie should be exist' content_pie_id = content_pie.content_id content_pie_parent = content_pie.parent eq_( content_pie_parent.label, 'Desserts', msg='field parent should be Desserts', ) pie.moveRecursive('/Recipes/Salads/Apple_Pie.txt') # move in f2 # Database content is moved content_pie = self.session.query(ContentRevisionRO) \ .filter(ContentRevisionRO.content_id == content_pie_id) \ .order_by(ContentRevisionRO.revision_id.desc()) \ .first() assert content_pie.parent.label != content_pie_parent.label,\ 'file should be moved in Salads but is in {0}'.format( content_pie.parent.label )
def test_new_revision(self): admin = self.session.query(User).filter( User.email == '*****@*****.**').one() workspace = self._create_workspace_and_test(name='workspace_1', user=admin) folder = self._create_content_and_test(name='folder_1', workspace=workspace, type=ContentType.Folder) page = self._create_content_and_test(workspace=workspace, parent=folder, name='file_1', description='content of file_1', type=ContentType.Page, owner=admin) self.session.flush() # Model create a new instance with list of column new_revision_by_model = ContentRevisionRO.new_from(page.revision) # Test create a new instance from dynamic listing of model # columns mapping new_revision_by_test = self._new_from(page.revision) new_revision_by_model_dict = self._get_dict_representation( new_revision_by_model) new_revision_by_test_dict = self._get_dict_representation( new_revision_by_test) # They must be identical eq_(new_revision_by_model_dict, new_revision_by_test_dict)
def test_unit__create_content__ok(self): provider = self._get_provider(self.app_config) environ = self._get_environ( provider, '*****@*****.**', ) result = provider.getResourceInst( '/Recipes/Salads/greek_salad.txt', environ, ) eq_(None, result, msg='Result should be None instead {0}'.format(result)) result = self._put_new_text_file( provider, environ, '/Recipes/Salads/greek_salad.txt', b'Greek Salad\n', ) assert result, 'Result should not be None instead {0}'.format(result) eq_(b'Greek Salad\n', result.content.depot_file.file.read(), msg='fiel content should be "Greek Salad\n" but it is {0}'.format( result.content.depot_file.file.read()))
def test_notifier_factory_method(self): u = User() self.app_config.EMAIL_NOTIFICATION_ACTIVATED = True notifier = NotifierFactory.create(self.app_config, u) eq_(EmailNotifier, notifier.__class__) self.app_config.EMAIL_NOTIFICATION_ACTIVATED = False notifier = NotifierFactory.create(self.app_config, u) eq_(DummyNotifier, notifier.__class__)
def test_get_one(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_user() api.update(u, 'titi', 'titi@titi', True) one = api.get_one(u.user_id) eq_(u.user_id, one.user_id)
def test_unit__get_one__ok__nominal_case(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_minimal_user('titi@titi') api.update(u, 'titi', 'titi@titi', 'pass', do_save=True) one = api.get_one(u.user_id) eq_(u.user_id, one.user_id)
def test_unit__get_content__ok(self): provider = self._get_provider(self.app_config) pie = provider.getResourceInst( '/Recipes/Desserts/Apple_Pie.txt', self._get_environ( provider, '*****@*****.**', )) assert pie, 'Apple_Pie should be found' eq_('Apple_Pie.txt', pie.name)
def test_unit__user_with_email_exists__ok__nominal_case(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_minimal_user('bibi@bibi') api.update(u, 'bibi', 'bibi@bibi', 'pass', do_save=True) transaction.commit() eq_(True, api.user_with_email_exists('bibi@bibi')) eq_(False, api.user_with_email_exists('unknown'))
def test_get_one_by_email(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_user() api.update(u, 'bibi', 'bibi@bibi', True) uid = u.user_id transaction.commit() eq_(uid, api.get_one_by_email('bibi@bibi').user_id)
def test_user_with_email_exists(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_user() api.update(u, 'bibi', 'bibi@bibi', True) transaction.commit() eq_(True, api.user_with_email_exists('bibi@bibi')) eq_(False, api.user_with_email_exists('unknown'))
def test_null_password(self): # Check bug #70 fixed # http://tracim.org/workspaces/4/folders/5/threads/70 name = 'Damien' email = '*****@*****.**' user = User() user.display_name = name user.email = email eq_(False, user.validate_password(None))
def test_create_and_update_user(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_user() api.update(u, 'bob', 'bob@bob', True) nu = api.get_one_by_email('bob@bob') assert nu != None eq_('bob@bob', nu.email) eq_('bob', nu.display_name)
def test_children(self): admin = self.session.query(User).filter( User.email == '*****@*****.**').one() self._create_thread_and_test(workspace_name='workspace_1', folder_name='folder_1', thread_name='thread_1', user=admin) workspace = self.session.query(Workspace).filter( Workspace.label == 'workspace_1').one() content_api = ContentApi( session=self.session, current_user=admin, config=self.app_config, ) folder = content_api.get_canonical_query().filter( Content.label == 'folder_1').one() eq_([ folder, ], list(workspace.get_valid_children()))
def test_get_notifiable_roles(self): admin = self.session.query(User) \ .filter(User.email == '*****@*****.**').one() wapi = WorkspaceApi( session=self.session, config=self.app_config, current_user=admin, ) w = wapi.create_workspace(label='workspace w', save_now=True) uapi = UserApi( session=self.session, current_user=admin, config=self.config ) u = uapi.create_minimal_user(email='[email protected]', save_now=True) eq_([], wapi.get_notifiable_roles(workspace=w)) rapi = RoleApi( session=self.session, current_user=admin, config=self.app_config, ) r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif=True) eq_([r, ], wapi.get_notifiable_roles(workspace=w)) u.is_active = False eq_([], wapi.get_notifiable_roles(workspace=w))
def test_unit__delete_content__ok(self): provider = self._get_provider(self.app_config) pie = provider.getResourceInst( '/Recipes/Desserts/Apple_Pie.txt', self._get_environ( provider, '*****@*****.**', )) content_pie = self.session.query(ContentRevisionRO) \ .filter(Content.label == 'Apple_Pie') \ .one() # It must exist only one revision, cf fixtures eq_(False, content_pie.is_deleted, msg='Content should not be deleted !') content_pie_id = content_pie.content_id pie.delete() self.session.flush() content_pie = self.session.query(ContentRevisionRO) \ .filter(Content.content_id == content_pie_id) \ .order_by(Content.revision_id.desc()) \ .first() eq_(True, content_pie.is_deleted, msg='Content should be deleted!') result = provider.getResourceInst( '/Recipes/Desserts/Apple_Pie.txt', self._get_environ( provider, '*****@*****.**', )) eq_(None, result, msg='Result should be None instead {0}'.format(result))
def test_unit__list_workspace_folders__ok(self): provider = self._get_provider(self.app_config) Recipes = provider.getResourceInst( '/Recipes/', self._get_environ( provider, '*****@*****.**', )) assert Recipes, 'Path /Recipes should return a Wrkspace instance' children = Recipes.getMemberList() eq_( 2, len(children), msg='Recipes should list 2 folders instead {0}'.format( len(children), ), ) folders_names = [f.name for f in children] assert 'Salads' in folders_names, 'Salads should be in names ({0})'.format( folders_names, ) assert 'Desserts' in folders_names, 'Desserts should be in names ({0})'.format( folders_names, )
def test_unit__list_workspaces_with_admin__ok(self): provider = self._get_provider(self.app_config) root = provider.getResourceInst( '/', self._get_environ( provider, '*****@*****.**', )) assert root, 'Path / should return a RootResource instance' assert isinstance( root, RootResource), 'Path / should return a RootResource instance' children = root.getMemberList() eq_(2, len(children), msg='RootResource should return 3 workspaces instead {0}'.format( len(children), )) workspaces_names = [w.name for w in children] assert 'Recipes' in workspaces_names, 'Recipes should be in names ({0})'.format( workspaces_names, ) assert 'Business' in workspaces_names, 'Business should be in names ({0})'.format( workspaces_names, )
def test_unit__list_content__ok(self): provider = self._get_provider(self.app_config) Salads = provider.getResourceInst( '/Recipes/Desserts', self._get_environ( provider, '*****@*****.**', )) assert Salads, 'Path /Salads should return a Wrkspace instance' children = Salads.getMemberList() eq_( 5, len(children), msg='Salads should list 5 Files instead {0}'.format( len(children), ), ) content_names = [c.name for c in children] assert 'Brownie Recipe.html' in content_names, \ 'Brownie Recipe.html should be in names ({0})'.format( content_names, ) assert 'Best Cakesʔ.html' in content_names,\ 'Best Cakesʔ.html should be in names ({0})'.format( content_names, ) assert 'Apple_Pie.txt' in content_names,\ 'Apple_Pie.txt should be in names ({0})'.format(content_names,) assert 'Fruits Desserts' in content_names, \ 'Fruits Desserts should be in names ({0})'.format( content_names, ) assert 'Tiramisu Recipe.html' in content_names,\ 'Tiramisu Recipe.html should be in names ({0})'.format( content_names, )
def test_unit__get_all_manageable(self): admin = self.session.query(User) \ .filter(User.email == '*****@*****.**').one() uapi = UserApi( session=self.session, current_user=admin, config=self.config, ) # Checks a case without workspaces. wapi = WorkspaceApi( session=self.session, current_user=admin, config=self.app_config, ) eq_([], wapi.get_all_manageable()) # Checks an admin gets all workspaces. w4 = wapi.create_workspace(label='w4') w3 = wapi.create_workspace(label='w3') w2 = wapi.create_workspace(label='w2') w1 = wapi.create_workspace(label='w1') eq_([w1, w2, w3, w4], wapi.get_all_manageable()) # Checks a regular user gets none workspace. gapi = GroupApi( session=self.session, current_user=None, config=self.app_config, ) u = uapi.create_minimal_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True) wapi = WorkspaceApi( session=self.session, current_user=u, config=self.app_config, ) rapi = RoleApi( session=self.session, current_user=u, config=self.app_config, ) rapi.create_one(u, w4, UserRoleInWorkspace.READER, False) rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, False) rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, False) rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, False) eq_([], wapi.get_all_manageable()) # Checks a manager gets only its own workspaces. u.groups.append(gapi.get_one(Group.TIM_MANAGER)) rapi.delete_one(u.user_id, w2.workspace_id) rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, False) eq_([w1, w2], wapi.get_all_manageable())
def test_unit__move_content__ok__another_workspace(self): provider = self._get_provider(self.app_config) environ = self._get_environ( provider, '*****@*****.**', ) content_to_move_res = provider.getResourceInst( '/Recipes/Desserts/Apple_Pie.txt', environ, ) content_to_move = self.session.query(ContentRevisionRO) \ .filter(Content.label == 'Apple_Pie') \ .one() # It must exist only one revision, cf fixtures assert content_to_move, 'Apple_Pie should be exist' content_to_move_id = content_to_move.content_id content_to_move_parent = content_to_move.parent eq_( content_to_move_parent.label, 'Desserts', msg='field parent should be Desserts', ) content_to_move_res.moveRecursive( '/Others/Infos/Apple_Pie.txt') # move in Business, f1 # Database content is moved content_to_move = self.session.query(ContentRevisionRO) \ .filter(ContentRevisionRO.content_id == content_to_move_id) \ .order_by(ContentRevisionRO.revision_id.desc()) \ .first() assert content_to_move.parent, 'Content should have a parent' assert content_to_move.parent.label == 'Infos',\ 'file should be moved in Infos but is in {0}'.format( content_to_move.parent.label )
def test_unit__update_content__ok(self): provider = self._get_provider(self.app_config) environ = self._get_environ( provider, '*****@*****.**', ) result = provider.getResourceInst( '/Recipes/Salads/greek_salad.txt', environ, ) eq_(None, result, msg='Result should be None instead {0}'.format(result)) result = self._put_new_text_file( provider, environ, '/Recipes/Salads/greek_salad.txt', b'hello\n', ) assert result, 'Result should not be None instead {0}'.format(result) eq_(b'hello\n', result.content.depot_file.file.read(), msg='fiel content should be "hello\n" but it is {0}'.format( result.content.depot_file.file.read())) # ReInit DummyNotifier counter DummyNotifier.send_count = 0 # Update file content write_object = result.beginWrite( contentType='application/octet-stream', ) write_object.write(b'An other line') write_object.close() result.endWrite(withErrors=False) eq_( 1, DummyNotifier.send_count, msg='DummyNotifier should send 1 mail, not {}'.format( DummyNotifier.send_count), )
def test_create(self): self.session.flush() transaction.commit() name = 'Damien' email = '*****@*****.**' user = User() user.display_name = name user.email = email self.session.add(user) self.session.flush() transaction.commit() new_user = self.session.query(User).filter( User.display_name == name).one() eq_(new_user.display_name, name) eq_(new_user.email, email) eq_(new_user.email_address, email)
def test_unit__create_delete_and_create_file__ok(self): provider = self._get_provider(self.app_config) environ = self._get_environ( provider, '*****@*****.**', ) new_file = provider.getResourceInst( '/Recipes/Salads/greek_salad.txt', environ, ) eq_(None, new_file, msg='Result should be None instead {0}'.format(new_file)) # create it new_file = self._put_new_text_file( provider, environ, '/Recipes/Salads/greek_salad.txt', b'Greek Salad\n', ) assert new_file, 'Result should not be None instead {0}'.format( new_file) content_new_file = self.session.query(ContentRevisionRO) \ .filter(Content.label == 'greek_salad') \ .one() # It must exist only one revision eq_(False, content_new_file.is_deleted, msg='Content should not be deleted!') content_new_file_id = content_new_file.content_id # Delete if new_file.delete() self.session.flush() content_pie = self.session.query(ContentRevisionRO) \ .filter(Content.content_id == content_new_file_id) \ .order_by(Content.revision_id.desc()) \ .first() eq_(True, content_pie.is_deleted, msg='Content should be deleted!') result = provider.getResourceInst( '/Recipes/Salads/greek_salad.txt', self._get_environ( provider, '*****@*****.**', )) eq_(None, result, msg='Result should be None instead {0}'.format(result)) # Then create it again new_file = self._put_new_text_file( provider, environ, '/Recipes/Salads/greek_salad.txt', b'greek_salad\n', ) assert new_file, 'Result should not be None instead {0}'.format( new_file) # Previous file is still dleeted self.session.flush() content_pie = self.session.query(ContentRevisionRO) \ .filter(Content.content_id == content_new_file_id) \ .order_by(Content.revision_id.desc()) \ .first() eq_(True, content_pie.is_deleted, msg='Content should be deleted!') # And an other file exist for this name content_new_new_file = self.session.query(ContentRevisionRO) \ .filter(Content.label == 'greek_salad') \ .order_by(Content.revision_id.desc()) \ .first() assert content_new_new_file.content_id != content_new_file_id,\ 'Contents ids should not be same!' eq_(False, content_new_new_file.is_deleted, msg='Content should not be deleted!')