def test_get_cookie(self): user = AuthUserFactory() create_delta = Delta(lambda: Session.find().count(), lambda value: value + 1) with AssertDeltas(create_delta): utils.get_cookie_for_user(user) get_delta = Delta(lambda: Session.find().count()) with AssertDeltas(get_delta): utils.get_cookie_for_user(user)
def test_download_invalid_version(self, mock_get_url): mock_get_url.return_value = 'http://freddie.queen.com/' deltas = [ Delta(lambda: self.record.get_download_count(), lambda value: value), Delta(lambda: self.record.get_download_count(3), lambda value: value), ] with AssertDeltas(deltas): res = self.download_file( path=self.path, version=3, expect_errors=True, ) assert_equal(res.status_code, 404) assert_false(mock_get_url.called)
def test_download_by_version_latest(self, mock_get_url): mock_get_url.return_value = 'http://freddie.queen.com/' versions = [factories.FileVersionFactory() for _ in range(3)] self.record.versions.extend(versions) self.record.save() deltas = [ Delta(lambda: self.record.get_download_count(), lambda value: value + 1), Delta(lambda: self.record.get_download_count(3), lambda value: value + 1), ] with AssertDeltas(deltas): res = self.download_file(path=self.path, version=3) assert_equal(res.status_code, 302) assert_equal(res.location, mock_get_url.return_value) mock_get_url.assert_called_with(3, versions[1], self.record)
def test_download_pending_version(self, mock_get_url): mock_get_url.return_value = 'http://freddie.queen.com/' self.record.create_pending_version(self.user, '9d989e8') deltas = [ Delta(lambda: self.record.get_download_count(), lambda value: value), Delta(lambda: self.record.get_download_count(2), lambda value: value), ] with AssertDeltas(deltas): res = self.download_file( path=self.path, version=2, expect_errors=True, ) assert_equal(res.status_code, 404) assert_in('File upload in progress', res) assert_false(mock_get_url.called)
def test_download(self, mock_get_url): mock_get_url.return_value = 'http://freddie.queen.com/' deltas = [ Delta(lambda: self.record.get_download_count(), lambda value: value + 1), Delta( lambda: self.record.get_download_count( len(self.record.versions)), lambda value: value + 1), ] with AssertDeltas(deltas): res = self.download_file(self.path) assert_equal(res.status_code, 302) assert_equal(res.location, mock_get_url.return_value) mock_get_url.assert_called_with( len(self.record.versions), self.version, self.record, )
def test_upload_update(self): delta = Delta(lambda: len(self.record.versions), lambda value: value + 1) with AssertDeltas(delta): res = self.send_upload_hook(self.make_payload()) self.record.reload() assert_equal(res.status_code, 200) assert_equal(res.json['status'], 'success') version = model.OsfStorageFileVersion.load(res.json['version']) assert_is_not(version, None) assert_in(version, self.record.versions)
def test_download_render_mode(self, mock_get_url): mock_get_url.return_value = 'http://freddie.queen.com/' deltas = [ Delta(lambda: self.record.get_download_count(), lambda value: value), Delta( lambda: self.record.get_download_count( len(self.record.versions)), lambda value: value), ] with AssertDeltas(deltas): res = self.app.get( self.project.web_url_for( 'osf_storage_view_file', path=self.path, action='download', mode='render', ), auth=self.project.creator.auth, )
def test_upload_duplicate(self): location = { 'service': 'cloud', storage_settings.WATERBUTLER_RESOURCE: 'osf', 'object': 'file', } version = self.record.create_version(self.user, location) with AssertDeltas(Delta(lambda: len(self.record.versions))): res = self.send_upload_hook(self.make_payload()) self.record.reload() assert_equal(res.status_code, 200) assert_equal(res.json['status'], 'success') version = model.OsfStorageFileVersion.load(res.json['version']) assert_is_not(version, None) assert_in(version, self.record.versions)