def deposit(app, db, user, pdf_file, bucket_location, deposit_json, embargo_date): """Deposit fixture.""" json = copy.deepcopy(deposit_json) json['user'] = { '$ref': 'https://sonar.ch/api/users/{pid}'.format(pid=user['pid']) } deposit = DepositRecord.create(json, dbcommit=True, with_bucket=True) with open(pdf_file, 'rb') as file: content = file.read() deposit.files['main.pdf'] = BytesIO(content) deposit.files['main.pdf']['label'] = 'Main file' deposit.files['main.pdf']['category'] = 'main' deposit.files['main.pdf']['type'] = 'file' deposit.files['main.pdf']['embargo'] = True deposit.files['main.pdf']['embargoDate'] = embargo_date.isoformat() deposit.files['main.pdf']['exceptInOrganisation'] = True deposit.files['additional.pdf'] = BytesIO(content) deposit.files['additional.pdf']['label'] = 'Additional file 1' deposit.files['additional.pdf']['category'] = 'additional' deposit.files['additional.pdf']['type'] = 'file' deposit.files['additional.pdf']['embargo'] = False deposit.files['additional.pdf']['exceptInOrganisation'] = False deposit.commit() deposit.reindex() db.session.commit() return deposit
def test_user_resolver(app, organisation, roles): """Test user resolver.""" UserRecord.create({ 'pid': '1', 'full_name': 'Jules Brochu', 'email': '*****@*****.**', 'roles': ['user'], 'organisation': { '$ref': 'https://sonar.ch/api/organisations/org' } }) record = DepositRecord.create( {'user': { '$ref': 'https://sonar.ch/api/users/1' }}, with_bucket=False) assert record.replace_refs().get('user')['email'] == '*****@*****.**'
def _make_deposit(role='submitter', organisation=None): user = make_user(role, organisation) deposit_json['user'] = { '$ref': 'https://sonar.ch/api/users/{pid}'.format(pid=user['pid']) } deposit_json.pop('pid', None) record = DepositRecord.create(deposit_json, dbcommit=True, with_bucket=True) with open(pdf_file, 'rb') as file: content = file.read() record.files['main.pdf'] = BytesIO(content) record.files['main.pdf']['label'] = 'Main file' record.files['main.pdf']['category'] = 'main' record.files['main.pdf']['type'] = 'file' record.files['main.pdf']['embargo'] = True record.files['main.pdf']['embargoDate'] = embargo_date.isoformat() record.files['main.pdf']['exceptInOrganisation'] = True record.files['additional.pdf'] = BytesIO(content) record.files['additional.pdf']['label'] = 'Additional file 1' record.files['additional.pdf']['category'] = 'additional' record.files['additional.pdf']['type'] = 'file' record.files['additional.pdf']['embargo'] = False record.files['additional.pdf']['exceptInOrganisation'] = False record.commit() record.reindex() db.session.commit() return record