-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelinkapi_test.py
189 lines (178 loc) · 4.84 KB
/
elinkapi_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import elinkapi
from models.record import Record
valid_save_json = {
"title": "Electron microscope data for photons",
"site_ownership_code": "LLNL",
"product_type": "TR",
"description": "Hello, from teh other side"
}
valid_save_update_json = {
"title": "Electron microscope data for photons",
"site_ownership_code": "LLNL",
"product_type": "TR",
"description": "A NEW custom description. Search on 'Allo-ballo holla olah'."
}
invalid_save_json = {
"product_type": "TD",
"site_ownership_code": "LLNL"
}
valid_submit_json = {
"persons": [
{
"type": "AUTHOR",
"first_name": "Required",
"middle_name": "Optional",
"last_name": "Required",
"email": [
],
"orcid": "0000000155554447",
"phone": "Optional",
"affiliations": [
{ "name": "Optional" }
]
},
{
"type": "RELEASE",
"first_name": "Required",
"middle_name": "Optional",
"last_name": "Required",
"email": [
],
"phone": "Optional"
},
{
"type": "CONTRIBUTING",
"first_name": "Required",
"middle_name": "Optional",
"last_name": "Required",
"email": [
],
"phone": "Optional",
"contributor_type": "Producer",
"affiliations": [
{ "name": "Optional" }
]
}
],
"organizations": [
{
"type": "AUTHOR",
"name": "Required"
},
{
"type": "CONTRIBUTING",
"name": "Required",
"contributor_type": "Producer"
},
{
"type": "SPONSOR",
"name": "Required",
"identifiers": [
{
"type": "CN_NONDOE",
"value": "Required"
},
{
"type": "CN_DOE",
"value": "SC0001234"
},
{
"type": "AWARD_DOI",
"value": "Optional"
}
]
},
{
"type": "RESEARCHING",
"name": "Required"
}
],
"identifiers": [
{
"type": "CN_DOE",
"value": "SC0001234"
},
{
"type": "CN_NONDOE",
"value": "Required"
}
],
"related_identifiers": [],
"access_limitations": [
"UNL"
],
"country_publication_code": "US",
"description": "Information about a particular record, report, or other document, or executive summary or abstract of same.",
"languages": [
"English"
],
"product_type": "TR",
"publication_date": "2018-02-21",
"publication_date_text": "Winter 2012",
"released_to_osti_date": "2023-03-03",
"site_ownership_code": "LLNL",
"title": "Sample document title"
}
# elinkapi.set_api_token("")
elinkapi.set_api_token("") # dev
osti_id = "2300069"
# osti_id = 2300063
media_id = "1900082"
reason = "I wanted to"
revision_number = "3"
date = "2022-03-03"
state = "save"
file_path = "./test_media_files/media_file.txt"
file_path2 = "./test_media_files/best_media_file.txt"
file_path3 = "./test_media_files/another_media_file.txt"
json_responses = []
reserved_osti_id = 1
# RECORD ENDPOINTS
# Post a new Record
submitted_record = {}
try:
submitted_record = elinkapi.post_new_record(Record(**valid_submit_json), "save") # Works - submitted
except Exception as e:
print(e)
osti_id = submitted_record.osti_id
# Fetch single Record from ID
single_record = elinkapi.get_single_record(osti_id) #works
# Query for many Records
list_of_records = elinkapi.query_records({"title": "Allo-ballo holla olah"}) # works, nothing found
# Reserve a DOI
try:
saved_record = elinkapi.reserve_doi(Record(**valid_save_json)) #works - naved
reserved_osti_id = saved_record.osti_id
except Exception as e:
print(f'failed to reserve doi on record')
# Update an existing Record
updated_record = elinkapi.update_record(osti_id, Record(**valid_save_update_json), 'submit') #works
# Get Revision based on revision number
revision_by_number = elinkapi.get_revision_by_number(osti_id, revision_number) # works
# Get Revision based on date
revision_by_date = elinkapi.get_revision_by_date(osti_id, date) # works
# Get all RevisionHistory of a Record
revision_history = elinkapi.get_all_revisions(osti_id) # works
most_recent_revision = revision_history[0]
oldest_revision = revision_history[-1]
# MEDIA ENDPOINTS
# Associate new Media with a Record
posted_media = elinkapi.post_media(osti_id, file_path, {"title": "Title of the Media media_file.txt"})
posted_media3 = elinkapi.post_media(osti_id, file_path3, {"title": "Title of the Media media_file.txt"})
media_id = posted_media.media_id
# Replace existing Media on a Record
replaced_media2 = elinkapi.put_media(osti_id, media_id, file_path2, {"title": "Changed this title now"})
# Get Media associated with OSTI ID
media = elinkapi.get_media(osti_id)
# Get Media content of a media resource
media_content = elinkapi.get_media_content(media_id)
# Delete Media with media_id off of a Record
isSuccessDelete = elinkapi.delete_single_media(osti_id, media_id, reason) #works
# Delete all Media associated with a Record
isSuccessAllDelete = elinkapi.delete_all_media(osti_id, reason)
# Should see that all media has been deleted
final_media = elinkapi.get_media(osti_id)
print("Finished")