Unverified Commit cf1a83b3 authored by Nicola Soranzo's avatar Nicola Soranzo Committed by GitHub
Browse files

Merge pull request #14186 from davelopez/21.01_fix_histories_api_url_building

parents 216378ab cb831918
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -469,9 +469,9 @@ class HistorySerializer(sharable.SharableModelSerializer, deletable.PurgableSeri
            'nice_size': lambda item, key, **context: item.disk_nice_size,
            'state': self.serialize_history_state,

            'url': lambda item, key, **context: self.url_for('history', id=self.app.security.encode_id(item.id)),
            'url': lambda item, key, **context: self.url_for('history', id=self.app.security.encode_id(item.id), context=context),
            'contents_url': lambda item, key, **context: self.url_for('history_contents',
                                                           history_id=self.app.security.encode_id(item.id)),
                                                           history_id=self.app.security.encode_id(item.id), context=context),

            'empty': lambda item, key, **context: (len(item.datasets) + len(item.dataset_collections)) <= 0,
            'count': lambda item, key, **context: len(item.datasets),
+1 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ class FastAPIHistories:

    @router.get(
        '/api/histories/{id}',
        name="history",
        summary='Returns the history with the given ID.',
    )
    def show(
+9 −0
Original line number Diff line number Diff line
@@ -77,6 +77,15 @@ class HistoriesApiTestCase(ApiTestCase, BaseHistories):
        self._assert_has_keys(state_details, *states)
        self._assert_has_keys(state_ids, *states)

    def test_show_history_returns_expected_urls(self):
        # This test can be dropped when the URL attributes become deprecated
        history_id = self._create_history("TestHistoryForUrls")["id"]
        show_response = self._show(history_id)
        self._assert_has_key(show_response, 'id', 'url', 'contents_url')

        assert show_response["url"] == f"/api/histories/{history_id}"
        assert show_response["contents_url"] == f"/api/histories/{history_id}/contents"

    def test_show_most_recently_used(self):
        history_id = self._create_history("TestHistoryRecent")["id"]
        show_response = self._get("histories/most_recently_used").json()