|  | @@ -1,6 +1,6 @@
 | 
	
		
			
			| 1 | 1 |  # -*- coding: utf-8 -*-
 | 
	
		
			
			| 2 | 2 |  
 | 
	
		
			
			| 3 |  | -from nose.tools import eq_
 | 
	
		
			
			|  | 3 | +from nose.tools import eq_, ok_
 | 
	
		
			
			| 4 | 4 |  from nose.tools import raises
 | 
	
		
			
			| 5 | 5 |  from tracim.lib.group import GroupApi
 | 
	
		
			
			| 6 | 6 |  
 | 
	
	
		
			
			|  | @@ -12,7 +12,7 @@ from tracim.lib.group import GroupApi
 | 
	
		
			
			| 12 | 12 |  from tracim.lib.user import UserApi
 | 
	
		
			
			| 13 | 13 |  from tracim.lib.workspace import RoleApi
 | 
	
		
			
			| 14 | 14 |  from tracim.lib.workspace import WorkspaceApi
 | 
	
		
			
			| 15 |  | -from tracim.model import DBSession, new_revision
 | 
	
		
			
			|  | 15 | +from tracim.model import DBSession, new_revision, User
 | 
	
		
			
			| 16 | 16 |  
 | 
	
		
			
			| 17 | 17 |  from tracim.model.auth import Group
 | 
	
		
			
			| 18 | 18 |  
 | 
	
	
		
			
			|  | @@ -21,10 +21,10 @@ from tracim.model.data import Content
 | 
	
		
			
			| 21 | 21 |  from tracim.model.data import ContentType
 | 
	
		
			
			| 22 | 22 |  from tracim.model.data import UserRoleInWorkspace
 | 
	
		
			
			| 23 | 23 |  
 | 
	
		
			
			| 24 |  | -from tracim.tests import TestStandard
 | 
	
		
			
			|  | 24 | +from tracim.tests import TestStandard, BaseTest
 | 
	
		
			
			| 25 | 25 |  
 | 
	
		
			
			| 26 | 26 |  
 | 
	
		
			
			| 27 |  | -class TestContentApi(TestStandard):
 | 
	
		
			
			|  | 27 | +class TestContentApi(BaseTest, TestStandard):
 | 
	
		
			
			| 28 | 28 |  
 | 
	
		
			
			| 29 | 29 |      def test_compare_content_for_sorting_by_type(self):
 | 
	
		
			
			| 30 | 30 |          c1 = Content()
 | 
	
	
		
			
			|  | @@ -729,3 +729,44 @@ class TestContentApi(TestStandard):
 | 
	
		
			
			| 729 | 729 |  
 | 
	
		
			
			| 730 | 730 |          eq_(True, id1 in [o.content_id for o in res.all()])
 | 
	
		
			
			| 731 | 731 |          eq_(True, id2 in [o.content_id for o in res.all()])
 | 
	
		
			
			|  | 732 | +
 | 
	
		
			
			|  | 733 | +    def test_unit__search_exclude_content_under_deleted_or_archived_parents__ok(self):
 | 
	
		
			
			|  | 734 | +        admin = DBSession.query(User).filter(User.email == 'admin@admin.admin').one()
 | 
	
		
			
			|  | 735 | +        workspace = self._create_workspace_and_test('workspace_1', admin)
 | 
	
		
			
			|  | 736 | +        folder_1 = self._create_content_and_test('folder_1', workspace=workspace, type=ContentType.Folder)
 | 
	
		
			
			|  | 737 | +        folder_2 = self._create_content_and_test('folder_2', workspace=workspace, type=ContentType.Folder)
 | 
	
		
			
			|  | 738 | +        page_1 = self._create_content_and_test('foo', workspace=workspace, type=ContentType.Page, parent=folder_1)
 | 
	
		
			
			|  | 739 | +        page_2 = self._create_content_and_test('bar', workspace=workspace, type=ContentType.Page, parent=folder_2)
 | 
	
		
			
			|  | 740 | +
 | 
	
		
			
			|  | 741 | +        api = ContentApi(admin)
 | 
	
		
			
			|  | 742 | +
 | 
	
		
			
			|  | 743 | +        foo_result = api.search(['foo']).all()
 | 
	
		
			
			|  | 744 | +        eq_(1, len(foo_result))
 | 
	
		
			
			|  | 745 | +        ok_(page_1 in foo_result)
 | 
	
		
			
			|  | 746 | +
 | 
	
		
			
			|  | 747 | +        bar_result = api.search(['bar']).all()
 | 
	
		
			
			|  | 748 | +        eq_(1, len(bar_result))
 | 
	
		
			
			|  | 749 | +        ok_(page_2 in bar_result)
 | 
	
		
			
			|  | 750 | +
 | 
	
		
			
			|  | 751 | +        with new_revision(folder_1):
 | 
	
		
			
			|  | 752 | +            api.delete(folder_1)
 | 
	
		
			
			|  | 753 | +        with new_revision(folder_2):
 | 
	
		
			
			|  | 754 | +            api.archive(folder_2)
 | 
	
		
			
			|  | 755 | +
 | 
	
		
			
			|  | 756 | +        # Actually ContentApi.search don't filter it
 | 
	
		
			
			|  | 757 | +        foo_result = api.search(['foo']).all()
 | 
	
		
			
			|  | 758 | +        eq_(1, len(foo_result))
 | 
	
		
			
			|  | 759 | +        ok_(page_1 in foo_result)
 | 
	
		
			
			|  | 760 | +
 | 
	
		
			
			|  | 761 | +        bar_result = api.search(['bar']).all()
 | 
	
		
			
			|  | 762 | +        eq_(1, len(bar_result))
 | 
	
		
			
			|  | 763 | +        ok_(page_2 in bar_result)
 | 
	
		
			
			|  | 764 | +
 | 
	
		
			
			|  | 765 | +        # ContentApi offer exclude_unavailable method to do it
 | 
	
		
			
			|  | 766 | +        foo_result = api.search(['foo']).all()
 | 
	
		
			
			|  | 767 | +        api.exclude_unavailable(foo_result)
 | 
	
		
			
			|  | 768 | +        eq_(0, len(foo_result))
 | 
	
		
			
			|  | 769 | +
 | 
	
		
			
			|  | 770 | +        bar_result = api.search(['bar']).all()
 | 
	
		
			
			|  | 771 | +        api.exclude_unavailable(bar_result)
 | 
	
		
			
			|  | 772 | +        eq_(0, len(bar_result))
 |