Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Tests to reinforce API filtering for Preprints [OSF-7418] #6828

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 61 additions & 1 deletion api_tests/nodes/views/test_node_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def test_node_list_has_proper_root(self):
assert_equal(project_json['embeds']['root']['data']['id'], project.root._id)



class TestNodeFiltering(ApiTestCase):

def setUp(self):
Expand Down Expand Up @@ -631,6 +630,67 @@ def test_preprint_filter_excludes_orphans(self):
assert_not_in(self.project_two._id, ids)
assert_not_in(self.project_three._id, ids)

def test_deleted_preprint_file_not_in_filtered_results(self):
orphan = PreprintFactory(creator=self.preprint.node.creator)

# orphan the preprint by deleting the file
orphan.primary_file.delete()
orphan.save()

url = '/{}nodes/?filter[preprint]=true'.format(API_BASE)
res = self.app.get(url, auth=self.user_one.auth)
assert_equal(res.status_code, 200)
data = res.json['data']

ids = [each['id'] for each in data]

assert_in(self.preprint.node._id, ids)
assert_not_in(orphan.node._id, ids)

def test_deleted_preprint_file_in_preprint_false_filtered_results(self):
orphan = PreprintFactory(creator=self.preprint.node.creator)

# orphan the preprint by deleting the file
orphan.primary_file.delete()
orphan.save()
orphan.refresh_from_db()

url = '/{}nodes/?filter[preprint]=false'.format(API_BASE)
res = self.app.get(url, auth=self.user_one.auth)
assert_equal(res.status_code, 200)
data = res.json['data']

ids = [each['id'] for each in data]

assert_not_in(self.preprint.node._id, ids)
assert_in(orphan.node._id, ids)

def test_unpublished_preprint_not_in_preprint_true_filter_results(self):
unpublished = PreprintFactory(creator=self.preprint.node.creator, is_published=False)
assert_false(unpublished.is_published)

url = '/{}nodes/?filter[preprint]=true'.format(API_BASE)
res = self.app.get(url, auth=self.user_one.auth)
assert_equal(res.status_code, 200)
data = res.json['data']
ids = [each['id'] for each in data]

assert_in(self.preprint.node._id, ids)
assert_not_in(unpublished.node._id, ids)

def test_unpublished_preprint_in_preprint_false_filter_results(self):
unpublished = PreprintFactory(creator=self.preprint.node.creator, is_published=False)
assert_false(unpublished.is_published)

url = '/{}nodes/?filter[preprint]=false'.format(API_BASE)
res = self.app.get(url, auth=self.user_one.auth)
assert_equal(res.status_code, 200)
data = res.json['data']
ids = [each['id'] for each in data]

assert_not_in(self.preprint.node._id, ids)
assert_in(unpublished.node._id, ids)


class TestNodeCreate(ApiTestCase):

Expand Down