Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
WiKoDa - Server
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
innohs_one
WiKoDa - Server
Commits
3131d393
Commit
3131d393
authored
3 years ago
by
Jan Bernoth
Browse files
Options
Downloads
Patches
Plain Diff
test overview with or without user
parent
ccf47022
No related branches found
No related tags found
1 merge request
!122
User centric api
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
articles/test_api.py
+59
-4
59 additions, 4 deletions
articles/test_api.py
with
59 additions
and
4 deletions
articles/test_api.py
+
59
−
4
View file @
3131d393
...
...
@@ -7,8 +7,8 @@ from django.db.models.signals import post_save
from
django.test
import
TransactionTestCase
from
articles.apps
import
ArticlesConfig
from
articles.models
import
Article
,
MediumType
,
Medium
,
Files
,
User
from
articles.serializers
import
MediumTypeSerializer
,
MediumSerializer
,
ArticleSerializer
from
articles.models
import
Article
,
MediumType
,
Medium
,
Files
,
User
,
Tag
from
articles.serializers
import
MediumTypeSerializer
,
MediumSerializer
,
ArticleSerializer
,
write_article_to_db
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -109,10 +109,65 @@ class ArticleTest(TransactionTestCase):
class
OverviewTest
(
TransactionTestCase
):
"""
test functions for REST API Overview
"""
def
setUp
(
self
):
tag_1
=
Tag
(
name
=
"
Test1
"
)
tag_1
.
save
()
tag_2
=
Tag
(
name
=
"
Test2
"
)
tag_2
.
save
()
conf
=
ArticlesConfig
.
create
(
'
articles.apps.ArticlesConfig
'
)
conf
.
ready
()
with
mock
.
patch
(
'
articles.signals.extract_information_from_file
'
,
autospec
=
True
)
as
mocked_post_save
:
post_save
.
connect
(
mocked_post_save
,
sender
=
Files
,
dispatch_uid
=
'
extract_information_from_file
'
)
Files
.
objects
.
create
(
upload_file
=
'
testfile.pdf
'
,
upload_date
=
'
18.11.2021
'
)
file
=
Files
.
objects
.
get
(
upload_file
=
'
testfile.pdf
'
)
input_data
=
{
'
medium_name
'
:
'
MAZ
'
,
'
medium_type
'
:
'
Zeitung
'
,
'
name
'
:
'
Testartikel
'
,
'
source_file
'
:
file
,
'
reach
'
:
1000
,
'
date_of_publication
'
:
datetime
.
datetime
.
today
(),
'
text
'
:
'
Dies ist ein beispielhafter Beispieltext
'
,
'
pages
'
:
2
,
'
wrongly_parsed
'
:
True
,
'
tags
'
:
[
tag_1
.
name
,
tag_2
.
name
]
}
write_article_to_db
(
**
input_data
)
def
test_create_user_app_conf
(
self
):
"""
tests if user were created if config is ready
"""
logger
.
info
(
"
started OverviewTest.test_create_user_app_conf
"
)
conf
=
ArticlesConfig
.
create
(
'
articles.apps.ArticlesConfig
'
)
conf
.
ready
()
user
=
User
.
objects
.
get
(
id_tag
=
1
)
self
.
assertTrue
(
user
.
activated
)
self
.
assertEqual
(
user
.
favorite_tags
.
all
().
count
(),
2
)
def
test_overview_api_wo_user
(
self
):
"""
tests the api without user id
"""
logger
.
info
(
"
started OverviewTest.test_overview_api_wo_user
"
)
response
=
self
.
client
.
get
(
'
/articles/overview
'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
today_str
=
datetime
.
datetime
.
today
().
strftime
(
'
%Y-%m-%d
'
)
self
.
assertJSONEqual
(
str
(
response
.
content
,
encoding
=
'
utf8
'
),
[
{
"
name
"
:
"
Test1
"
,
"
article_name
"
:
"
Testartikel
"
,
"
medium_name
"
:
"
maz
"
,
"
date_of_publication
"
:
today_str
,
"
reach
"
:
"
1000
"
},
{
"
name
"
:
"
Test2
"
,
"
article_name
"
:
"
Testartikel
"
,
"
medium_name
"
:
"
maz
"
,
"
date_of_publication
"
:
today_str
,
"
reach
"
:
"
1000
"
}])
def
test_overview_api_with_user
(
self
):
"""
tests the overview with user id
"""
logger
.
info
(
"
started OverviewTest.test_overview_api_with_user
"
)
today_str
=
datetime
.
datetime
.
today
().
strftime
(
'
%Y-%m-%d
'
)
user
=
User
(
id_tag
=
2
)
user
.
save
()
tag2
=
Tag
.
objects
.
get
(
name
=
"
Test2
"
)
user
.
favorite_tags
.
add
(
tag2
)
user
.
save
()
response
=
self
.
client
.
get
(
'
/articles/overview?user=
'
+
str
(
user
.
id_tag
))
self
.
assertJSONEqual
(
str
(
response
.
content
,
encoding
=
'
utf8
'
),
[
{
"
name
"
:
tag2
.
name
,
"
article_name
"
:
"
Testartikel
"
,
"
medium_name
"
:
"
maz
"
,
"
date_of_publication
"
:
today_str
,
"
reach
"
:
"
1000
"
}
])
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