Skip to content

Commit

Permalink
Mock the response for test_detect_ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
u10313335 committed Mar 25, 2024
1 parent 7712751 commit 1039d8d
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions tests/unit/contentproviders/test_ckan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,23 @@
from contextlib import contextmanager
from tempfile import NamedTemporaryFile, TemporaryDirectory

import pytest

from repo2docker.contentproviders import CKAN

test_ckan = CKAN()
test_hosts = [
(
[
"http://demo.ckan.org/dataset/sample-dataset-1",
],
{
"dataset_id": "sample-dataset-1",
"api_url": "http://demo.ckan.org/api/3/action/",
"version": "1707387710",
},

def test_detect_ckan(requests_mock):
mock_response = {"result": {"metadata_modified": "2024-02-27T14:15:54.573058"}}
requests_mock.get("http://demo.ckan.org/api/3/action/status_show", status_code=200)
requests_mock.get(
"http://demo.ckan.org/api/3/action/package_show?id=1234", json=mock_response
)
]

expected = {
"dataset_id": "1234",
"api_url": "http://demo.ckan.org/api/3/action/",
"version": "1709043354",
}

@pytest.mark.parametrize("test_input, expected", test_hosts)
def test_detect_ckan(test_input, expected):
assert CKAN().detect(test_input[0]) == expected
assert CKAN().detect("http://demo.ckan.org/dataset/1234") == expected


def test_detect_not_ckan():
Expand Down

0 comments on commit 1039d8d

Please sign in to comment.