Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
69ba3f08
Commit
69ba3f08
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Fix tests for PDFFile
parent
cd623328
No related branches found
No related tags found
1 merge request
!617
Resolve "Remove token-based filenames for generated PDF files"
Pipeline
#12205
failed
3 years ago
Stage: test
Stage: build
Stage: publish
Stage: docker
Stage: deploy
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/core/tests/models/test_pdffile.py
+7
-7
7 additions, 7 deletions
aleksis/core/tests/models/test_pdffile.py
with
7 additions
and
7 deletions
aleksis/core/tests/models/test_pdffile.py
+
7
−
7
View file @
69ba3f08
...
...
@@ -3,6 +3,7 @@ import re
from
datetime
import
datetime
,
timedelta
from
django.core.files
import
File
from
django.core.files.base
import
ContentFile
from
django.core.files.storage
import
default_storage
from
django.template.loader
import
render_to_string
from
django.test
import
TransactionTestCase
,
override_settings
...
...
@@ -25,14 +26,13 @@ class PDFFIleTest(TransactionTestCase):
_test_pdf
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
"
test.pdf
"
)
def
_get_test_html
(
self
):
return
render_to_string
(
"
core/pages/test_pdf.html
"
)
return
ContentFile
(
render_to_string
(
"
core/pages/test_pdf.html
"
)
,
name
=
"
source.html
"
)
def
test_pdf_file
(
self
):
dummy_person
=
Person
.
objects
.
create
(
first_name
=
"
Jane
"
,
last_name
=
"
Doe
"
)
html
=
self
.
_get_test_html
()
assert
"
html
"
in
html
file_object
=
PDFFile
.
objects
.
create
(
person
=
dummy_person
,
html
=
html
)
file_object
=
PDFFile
.
objects
.
create
(
person
=
dummy_person
,
html_file
=
html
)
assert
isinstance
(
file_object
.
expires_at
,
datetime
)
assert
file_object
.
expires_at
>
timezone
.
now
()
assert
not
bool
(
file_object
.
file
)
...
...
@@ -40,12 +40,12 @@ class PDFFIleTest(TransactionTestCase):
with
open
(
self
.
_test_pdf
,
"
rb
"
)
as
f
:
file_object
.
file
.
save
(
"
print.pdf
"
,
File
(
f
))
file_object
.
save
()
re_base
=
r
"
pdfs/[a-zA-Z0-9]+\.pdf
"
re_base
=
r
"
pdfs/
print_
[a-zA-Z0-9]+\.pdf
"
assert
re
.
match
(
re_base
,
file_object
.
file
.
name
)
def
test_delete_signal
(
self
):
dummy_person
=
Person
.
objects
.
create
(
first_name
=
"
Jane
"
,
last_name
=
"
Doe
"
)
file_object
=
PDFFile
.
objects
.
create
(
person
=
dummy_person
,
html
=
self
.
_get_test_html
())
file_object
=
PDFFile
.
objects
.
create
(
person
=
dummy_person
,
html
_file
=
self
.
_get_test_html
())
with
open
(
self
.
_test_pdf
,
"
rb
"
)
as
f
:
file_object
.
file
.
save
(
"
print.pdf
"
,
File
(
f
))
file_object
.
save
()
...
...
@@ -59,10 +59,10 @@ class PDFFIleTest(TransactionTestCase):
def
test_delete_expired_files
(
self
):
# Create test instances
dummy_person
=
Person
.
objects
.
create
(
first_name
=
"
Jane
"
,
last_name
=
"
Doe
"
)
file_object
=
PDFFile
.
objects
.
create
(
person
=
dummy_person
,
html
=
self
.
_get_test_html
())
file_object
=
PDFFile
.
objects
.
create
(
person
=
dummy_person
,
html
_file
=
self
.
_get_test_html
())
file_object2
=
PDFFile
.
objects
.
create
(
person
=
dummy_person
,
html
=
self
.
_get_test_html
(),
html
_file
=
self
.
_get_test_html
(),
expires_at
=
timezone
.
now
()
+
timedelta
(
minutes
=
10
),
)
with
open
(
self
.
_test_pdf
,
"
rb
"
)
as
f
:
...
...
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