Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-deposit
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
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
Platform
Development
swh-deposit
Commits
29b30d4e
Verified
Commit
29b30d4e
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
tests_deposit_private_update_status: Migrate to pytest
parent
8d49c14e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!40
Migrate most deposit tests to pytest
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/deposit/tests/api/conftest.py
+14
-1
14 additions, 1 deletion
swh/deposit/tests/api/conftest.py
swh/deposit/tests/api/test_deposit_private_update_status.py
+68
-62
68 additions, 62 deletions
swh/deposit/tests/api/test_deposit_private_update_status.py
with
82 additions
and
63 deletions
swh/deposit/tests/api/conftest.py
+
14
−
1
View file @
29b30d4e
...
...
@@ -10,7 +10,9 @@ from django.urls import reverse
from
os
import
path
,
listdir
from
typing
import
Mapping
from
swh.deposit.config
import
DEPOSIT_STATUS_DEPOSITED
,
COL_IRI
from
swh.deposit.config
import
(
DEPOSIT_STATUS_DEPOSITED
,
COL_IRI
,
DEPOSIT_STATUS_VERIFIED
)
from
swh.deposit.models
import
Deposit
from
swh.deposit.parsers
import
parse_xml
...
...
@@ -50,6 +52,17 @@ def ready_deposit_ok(partial_deposit_with_metadata):
return
deposit
@pytest.fixture
def
ready_deposit_verified
(
partial_deposit_with_metadata
):
"""
Returns a deposit ready for checks (it will pass the checks).
"""
deposit
=
partial_deposit_with_metadata
deposit
.
status
=
DEPOSIT_STATUS_VERIFIED
deposit
.
save
()
return
deposit
@pytest.fixture
def
ready_deposit_only_metadata
(
partial_deposit_only_metadata
):
"""
Deposit in status ready that will fail the checks (because missing
...
...
This diff is collapsed.
Click to expand it.
swh/deposit/tests/api/test_deposit_private_update_status.py
+
68
−
62
View file @
29b30d4e
...
...
@@ -7,57 +7,56 @@ import json
from
django.urls
import
reverse
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
from
swh.deposit.models
import
Deposit
,
DEPOSIT_STATUS_DETAIL
from
swh.deposit.config
import
PRIVATE_PUT_DEPOSIT
,
DEPOSIT_STATUS_VERIFIED
from
swh.deposit.config
import
DEPOSIT_STATUS_LOAD_SUCCESS
from
swh.deposit.tests.common
import
BasicTestCase
from
swh.deposit.config
import
(
PRIVATE_PUT_DEPOSIT
,
DEPOSIT_STATUS_VERIFIED
,
DEPOSIT_STATUS_LOAD_SUCCESS
)
class
UpdateDepositStatusTest
(
APITestCase
,
BasicTestCase
):
"""
Update the deposit
'
s status scenario
PRIVATE_PUT_DEPOSIT_NC
=
PRIVATE_PUT_DEPOSIT
+
'
-nc
'
"""
def
setUp
(
self
):
super
().
setUp
()
deposit
=
Deposit
(
status
=
DEPOSIT_STATUS_VERIFIED
,
collection
=
self
.
collection
,
client
=
self
.
user
)
deposit
.
save
()
self
.
deposit
=
Deposit
.
objects
.
get
(
pk
=
deposit
.
id
)
assert
self
.
deposit
.
status
==
DEPOSIT_STATUS_VERIFIED
def
private_deposit_url
(
self
,
deposit_id
):
return
reverse
(
PRIVATE_PUT_DEPOSIT
,
args
=
[
self
.
collection
.
name
,
deposit_id
])
def
private_check_url_endpoints
(
collection
,
deposit
):
"""
There are 2 endpoints to check (one with collection, one without)
"""
return
[
reverse
(
PRIVATE_PUT_DEPOSIT
,
args
=
[
collection
.
name
,
deposit
.
id
]),
reverse
(
PRIVATE_PUT_DEPOSIT_NC
,
args
=
[
deposit
.
id
])
]
def
test_update_deposit_status
(
self
):
"""
Existing status for update should return a 204 response
"""
url
=
self
.
private_deposit_url
(
self
.
deposit
.
id
)
def
test_update_deposit_status
(
authenticated_client
,
deposit_collection
,
ready_deposit_verified
):
"""
Existing status for update should return a 204 response
"""
deposit
=
ready_deposit_verified
for
url
in
private_check_url_endpoints
(
deposit_collection
,
deposit
):
possible_status
=
set
(
DEPOSIT_STATUS_DETAIL
.
keys
())
-
set
(
[
DEPOSIT_STATUS_LOAD_SUCCESS
])
for
_status
in
possible_status
:
response
=
self
.
client
.
put
(
response
=
authenticated_
client
.
put
(
url
,
content_type
=
'
application/json
'
,
data
=
json
.
dumps
({
'
status
'
:
_status
}))
self
.
assert
Equal
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
assert
response
.
status_code
==
status
.
HTTP_204_NO_CONTENT
deposit
=
Deposit
.
objects
.
get
(
pk
=
self
.
deposit
.
id
)
self
.
assert
Equal
(
deposit
.
status
,
_status
)
deposit
=
Deposit
.
objects
.
get
(
pk
=
deposit
.
id
)
assert
deposit
.
status
==
_status
def
test_update_
deposit
_
status
_with_info
(
self
):
"""
Existing status for update with info should return a 204 response
deposit
.
status
=
DEPOSIT_STATUS_VERIFIED
deposit
.
save
()
# hack the same deposit
"""
url
=
self
.
private_deposit_url
(
self
.
deposit
.
id
)
def
test_update_deposit_status_with_info
(
authenticated_client
,
deposit_collection
,
ready_deposit_verified
):
"""
Existing status for update with info should return a 204 response
"""
deposit
=
ready_deposit_verified
for
url
in
private_check_url_endpoints
(
deposit_collection
,
deposit
):
expected_status
=
DEPOSIT_STATUS_LOAD_SUCCESS
origin_url
=
'
something
'
directory_id
=
'
42a13fc721c8716ff695d0d62fc851d641f3a12b
'
...
...
@@ -69,7 +68,7 @@ class UpdateDepositStatusTest(APITestCase, BasicTestCase):
expected_swh_anchor_id_context
=
'
swh:1:rev:%s;origin=%s
'
%
(
revision_id
,
origin_url
)
response
=
self
.
client
.
put
(
response
=
authenticated_
client
.
put
(
url
,
content_type
=
'
application/json
'
,
data
=
json
.
dumps
({
...
...
@@ -79,56 +78,63 @@ class UpdateDepositStatusTest(APITestCase, BasicTestCase):
'
origin_url
'
:
origin_url
,
}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
assert
response
.
status_code
==
status
.
HTTP_204_NO_CONTENT
deposit
=
Deposit
.
objects
.
get
(
pk
=
deposit
.
id
)
assert
deposit
.
status
==
expected_status
assert
deposit
.
swh_id
==
expected_swh_id
assert
deposit
.
swh_id_context
==
expected_swh_id_context
assert
deposit
.
swh_anchor_id
==
expected_swh_anchor_id
assert
deposit
.
swh_anchor_id_context
==
expected_swh_anchor_id_context
deposit
=
Deposit
.
objects
.
get
(
pk
=
self
.
deposit
.
id
)
self
.
assertEqual
(
deposit
.
status
,
expected_status
)
self
.
assertEqual
(
deposit
.
swh_id
,
expected_swh_id
)
self
.
assertEqual
(
deposit
.
swh_id_context
,
expected_swh_id_context
)
self
.
assertEqual
(
deposit
.
swh_anchor_id
,
expected_swh_anchor_id
)
self
.
assertEqual
(
deposit
.
swh_anchor_id_context
,
expected_swh_anchor_id_context
)
deposit
.
swh_id
=
None
deposit
.
swh_id_context
=
None
deposit
.
swh_anchor_id
=
None
deposit
.
swh_anchor_id_context
=
None
deposit
.
status
=
DEPOSIT_STATUS_VERIFIED
deposit
.
save
()
def
test_update_deposit_status_will_fail_with_unknown_status
(
self
):
"""
Unknown status for update should return a 400 response
"""
url
=
self
.
private_deposit_url
(
self
.
deposit
.
id
)
def
test_update_deposit_status_will_fail_with_unknown_status
(
authenticated_client
,
deposit_collection
,
ready_deposit_verified
):
"""
Unknown status for update should return a 400 response
response
=
self
.
client
.
put
(
"""
deposit
=
ready_deposit_verified
for
url
in
private_check_url_endpoints
(
deposit_collection
,
deposit
):
response
=
authenticated_client
.
put
(
url
,
content_type
=
'
application/json
'
,
data
=
json
.
dumps
({
'
status
'
:
'
unknown
'
}))
self
.
assert
Equal
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
assert
response
.
status_code
==
status
.
HTTP_400_BAD_REQUEST
def
test_update_deposit_status_will_fail_with_no_status_key
(
self
):
"""
No status provided for update should return a 400 response
"""
url
=
self
.
private_deposit_url
(
self
.
deposit
.
id
)
def
test_update_deposit_status_will_fail_with_no_status_key
(
authenticated_client
,
deposit_collection
,
ready_deposit_verified
):
"""
No status provided for update should return a 400 response
response
=
self
.
client
.
put
(
"""
deposit
=
ready_deposit_verified
for
url
in
private_check_url_endpoints
(
deposit_collection
,
deposit
):
response
=
authenticated_client
.
put
(
url
,
content_type
=
'
application/json
'
,
data
=
json
.
dumps
({
'
something
'
:
'
something
'
}))
self
.
assert
Equal
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
assert
response
.
status_code
==
status
.
HTTP_400_BAD_REQUEST
def
test_update_deposit_status_success_without_swh_id_fail
(
self
):
"""
Providing successful status without swh_id should return a 400
"""
url
=
self
.
private_deposit_url
(
self
.
deposit
.
id
)
def
test_update_deposit_status_success_without_swh_id_fail
(
authenticated_client
,
deposit_collection
,
ready_deposit_verified
):
"""
Providing successful status without swh_id should return a 400
response
=
self
.
client
.
put
(
"""
deposit
=
ready_deposit_verified
for
url
in
private_check_url_endpoints
(
deposit_collection
,
deposit
):
response
=
authenticated_client
.
put
(
url
,
content_type
=
'
application/json
'
,
data
=
json
.
dumps
({
'
status
'
:
DEPOSIT_STATUS_LOAD_SUCCESS
}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
class
UpdateDepositStatusTest2
(
UpdateDepositStatusTest
):
def
private_deposit_url
(
self
,
deposit_id
):
return
reverse
(
PRIVATE_PUT_DEPOSIT
+
'
-nc
'
,
args
=
[
deposit_id
])
assert
response
.
status_code
==
status
.
HTTP_400_BAD_REQUEST
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