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
c41f071d
Verified
Commit
c41f071d
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for `APIImageViewSet`
parent
7c55890e
No related branches found
No related tags found
No related merge requests found
Pipeline
#3300
passed
1 year ago
Stage: build
Stage: deploy
Stage: release
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/tests/__init__.py
+26
-1
26 additions, 1 deletion
program/tests/__init__.py
program/tests/test_images.py
+135
-0
135 additions, 0 deletions
program/tests/test_images.py
with
161 additions
and
1 deletion
program/tests/__init__.py
+
26
−
1
View file @
c41f071d
import
datetime
from
io
import
BytesIO
from
PIL
import
Image
as
PILImage
from
django.contrib.auth.models
import
User
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.utils.text
import
slugify
from
django.utils.timezone
import
now
from
program.models
import
Note
,
RRule
,
Schedule
,
Show
,
TimeSlot
from
program.models
import
Image
,
Note
,
RRule
,
Schedule
,
Show
,
TimeSlot
class
SteeringTestCaseMixin
:
...
...
@@ -33,6 +37,27 @@ class UserMixin:
)
class
ImageMixin
:
@staticmethod
def
_get_image_file
(
size
=
(
400
,
400
),
color
=
(
255
,
0
,
0
))
->
SimpleUploadedFile
:
image_bytes
=
BytesIO
()
PILImage
.
new
(
mode
=
"
RGB
"
,
size
=
size
,
color
=
color
).
save
(
image_bytes
,
format
=
"
png
"
)
return
SimpleUploadedFile
(
"
image.png
"
,
image_bytes
.
getvalue
())
@staticmethod
def
_create_image
(
size
=
(
400
,
400
),
color
=
(
255
,
0
,
0
),
alt_text
=
""
,
credits
=
""
,
owner
=
None
)
->
Image
:
return
Image
.
objects
.
create
(
alt_text
=
alt_text
,
credits
=
credits
,
image
=
ImageMixin
.
_get_image_file
(
size
=
size
,
color
=
color
),
owner
=
owner
,
)
class
ShowMixin
:
def
_create_show
(
self
,
name
:
str
,
**
kwargs
):
kwargs
[
"
name
"
]
=
name
...
...
This diff is collapsed.
Click to expand it.
program/tests/test_images.py
0 → 100644
+
135
−
0
View file @
c41f071d
from
rest_framework.test
import
APITransactionTestCase
from
program.tests
import
ImageMixin
,
SteeringTestCaseMixin
,
UserMixin
class
ImageViewTestCase
(
UserMixin
,
ImageMixin
,
SteeringTestCaseMixin
,
APITransactionTestCase
):
reset_sequences
=
True
def
test_create_image
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
)
image_data
=
{
"
image
"
:
self
.
_get_image_file
()}
response
=
client
.
post
(
url
,
data
=
image_data
,
format
=
"
multipart
"
)
self
.
assertEqual
(
response
.
status_code
,
201
)
def
test_destroy_image
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
response
=
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
204
)
def
test_destroy_image_not_found_for_different_user
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_common
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
response
=
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_list_images
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
)
for
_
in
range
(
3
):
self
.
_create_image
(
owner
=
self
.
user_admin
)
response
=
client
.
get
(
url
)
self
.
assertEqual
(
len
(
response
.
data
),
3
)
def
test_list_images_for_different_user
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
)
for
_
in
range
(
3
):
self
.
_create_image
(
owner
=
self
.
user_common
)
response
=
client
.
get
(
url
)
self
.
assertEqual
(
len
(
response
.
data
),
0
)
def
test_retrieve_image
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
data
=
{
"
alt_text
"
:
"
ALT_TEXT
"
,
"
credits
"
:
"
CREDITS
"
}
image
=
self
.
_create_image
(
**
data
,
owner
=
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
response
=
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
"
alt_text
"
],
data
[
"
alt_text
"
])
self
.
assertEqual
(
response
.
data
[
"
credits
"
],
data
[
"
credits
"
])
def
test_retrieve_image_not_found_for_different_user
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_common
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
response
=
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_update_alt_text
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
update
=
{
"
alt_text
"
:
"
ALT_TEXT
"
}
response
=
client
.
put
(
url
,
data
=
update
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
"
alt_text
"
],
update
[
"
alt_text
"
])
def
test_update_alt_text_not_found_for_different_user
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_common
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
response
=
client
.
put
(
url
,
data
=
{
"
alt_text
"
:
"
ALT_TEXT
"
})
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_update_credits
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
update
=
{
"
credits
"
:
"
CREDITS
"
}
response
=
client
.
put
(
url
,
data
=
update
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
"
credits
"
],
update
[
"
credits
"
])
def
test_update_credits_not_found_for_different_user
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_common
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
response
=
client
.
put
(
url
,
data
=
{
"
credits
"
:
"
CREDITS
"
})
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_update_ppoi
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_admin
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
update
=
{
"
ppoi
"
:
"
0.3x0.7
"
}
response
=
client
.
put
(
url
,
data
=
update
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
"
ppoi
"
],
update
[
"
ppoi
"
])
def
test_update_ppoi_not_found_for_different_user
(
self
):
client
=
self
.
_get_client
(
self
.
user_admin
)
image
=
self
.
_create_image
(
owner
=
self
.
user_common
)
url
=
self
.
_url
(
"
images
"
,
image
.
id
)
response
=
client
.
put
(
url
,
data
=
{
"
ppoi
"
:
"
0.3x0.7
"
})
self
.
assertEqual
(
response
.
status_code
,
404
)
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