def test_file_not_osfstorage(self): public_project_payload = build_preprint_create_payload( provider_id=self.provider._id) res = self.app.post_json_api( self.url, public_project_payload, auth=self.user.auth, expect_errors=True) preprint = Preprint.load(res.json['data']['id']) assert_equal(res.status_code, 201) github_file = test_utils.create_test_preprint_file( preprint, self.user, 'coffee_manuscript.pdf') github_file.recast(GithubFile._typedmodels_type) github_file.save() update_payload = build_preprint_update_payload(preprint._id, github_file._id) res = self.app.patch_json_api( self.url + '{}/'.format(preprint._id), update_payload, auth=self.user.auth, expect_errors=True ) assert_equal(res.status_code, 400) assert_equal( res.json['errors'][0]['detail'], 'This file is not a valid primary file for this preprint.')
def test_file_not_osfstorage(self): public_project_payload = build_preprint_create_payload( provider_id=self.provider._id) res = self.app.post_json_api( self.url, public_project_payload, auth=self.user.auth, expect_errors=True) preprint = Preprint.load(res.json['data']['id']) assert_equal(res.status_code, 201) github_file = test_utils.create_test_preprint_file( preprint, self.user, 'coffee_manuscript.pdf') github_file.recast(GithubFile._typedmodels_type) github_file.save() update_payload = build_preprint_update_payload(preprint._id, github_file._id) res = self.app.patch_json_api( self.url + '{}/'.format(preprint._id), update_payload, auth=self.user.auth, expect_errors=True ) assert_equal(res.status_code, 400) assert_equal( res.json['errors'][0]['detail'], 'This file is not a valid primary file for this preprint.')
def publish_preprint(self, preprint, user, expect_errors=False): preprint_file = test_utils.create_test_preprint_file( preprint, user, 'coffee_manuscript.pdf') update_payload = build_preprint_update_payload(preprint._id, preprint_file._id) res = self.app.patch_json_api(self.url + '{}/'.format(preprint._id), update_payload, auth=user.auth, expect_errors=expect_errors) return res
def publish_preprint(self, preprint, user, expect_errors=False): preprint_file = test_utils.create_test_preprint_file( preprint, user, 'coffee_manuscript.pdf') update_payload = build_preprint_update_payload(preprint._id, preprint_file._id) res = self.app.patch_json_api( self.url + '{}/'.format(preprint._id), update_payload, auth=user.auth, expect_errors=expect_errors ) return res
def test_unauth_user_downloads_preprint(self, mock_record): test_file = create_test_preprint_file(self.preprint, self.user) resp = django_app.get('/v2/') # tests unauthenticated user gets cookie. assert f'{SLOAN_ID_COOKIE_NAME}=' in resp.headers.get('Set-Cookie') sloan_cookie_value = resp.headers['Set-Cookie'].split('=')[1].split(';')[0] # tests cookies get sent to impact self.app.set_cookie(f'dwf_{SLOAN_COI_DISPLAY}', 'True') self.app.set_cookie(f'dwf_{SLOAN_DATA_DISPLAY}', 'False') self.app.set_cookie(SLOAN_ID_COOKIE_NAME, sloan_cookie_value) with override_switch(ELASTICSEARCH_METRICS, active=True): self.app.get(self.build_url(path=test_file.path)) mock_record.assert_called_with( path=test_file.path, preprint=self.preprint, user=None, version='1', sloan_coi=1, sloan_data=0, sloan_id=sloan_cookie_value, )
def file(self, preprint, user): return create_test_preprint_file(preprint, user, 'test_file')