Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8394407
test_identifiers.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
test_identifiers.py
View Options
# Copyright (C) 2018 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
from
hypothesis
import
given
from
rest_framework.test
import
APITestCase
from
swh.model.identifiers
import
(
CONTENT
,
DIRECTORY
,
RELEASE
,
REVISION
,
SNAPSHOT
)
from
swh.web.common.utils
import
reverse
from
swh.web.tests.strategies
import
(
content
,
directory
,
origin
,
release
,
revision
,
snapshot
,
unknown_content
,
unknown_directory
,
unknown_release
,
unknown_revision
,
unknown_snapshot
)
from
swh.web.tests.testcase
import
WebTestCase
class
SwhIdsApiTestCase
(
WebTestCase
,
APITestCase
):
@given
(
origin
(),
content
(),
directory
(),
release
(),
revision
(),
snapshot
())
def
test_swh_id_resolve_success
(
self
,
origin
,
content
,
directory
,
release
,
revision
,
snapshot
):
for
obj_type_short
,
obj_type
,
obj_id
in
(
(
'cnt'
,
CONTENT
,
content
[
'sha1_git'
]),
(
'dir'
,
DIRECTORY
,
directory
),
(
'rel'
,
RELEASE
,
release
),
(
'rev'
,
REVISION
,
revision
),
(
'snp'
,
SNAPSHOT
,
snapshot
)):
swh_id
=
'swh:1:
%s
:
%s
;origin=
%s
'
%
(
obj_type_short
,
obj_id
,
origin
[
'url'
])
url
=
reverse
(
'api-resolve-swh-pid'
,
url_args
=
{
'swh_id'
:
swh_id
})
resp
=
self
.
client
.
get
(
url
)
if
obj_type
==
CONTENT
:
url_args
=
{
'query_string'
:
'sha1_git:
%s
'
%
obj_id
}
elif
obj_type
==
SNAPSHOT
:
url_args
=
{
'snapshot_id'
:
obj_id
}
else
:
url_args
=
{
'sha1_git'
:
obj_id
}
browse_rev_url
=
reverse
(
'browse-
%s
'
%
obj_type
,
url_args
=
url_args
,
query_params
=
{
'origin'
:
origin
[
'url'
]})
expected_result
=
{
'browse_url'
:
browse_rev_url
,
'metadata'
:
{
'origin'
:
origin
[
'url'
]},
'namespace'
:
'swh'
,
'object_id'
:
obj_id
,
'object_type'
:
obj_type
,
'scheme_version'
:
1
}
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
data
,
expected_result
)
def
test_swh_id_resolve_invalid
(
self
):
rev_id_invalid
=
'96db9023b8_foo_50d6c108e9a3'
swh_id
=
'swh:1:rev:
%s
'
%
rev_id_invalid
url
=
reverse
(
'api-resolve-swh-pid'
,
url_args
=
{
'swh_id'
:
swh_id
})
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
resp
.
status_code
,
400
)
@given
(
unknown_content
(),
unknown_directory
(),
unknown_release
(),
unknown_revision
(),
unknown_snapshot
())
def
test_swh_id_resolve_not_found
(
self
,
unknown_content
,
unknown_directory
,
unknown_release
,
unknown_revision
,
unknown_snapshot
):
for
obj_type_short
,
obj_id
in
((
'cnt'
,
unknown_content
[
'sha1_git'
]),
(
'dir'
,
unknown_directory
),
(
'rel'
,
unknown_release
),
(
'rev'
,
unknown_revision
),
(
'snp'
,
unknown_snapshot
)):
swh_id
=
'swh:1:
%s
:
%s
'
%
(
obj_type_short
,
obj_id
)
url
=
reverse
(
'api-resolve-swh-pid'
,
url_args
=
{
'swh_id'
:
swh_id
})
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
resp
.
status_code
,
404
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Wed, Jun 4, 7:24 PM (1 w, 18 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3391241
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment