Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
f52ebda4
Commit
f52ebda4
authored
Dec 26, 2020
by
HeJ
Browse files
Options
Downloads
Patches
Plain Diff
API: upon creating a new Event, set the given ID
parent
d7ba8e7c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/api/tests/schedule.py
+58
-19
58 additions, 19 deletions
src/api/tests/schedule.py
src/api/views/schedule.py
+3
-3
3 additions, 3 deletions
src/api/views/schedule.py
with
61 additions
and
22 deletions
src/api/tests/schedule.py
+
58
−
19
View file @
f52ebda4
...
...
@@ -8,22 +8,23 @@ from core.models import Assembly, Conference, Event, PlatformUser, Room
class
ScheduleTest
(
TestCase
):
def
test_push_event
(
self
):
conf
=
Conference
(
slug
=
'
conf
'
,
name
=
'
TestConf
'
,
is_public
=
True
)
conf
.
save
()
conf
.
tracks
.
create
(
name
=
'
Community
'
).
save
()
assembly
=
Assembly
(
name
=
'
TestAssembly
'
,
slug
=
'
asmbly
'
,
conference
=
conf
)
assembly
.
save
()
room
=
Room
(
conference
=
conf
,
assembly
=
assembly
,
name
=
'
Foo Room
'
,
room_type
=
Room
.
RoomType
.
STAGE
)
room
.
save
()
user
=
PlatformUser
(
username
=
'
bernd
'
,
is_active
=
True
)
user
.
save
()
token
=
Token
(
user
=
user
)
token
.
save
()
event
=
Event
(
conference
=
conf
,
assembly
=
assembly
,
name
=
'
Example Event
'
)
def
setUp
(
self
):
self
.
conf
=
Conference
(
slug
=
'
conf
'
,
name
=
'
TestConf
'
,
is_public
=
True
)
self
.
conf
.
save
()
self
.
conf
.
tracks
.
create
(
name
=
'
Community
'
).
save
()
self
.
assembly
=
Assembly
(
name
=
'
TestAssembly
'
,
slug
=
'
asmbly
'
,
conference
=
self
.
conf
)
self
.
assembly
.
save
()
self
.
room
=
Room
(
conference
=
self
.
conf
,
assembly
=
self
.
assembly
,
name
=
'
Foo Room
'
,
room_type
=
Room
.
RoomType
.
STAGE
)
self
.
room
.
save
()
self
.
user
=
PlatformUser
(
username
=
'
bernd
'
,
is_active
=
True
)
self
.
user
.
save
()
self
.
token
=
Token
(
user
=
self
.
user
)
self
.
token
.
save
()
def
test_push_existing_event
(
self
):
event
=
Event
(
conference
=
self
.
conf
,
assembly
=
self
.
assembly
,
name
=
'
Example Event
'
)
event
.
save
()
update
=
{
...
...
@@ -50,12 +51,50 @@ class ScheduleTest(TestCase):
"
attachments
"
:
[]
}
url
=
reverse
(
'
api:event-schedule
'
,
kwargs
=
{
'
conference
'
:
conf
.
slug
,
'
pk
'
:
event
.
pk
})
url
=
reverse
(
'
api:event-schedule
'
,
kwargs
=
{
'
conference
'
:
self
.
conf
.
slug
,
'
pk
'
:
event
.
pk
})
with
self
.
modify_settings
(
API_USERS
=
{
'
append
'
:
user
.
username
}):
resp
=
self
.
client
.
post
(
url
,
json
.
dumps
(
update
),
content_type
=
'
application/json
'
,
HTTP_AUTHORIZATION
=
f
'
Token
{
token
.
key
}
'
)
with
self
.
modify_settings
(
API_USERS
=
{
'
append
'
:
self
.
user
.
username
}):
resp
=
self
.
client
.
post
(
url
,
json
.
dumps
(
update
),
content_type
=
'
application/json
'
,
HTTP_AUTHORIZATION
=
f
'
Token
{
self
.
token
.
key
}
'
)
self
.
assertEqual
(
201
,
resp
.
status_code
,
f
'
Unexpected result from POST:
{
resp
.
content
}
'
)
event
.
refresh_from_db
()
self
.
assertTrue
(
'
rC3
'
in
event
.
name
,
f
'
Expected
"
rC3
"
in event name
"
{
event
.
name
}
"
.
'
)
def
test_push_new_event
(
self
):
update
=
{
"
url
"
:
"
https://fahrplan.events.ccc.de/rc3/2020/Fahrplan/events/11583.html
"
,
"
id
"
:
11583
,
"
guid
"
:
"
d9334deb-f183-4aec-9c6c-137741f6ff73
"
,
"
logo
"
:
None
,
"
date
"
:
"
2020-12-27T12:20:00+01:00
"
,
"
start
"
:
"
12:20
"
,
"
duration
"
:
"
00:30
"
,
"
room
"
:
"
foo room
"
,
"
slug
"
:
"
rc3-11583-rc3_eroffnung
"
,
"
title
"
:
"
#rC3 Er
\u00f6
ffnung
"
,
"
subtitle
"
:
""
,
"
track
"
:
"
Community
"
,
"
type
"
:
"
Talk
"
,
"
language
"
:
"
de
"
,
"
abstract
"
:
"
Willkommen zur ersten und hoffentlich einzigen Remote Chaos Experience!
"
,
"
description
"
:
""
,
"
recording_license
"
:
""
,
"
do_not_record
"
:
False
,
"
persons
"
:
[{
"
id
"
:
14151
,
"
public_name
"
:
"
blubbel
"
}],
"
links
"
:
[],
"
attachments
"
:
[]
}
self
.
assertFalse
(
Event
.
objects
.
filter
(
pk
=
update
[
'
guid
'
]).
exists
())
url
=
reverse
(
'
api:event-schedule
'
,
kwargs
=
{
'
conference
'
:
self
.
conf
.
slug
,
'
pk
'
:
update
[
'
guid
'
]})
with
self
.
modify_settings
(
API_USERS
=
{
'
append
'
:
self
.
user
.
username
}):
resp
=
self
.
client
.
post
(
url
,
json
.
dumps
(
update
),
content_type
=
'
application/json
'
,
HTTP_AUTHORIZATION
=
f
'
Token
{
self
.
token
.
key
}
'
)
self
.
assertEqual
(
201
,
resp
.
status_code
,
f
'
Unexpected result from POST:
{
resp
.
content
}
'
)
self
.
assertTrue
(
Event
.
objects
.
filter
(
pk
=
update
[
'
guid
'
]).
exists
())
event
=
Event
.
objects
.
get
(
pk
=
update
[
'
guid
'
])
self
.
assertTrue
(
'
rC3
'
in
event
.
name
,
f
'
Expected
"
rC3
"
in event name
"
{
event
.
name
}
"
.
'
)
This diff is collapsed.
Click to expand it.
src/api/views/schedule.py
+
3
−
3
View file @
f52ebda4
...
...
@@ -93,13 +93,13 @@ class EventSchedule(ConferenceSlugMixin, APIView):
try
:
obj
=
Event
.
objects
.
get
(
conference
=
self
.
conference
,
pk
=
pk
)
except
Event
.
DoesNotExist
:
obj
=
Event
(
conference
=
self
.
conference
)
obj
=
Event
(
conference
=
self
.
conference
,
pk
=
pk
)
logger
.
warning
(
'
Event schedule POST: id %s did not exist yet, creating.
'
,
pk
)
try
:
if
'
guid
'
in
event
:
if
event
[
'
guid
'
]
!=
str
(
obj
.
pk
):
print
(
f
'
Attempted update of event
{
obj
.
pk
}
with guid
"
{
event
[
"
guid
"
]
}
"
.
'
)
logger
.
warning
(
f
'
Attempted update of event
{
obj
.
pk
}
with guid
"
{
event
[
"
guid
"
]
}
"
.
'
)
logger
.
warning
(
'
Attempted update of event %s with guid
"
%s
"
.
'
,
obj
.
pk
,
event
[
"
guid
"
])
return
JsonResponse
({
'
error
'
:
'
GUID mismatch.
'
})
if
'
slug
'
in
event
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment