def setUp(self): super(TestUserRoutesNodeRoutes, self).setUp() self.user_one = AuthUserFactory() self.user_one.social['twitter'] = 'howtopizza' self.user_two = AuthUserFactory() self.public_project_user_one = ProjectFactory( title="Public Project User One", is_public=True, creator=self.user_one) self.private_project_user_one = ProjectFactory( title="Private Project User One", is_public=False, creator=self.user_one) self.public_project_user_two = ProjectFactory( title="Public Project User Two", is_public=True, creator=self.user_two) self.private_project_user_two = ProjectFactory( title="Private Project User Two", is_public=False, creator=self.user_two) self.deleted_project_user_one = CollectionFactory( title="Deleted Project User One", is_public=False, creator=self.user_one, is_deleted=True) self.folder = CollectionFactory() self.deleted_folder = CollectionFactory( title="Deleted Folder User One", is_public=False, creator=self.user_one, is_deleted=True) self.bookmark_collection = BookmarkCollectionFactory()
def test_view_project_pointer_count_excludes_folders(self): pointer_project = ProjectFactory(is_public=True) # project that points to another project pointed_project = self.node # project that other project points to pointer_project.add_pointer(pointed_project, Auth(pointer_project.creator), save=True) # Project is in a organizer collection folder = CollectionFactory(creator=pointed_project.creator) folder.add_pointer(pointed_project, Auth(pointed_project.creator), save=True) result = _view_project(pointed_project, Auth(pointed_project.creator)) # pointer_project is included in count, but not folder assert_equal(result["node"]["points"], 1)
def test_collection_serialization(self): collection = CollectionFactory(creator=self.user) req = make_drf_request_with_version() result = CollectionSerializer(collection, context={ 'request': req }).data data = result['data'] assert_equal(data['id'], collection._id) assert_equal(data['type'], 'collections') # Attributes attributes = data['attributes'] assert_equal(attributes['title'], collection.title) assert_equal(attributes['date_created'], collection.date_created.isoformat()) assert_equal(attributes['date_modified'], collection.date_modified.isoformat()) assert_equal(attributes['bookmarks'], collection.is_bookmark_collection) # Relationships relationships = data['relationships'] assert_in('node_links', relationships) # Bunch of stuff in Nodes that should not be in Collections assert_not_in('contributors', relationships) assert_not_in('files', relationships) assert_not_in('parent', relationships) assert_not_in('registrations', relationships) assert_not_in('forked_from', relationships)
def test_redirect_to_collections_view(self): collection = CollectionFactory() url = '/{}guids/{}/'.format(API_BASE, collection._id) res = self.app.get(url, auth=self.user.auth) redirect_url = '{}{}collections/{}/'.format(API_DOMAIN, API_BASE, collection._id) assert_equal(res.status_code, 302) assert_equal(res.location, redirect_url)
def setUp(self): super(TestRegistrationFiltering, self).setUp() self.user_one = AuthUserFactory() self.user_two = AuthUserFactory() self.project_one = ProjectFactory(title="Project One", description='Two', is_public=True, creator=self.user_one, category='hypothesis') self.project_two = ProjectFactory(title="Project Two", description="One Three", is_public=True, creator=self.user_one) self.project_three = ProjectFactory(title="Three", is_public=True, creator=self.user_two) self.private_project_user_one = ProjectFactory(title="Private Project User One", is_public=False, creator=self.user_one) self.private_project_user_two = ProjectFactory(title="Private Project User Two", is_public=False, creator=self.user_two) self.project_one.add_tag('tag1', Auth(self.project_one.creator), save=False) self.project_one.add_tag('tag2', Auth(self.project_one.creator), save=False) self.project_one.save() self.project_two.add_tag('tag1', Auth(self.project_two.creator), save=True) self.project_two.save() self.project_one_reg = RegistrationFactory(creator=self.user_one, project=self.project_one, is_public=True) self.project_two_reg = RegistrationFactory(creator=self.user_one, project=self.project_two, is_public=True) self.project_three_reg = RegistrationFactory(creator=self.user_two, project=self.project_three, is_public=True) self.private_project_user_one_reg = RegistrationFactory(creator=self.user_one, project=self.private_project_user_one, is_public=False) self.private_project_user_two_reg = RegistrationFactory(creator=self.user_two, project=self.private_project_user_two, is_public=False) self.folder = CollectionFactory() self.bookmark_collection = find_bookmark_collection(self.user_one) self.url = "/{}registrations/".format(API_BASE)
def test_view_project_pointer_count_excludes_folders(self): pointer_project = ProjectFactory( is_public=True) # project that points to another project pointed_project = self.node # project that other project points to pointer_project.add_pointer(pointed_project, Auth(pointer_project.creator), save=True) # Project is in a organizer collection folder = CollectionFactory(creator=pointed_project.creator) folder.add_pointer(pointed_project, Auth(pointed_project.creator), save=True) result = _view_project(pointed_project, Auth(pointed_project.creator)) # pointer_project is included in count, but not folder assert_equal(result['node']['points'], 1)
def test_cannot_create_draft_from_collection(self): collection = CollectionFactory(creator=self.user) url = '/{}nodes/{}/draft_registrations/'.format( API_BASE, collection._id) res = self.app.post_json_api(url, self.payload, auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, 404)
def test_collection_guid_not_found(self): collection = CollectionFactory() collection.add_pointer(self.project, self.auth) with assert_raises(HTTPError) as exc_info: valid_project_helper(pid=collection._id, nid=collection._id) assert_equal(exc_info.exception.code, 404)
def test_cannot_return_folder_at_node_detail_endpoint(self): folder = CollectionFactory(creator=self.user) res = self.app.get('/{}nodes/{}/'.format(API_BASE, folder._id), auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, 404)