def test_more_than_one_projects_in_common(self, app, user_one, user_two): project1 = ProjectFactory(creator=user_one) project1.add_contributor(contributor=user_two, permissions=CREATOR_PERMISSIONS, auth=Auth(user=user_one)) project1.save() project2 = ProjectFactory(creator=user_one) project2.add_contributor(contributor=user_two, permissions=CREATOR_PERMISSIONS, auth=Auth(user=user_one)) project2.save() url = '/{}users/?show_projects_in_common=true'.format(API_BASE) res = app.get(url, auth=user_two.auth) user_json = res.json['data'] for user in user_json: if user['id'] == user_two._id: meta = user['relationships']['nodes']['links']['related'][ 'meta'] assert 'projects_in_common' in meta assert meta['projects_in_common'] == 2
def test_submit_draft_for_review_already_registered(self): self.draft.register(Auth(self.user), save=True) res = self.app.post_json( self.draft_api_url('submit_draft_for_review'), self.immediate_payload, auth=self.user.auth, expect_errors=True ) assert_equal(res.status_code, http.BAD_REQUEST) assert_equal(res.json['message_long'], 'This draft has already been registered, if you wish to register it ' 'again or submit it for review please create a new draft.')
def test_more_than_one_projects_in_common(self, app, user_one, user_two): group = OSFGroupFactory(creator=user_one) group.make_member(user_two) project1 = ProjectFactory(creator=user_one) project1.add_contributor( contributor=user_two, permissions=CREATOR_PERMISSIONS, auth=Auth(user=user_one) ) project1.save() project2 = ProjectFactory(creator=user_one) project2.add_contributor( contributor=user_two, permissions=CREATOR_PERMISSIONS, auth=Auth(user=user_one) ) project2.save() project3 = ProjectFactory() project4 = ProjectFactory() project3.add_osf_group(group) project4.add_osf_group(group) project4.is_deleted = True project3.save() project4.save() RegistrationFactory( project=project1, creator=user_one, is_public=True) url = '/{}users/?show_projects_in_common=true'.format(API_BASE) res = app.get(url, auth=user_two.auth) user_json = res.json['data'] for user in user_json: if user['id'] == user_two._id: meta = user['relationships']['nodes']['links']['related']['meta'] assert 'projects_in_common' in meta assert meta['projects_in_common'] == 4
def test_users_projects_in_common_exclude_deleted_projects( self, app, user_one, user_two): project_list = [] for x in range(1, 10): project = ProjectFactory(creator=user_one) project.add_contributor(contributor=user_two, permissions=CREATOR_PERMISSIONS, auth=Auth(user=user_one)) project.save() project_list.append(project) for x in range(1, 5): project = project_list[x] project.reload() project.remove_node(auth=Auth(user=user_one)) url = '/{}users/{}/nodes/?embed=contributors&show_projects_in_common=true'.format( API_BASE, user_two._id) res = app.get(url, auth=user_two.auth) user_json = res.json['data'][0]['embeds']['contributors']['data'] for user in user_json: meta = user['embeds']['users']['data']['relationships']['nodes'][ 'links']['related']['meta'] assert 'projects_in_common' in meta assert meta['projects_in_common'] == 5
def test_users_projects_in_common_with_embed_without_right_query(self): project = ProjectFactory(creator=self.user_one) project.add_contributor(contributor=self.user_two, permissions=CREATOR_PERMISSIONS, auth=Auth(user=self.user_one)) project.save() url = "/{}users/{}/nodes/?embed=contributors".format( API_BASE, self.user_two._id) res = self.app.get(url, auth=self.user_two.auth) user_json = res.json['data'][0]['embeds']['contributors']['data'] for user in user_json: meta = user['embeds']['users']['data']['relationships']['nodes'][ 'links']['related']['meta'] assert_not_in('projects_in_common', meta)
def test_users_projects_in_common_with_embed_and_right_query(self, app, user_one, user_two): project = ProjectFactory(creator=user_one) project.add_contributor( contributor=user_two, permissions=CREATOR_PERMISSIONS, auth=Auth(user=user_one) ) project.save() url = '/{}users/{}/nodes/?embed=contributors&show_projects_in_common=true'.format(API_BASE, user_two._id) res = app.get(url, auth=user_two.auth) user_json = res.json['data'][0]['embeds']['contributors']['data'] for user in user_json: meta = user['embeds']['users']['data']['relationships']['nodes']['links']['related']['meta'] assert 'projects_in_common' in meta assert meta['projects_in_common'] == 1