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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Antoine R. Dumont
swh-deposit
Commits
45aeec44
Verified
Commit
45aeec44
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
utils: Enforce necessary setup for deposit and associated client
Related T1648
parent
56e90372
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/deposit/tests/test_utils.py
+20
-0
20 additions, 0 deletions
swh/deposit/tests/test_utils.py
swh/deposit/utils.py
+12
-2
12 additions, 2 deletions
swh/deposit/utils.py
with
32 additions
and
2 deletions
swh/deposit/tests/test_utils.py
+
20
−
0
View file @
45aeec44
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
# See top-level LICENSE file for more information
# See top-level LICENSE file for more information
import
unittest
import
unittest
import
pytest
from
unittest.mock
import
patch
from
unittest.mock
import
patch
...
@@ -12,7 +13,9 @@ from swh.deposit.models import Deposit, DepositClient
...
@@ -12,7 +13,9 @@ from swh.deposit.models import Deposit, DepositClient
def
test_origin_url_from
():
def
test_origin_url_from
():
"""
With correctly setup-ed deposit, all is fine
"""
for
provider_url
,
external_id
in
(
for
provider_url
,
external_id
in
(
(
'
http://somewhere.org
'
,
'
uuid
'
),
(
'
http://somewhere.org
'
,
'
uuid
'
),
(
'
http://overthejungle.org
'
,
'
diuu
'
),
(
'
http://overthejungle.org
'
,
'
diuu
'
),
...
@@ -28,6 +31,23 @@ def test_origin_url_from():
...
@@ -28,6 +31,23 @@ def test_origin_url_from():
provider_url
.
rstrip
(
'
/
'
),
external_id
)
provider_url
.
rstrip
(
'
/
'
),
external_id
)
def
test_origin_url_from_ko
():
"""
Badly configured deposit should raise
"""
for
provider_url
,
external_id
in
(
(
None
,
'
uuid
'
),
(
'
http://overthejungle.org
'
,
None
),
):
deposit
=
Deposit
(
client
=
DepositClient
(
provider_url
=
provider_url
),
external_id
=
None
)
with
pytest
.
raises
(
AssertionError
):
utils
.
origin_url_from
(
deposit
)
class
UtilsTestCase
(
unittest
.
TestCase
):
class
UtilsTestCase
(
unittest
.
TestCase
):
"""
Utils library
"""
Utils library
...
...
This diff is collapsed.
Click to expand it.
swh/deposit/utils.py
+
12
−
2
View file @
45aeec44
...
@@ -11,17 +11,27 @@ from swh.model.identifiers import normalize_timestamp
...
@@ -11,17 +11,27 @@ from swh.model.identifiers import normalize_timestamp
def
origin_url_from
(
deposit
):
def
origin_url_from
(
deposit
):
"""
Given a deposit instance, return the associated origin url
"""
Given a deposit instance, return the associated origin url.
This expects a deposit and the associated client to be correctly
configured.
Args:
Args:
deposit (Deposit): The deposit from which derives the origin url
deposit (Deposit): The deposit from which derives the origin url
Raises:
AssertionError if:
- the client
'
s provider_url field is not configured.
- the deposit
'
s external_id field is not configured.
Returns
Returns
The associated origin url
The associated origin url
"""
"""
base_url
=
deposit
.
client
.
provider_url
external_id
=
deposit
.
external_id
external_id
=
deposit
.
external_id
assert
external_id
is
not
None
base_url
=
deposit
.
client
.
provider_url
assert
base_url
is
not
None
return
'
%s/%s
'
%
(
base_url
.
rstrip
(
'
/
'
),
external_id
)
return
'
%s/%s
'
%
(
base_url
.
rstrip
(
'
/
'
),
external_id
)
...
...
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