Skip to content

Commit a4ca8e4

Browse files
Merge branch 'develop' into feature/test_registration_output_badges
2 parents d9e7149 + 78bba40 commit a4ca8e4

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

api/osf_api.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,6 @@ def update_file_metadata(session, file_guid):
11961196
item_id=file_guid,
11971197
)
11981198

1199-
12001199
def get_registration_resource_id(registration_id):
12011200
"""This function returns the most recent resource id
12021201
added to the given registration"""
@@ -1229,7 +1228,6 @@ def delete_registration_resource(registration_id):
12291228

12301229
session.delete(url, item_type='resources')
12311230

1232-
12331231
def create_registration_resource(registration_guid, resource_type):
12341232
"""This method creates new registration output resource for a given
12351233
registration."""
@@ -1279,3 +1277,36 @@ def create_registration_resource(registration_guid, resource_type):
12791277
item_id=resource_id,
12801278
item_type='resources',
12811279
)['data']
1280+
1281+
1282+
def get_registration_resource_id(registration_id):
1283+
"""This function returns the most recent resource id
1284+
added to the given registration"""
1285+
session = client.Session(
1286+
api_base_url=settings.API_DOMAIN,
1287+
auth=(settings.REGISTRATIONS_USER, settings.REGISTRATIONS_USER_PASSWORD),
1288+
)
1289+
1290+
url = '/v2/registrations/{}/resources/'.format(registration_id)
1291+
data = session.get(url)['data']
1292+
if data:
1293+
for i in range(0, len(data)):
1294+
date_created = data[i]['attributes']['date_created']
1295+
now = datetime.datetime.now()
1296+
current_date = now.strftime('%Y-%m-%d')
1297+
if current_date in date_created:
1298+
return data[i]['id']
1299+
break
1300+
return None
1301+
1302+
1303+
def delete_registration_resource(registration_id):
1304+
"""This function deletes the resource added to the given registration"""
1305+
session = client.Session(
1306+
api_base_url=settings.API_DOMAIN,
1307+
auth=(settings.REGISTRATIONS_USER, settings.REGISTRATIONS_USER_PASSWORD),
1308+
)
1309+
registration_resource_id = get_registration_resource_id(registration_id)
1310+
url = '/v2/resources/{}'.format(registration_resource_id)
1311+
1312+
session.delete(url, item_type='resources')

tests/test_registration_sidebar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def test_add_new_resource(
140140
)
141141
)
142142
# Verify and delete the resource if already exists
143+
143144
resource_id = osf_api.get_registration_resource_id(
144145
registration_id=registration_guid
145146
)

0 commit comments

Comments
 (0)