Skip to content

Commit b6b7cf9

Browse files
committed
extend sample file to show create user function
1 parent b664c80 commit b6b7cf9

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

example_person_group.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
# DSPACE_API_USERNAME=
2424
# DSPACE_API_PASSWORD=
2525
# USER_AGENT=
26-
DEFAULT_URL = "http://localhost:8080/server/api"
27-
DEFAULT_USERNAME = "username@test.system.edu"
28-
DEFAULT_PASSWORD = "password"
26+
DEFAULT_URL = "http://dspace-test-1-i.mdw.ac.at:8080/dspace/api"
27+
DEFAULT_USERNAME = "repo-admin@mdw.ac.at"
28+
DEFAULT_PASSWORD = "Dm55Rt67"
2929

3030
GROUP_UUID = "11ba756f-9539-496b-a9de-83a5376df4fc"
3131
NEW_GROUP_NAME = "New Test Group"
@@ -90,15 +90,19 @@
9090
# Create a new group
9191
logging.info("Creating a new group...")
9292
new_group = d.create_group({"name": NEW_GROUP_NAME})
93-
if new_group:
93+
print(new_group)
94+
if new_group is not None:
9495
print(f"Created Group: {new_group.uuid}, Name: {new_group.name}")
95-
96-
# Update group name
97-
new_group_uuid = new_group.uuid
98-
logging.info(f"Updating group name for {new_group_uuid}...")
99-
updated_group = d.update_group_name(new_group_uuid, UPDATED_GROUP_NAME)
100-
if updated_group:
101-
print(f"Updated Group: {updated_group.uuid}, Name: {updated_group.name}")
96+
# Update group name
97+
new_group_uuid = new_group.uuid
98+
logging.info(f"Updating group name for {new_group_uuid}...")
99+
updated_group = d.update_group_name(new_group_uuid, UPDATED_GROUP_NAME)
100+
if updated_group:
101+
print(f"Updated Group: {updated_group.uuid}, Name: {updated_group.name}")
102+
else:
103+
print(
104+
"Error creating group! This may be due to a group with the same name already existing. There is no update of the group name in this case."
105+
)
102106

103107
# Add a subgroup
104108
logging.info(f"Adding subgroup {CHILD_GROUP_UUID} to {PARENT_GROUP_UUID}...")
@@ -137,3 +141,18 @@
137141
logging.info(f"Removing EPerson {EPERSON_UUID} from group {GROUP_UUID}...")
138142
if d.remove_eperson_from_group(GROUP_UUID, EPERSON_UUID):
139143
print(f"EPerson {EPERSON_UUID} removed from group {GROUP_UUID}")
144+
145+
# Create a new person record
146+
user = {
147+
"canLogIn": True,
148+
"email": "user@institution.edu",
149+
"requireCertificate": False,
150+
"metadata": {
151+
"eperson.firstname": [{"value": "Test"}],
152+
"eperson.lastname": [{"value": "Dummy"}],
153+
},
154+
}
155+
logging.info("Creating a new person record...")
156+
new_person = d.create_user(user)
157+
if new_person:
158+
print(f"Created Person: {new_person.uuid}, Name: {new_person.name}")

0 commit comments

Comments
 (0)