diff --git a/swh/deposit/tests/test_utils.py b/swh/deposit/tests/test_utils.py
index e3495685f914c8c2b336225cb09eb389709413bb..27e06047ed975187ba68e3ac4bced294da686e2b 100644
--- a/swh/deposit/tests/test_utils.py
+++ b/swh/deposit/tests/test_utils.py
@@ -4,6 +4,7 @@
 # See top-level LICENSE file for more information
 
 import unittest
+import pytest
 
 from unittest.mock import patch
 
@@ -12,7 +13,9 @@ from swh.deposit.models import Deposit, DepositClient
 
 
 def test_origin_url_from():
+    """With correctly setup-ed deposit, all is fine
 
+    """
     for provider_url, external_id in (
             ('http://somewhere.org', 'uuid'),
             ('http://overthejungle.org', 'diuu'),
@@ -28,6 +31,23 @@ def test_origin_url_from():
             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):
     """Utils library
 
diff --git a/swh/deposit/utils.py b/swh/deposit/utils.py
index 4818fc74e1a09dc2fdc93d651f77e2f64a0a26b9..beb31ef629df6096d848bb27da8679daf982fe27 100644
--- a/swh/deposit/utils.py
+++ b/swh/deposit/utils.py
@@ -11,17 +11,27 @@ from swh.model.identifiers import normalize_timestamp
 
 
 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:
         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
        The associated origin url
 
     """
-    base_url = deposit.client.provider_url
     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)