Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
20455353
Verified
Commit
20455353
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Add conftest
parent
ad929ecf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
conftest.py
+155
-0
155 additions, 0 deletions
conftest.py
with
155 additions
and
0 deletions
conftest.py
0 → 100644
+
155
−
0
View file @
20455353
from
datetime
import
datetime
,
timedelta
import
pytest
from
rest_framework.test
import
APIClient
from
django.contrib.auth.models
import
User
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
program.models
import
FundingCategory
,
Host
,
RRule
,
Schedule
,
Show
,
TimeSlot
,
Type
,
Image
from
program.tests.factories
import
(
CommonUserFactory
,
FundingCategoryFactory
,
HostFactory
,
RRuleFactory
,
ScheduleFactory
,
ShowFactory
,
TimeslotFactory
,
TypeFactory
,
ImageFactory
,
)
def
assert_data
(
response
,
data
)
->
None
:
if
"
schedule
"
in
data
:
for
key
,
value
in
data
[
"
schedule
"
].
items
():
if
key
==
"
rrule
"
:
assert
response
.
data
[
key
]
==
value
else
:
assert
str
(
response
.
data
[
key
])
==
value
else
:
for
key
,
value
in
data
.
items
():
if
key
==
"
password
"
:
continue
assert
response
.
data
[
key
]
==
value
@pytest.fixture
def
host
()
->
Host
:
return
HostFactory
()
@pytest.fixture
def
image_file
()
->
SimpleUploadedFile
:
return
SimpleUploadedFile
(
"
image.png
"
,
open
(
"
program/tests/data/image.png
"
,
"
rb
"
).
read
())
@pytest.fixture
def
image
(
image_file
)
->
Image
:
return
ImageFactory
(
image
=
image_file
)
@pytest.fixture
def
owned_image
(
image_file
,
common_user1
)
->
Image
:
return
ImageFactory
(
image
=
image_file
,
owner
=
common_user1
)
@pytest.fixture
def
api_client
()
->
APIClient
:
"""
Unauthenticated API client
"""
return
APIClient
()
@pytest.fixture
def
admin_api_client
(
api_client
,
admin_user
)
->
APIClient
:
"""
Authenticated admin user (superuser) API client
"""
api_client
.
force_authenticate
(
admin_user
)
yield
api_client
api_client
.
force_authenticate
()
@pytest.fixture
def
common_user1
()
->
User
:
return
CommonUserFactory
()
@pytest.fixture
def
common_user2
()
->
User
:
return
CommonUserFactory
()
@pytest.fixture
def
common_api_client1
(
api_client
,
common_user1
)
->
APIClient
:
"""
Authenticated common user 1 API client
"""
api_client
.
force_authenticate
(
common_user1
)
yield
api_client
api_client
.
force_authenticate
()
@pytest.fixture
def
common_api_client2
(
api_client
,
common_user2
)
->
APIClient
:
"""
Authenticated common user 2 API client
"""
api_client
.
force_authenticate
(
common_user2
)
yield
api_client
api_client
.
force_authenticate
()
@pytest.fixture
def
once_rrule
()
->
RRule
:
return
RRuleFactory
(
freq
=
0
)
@pytest.fixture
def
show
()
->
Show
:
return
ShowFactory
()
@pytest.fixture
def
owned_show
(
common_user1
):
show
=
ShowFactory
()
show
.
owners
.
set
([
common_user1
])
show
.
save
()
return
show
@pytest.fixture
def
owned_show_once_timeslot
(
common_user1
,
show
,
once_schedule
)
->
TimeSlot
:
show
.
owners
.
set
([
common_user1
])
show
.
save
()
timeslot
=
TimeslotFactory
(
show
=
show
,
schedule
=
once_schedule
)
return
timeslot
@pytest.fixture
def
once_timeslot
(
show
,
once_schedule
)
->
TimeSlot
:
return
TimeslotFactory
(
show
=
show
,
schedule
=
once_schedule
)
@pytest.fixture
def
once_schedule
(
once_rrule
,
show
)
->
Schedule
:
start
=
datetime
.
now
()
end
=
start
+
timedelta
(
hours
=
1
)
return
ScheduleFactory
(
end_time
=
end
.
strftime
(
"
%H:%M:%S
"
),
first_date
=
start
.
strftime
(
"
%Y-%m-%d
"
),
rrule
=
once_rrule
,
show
=
show
,
start_time
=
start
.
strftime
(
"
%H:%M:%S
"
),
)
@pytest.fixture
def
funding_category
()
->
FundingCategory
:
return
FundingCategoryFactory
()
@pytest.fixture
def
type_
()
->
Type
:
return
TypeFactory
()
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