From cb80537aee629fd0dbec179243651cd2cab98cee Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Wed, 2 Feb 2022 12:48:57 +0000 Subject: [PATCH 01/12] create viz version graphql endpoint Signed-off-by: Tynan DeBold --- package/kedro_viz/api/graphql.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/package/kedro_viz/api/graphql.py b/package/kedro_viz/api/graphql.py index 917ffe17f7..6668218004 100644 --- a/package/kedro_viz/api/graphql.py +++ b/package/kedro_viz/api/graphql.py @@ -18,12 +18,14 @@ Optional, cast, ) +import requests import strawberry from fastapi import APIRouter from strawberry import ID from strawberry.asgi import GraphQL +from kedro_viz import __version__ from kedro_viz.data_access import data_access_manager from kedro_viz.models.experiments_tracking import RunModel, UserRunDetailsModel @@ -119,6 +121,22 @@ def get_runs(run_ids: List[ID]) -> List[Run]: ) +def get_version(): + """Get the user's installed Viz version and the latest version on PyPI. + Returns: + the currently installed and most-recent released version of Viz. + """ + package = 'kedro-viz' + response = requests.get(f'https://pypi.org/pypi/{package}/json') + latest_version = response.json()['info']['version'] + + version = Version( + current=__version__, + latest=latest_version + ) + return version + + def get_all_runs() -> List[Run]: """Get all runs from the session store. @@ -267,6 +285,14 @@ class TrackingDataset: data: Optional[JSONObject] +@strawberry.type +class Version: + """The latest and current Kedro Viz versions.""" + + current: str + latest: str + + @strawberry.type class Subscription: """Subscription object to track runs added in real time""" @@ -305,6 +331,11 @@ def run_tracking_data( """Query to get data for specific runs from the session store""" return get_run_tracking_data(run_ids, show_diff) + @strawberry.field + def version(self) -> Version: + """Query to get current and latest Kedro Viz versions""" + return get_version() + runs_list: List[Run] = strawberry.field(resolver=get_all_runs) From bbbed4f2cf91f69d8c3a468aed867d6b7bce9da4 Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Wed, 2 Feb 2022 13:02:38 +0000 Subject: [PATCH 02/12] fix formatting Signed-off-by: Tynan DeBold --- package/kedro_viz/api/graphql.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/package/kedro_viz/api/graphql.py b/package/kedro_viz/api/graphql.py index 6668218004..d3d7c6d36b 100644 --- a/package/kedro_viz/api/graphql.py +++ b/package/kedro_viz/api/graphql.py @@ -18,8 +18,8 @@ Optional, cast, ) -import requests +import requests import strawberry from fastapi import APIRouter from strawberry import ID @@ -121,19 +121,16 @@ def get_runs(run_ids: List[ID]) -> List[Run]: ) -def get_version(): +def get_version() -> Version: """Get the user's installed Viz version and the latest version on PyPI. Returns: the currently installed and most-recent released version of Viz. """ - package = 'kedro-viz' - response = requests.get(f'https://pypi.org/pypi/{package}/json') - latest_version = response.json()['info']['version'] + package = "kedro-viz" + response = requests.get(f"https://pypi.org/pypi/{package}/json") + latest_version = response.json()["info"]["version"] - version = Version( - current=__version__, - latest=latest_version - ) + version = Version(current=__version__, latest=latest_version) return version From 9b63ffaae3299a4f95d3a2048980333ef62d7938 Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Wed, 2 Feb 2022 14:16:40 +0000 Subject: [PATCH 03/12] update schema and edits based on Lim's comments Signed-off-by: Tynan DeBold --- package/kedro_viz/api/graphql.py | 12 +++--------- src/apollo/schema.graphql | 5 +++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/package/kedro_viz/api/graphql.py b/package/kedro_viz/api/graphql.py index d3d7c6d36b..26713a3840 100644 --- a/package/kedro_viz/api/graphql.py +++ b/package/kedro_viz/api/graphql.py @@ -19,7 +19,6 @@ cast, ) -import requests import strawberry from fastapi import APIRouter from strawberry import ID @@ -27,6 +26,7 @@ from kedro_viz import __version__ from kedro_viz.data_access import data_access_manager +from kedro_viz.integrations.pypi import get_latest_version from kedro_viz.models.experiments_tracking import RunModel, UserRunDetailsModel logger = logging.getLogger(__name__) @@ -126,10 +126,7 @@ def get_version() -> Version: Returns: the currently installed and most-recent released version of Viz. """ - package = "kedro-viz" - response = requests.get(f"https://pypi.org/pypi/{package}/json") - latest_version = response.json()["info"]["version"] - + latest_version = get_latest_version() version = Version(current=__version__, latest=latest_version) return version @@ -328,10 +325,7 @@ def run_tracking_data( """Query to get data for specific runs from the session store""" return get_run_tracking_data(run_ids, show_diff) - @strawberry.field - def version(self) -> Version: - """Query to get current and latest Kedro Viz versions""" - return get_version() + version: Version = strawberry.field(resolver=get_version) runs_list: List[Run] = strawberry.field(resolver=get_all_runs) diff --git a/src/apollo/schema.graphql b/src/apollo/schema.graphql index d0472778e4..0ea60d1cdc 100644 --- a/src/apollo/schema.graphql +++ b/src/apollo/schema.graphql @@ -49,3 +49,8 @@ union UpdateRunDetailsResponse = UpdateRunDetailsSuccess | UpdateRunDetailsFailu type UpdateRunDetailsSuccess { run: Run! } + +type Version { + current: String! + latest: String! +} From c5b5828f674028d375a4b652669dbc0d21f65361 Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Wed, 2 Feb 2022 14:31:08 +0000 Subject: [PATCH 04/12] update schema again Signed-off-by: Tynan DeBold --- package/kedro_viz/api/graphql.py | 6 +++--- src/apollo/schema.graphql | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package/kedro_viz/api/graphql.py b/package/kedro_viz/api/graphql.py index 26713a3840..910ca74638 100644 --- a/package/kedro_viz/api/graphql.py +++ b/package/kedro_viz/api/graphql.py @@ -127,7 +127,7 @@ def get_version() -> Version: the currently installed and most-recent released version of Viz. """ latest_version = get_latest_version() - version = Version(current=__version__, latest=latest_version) + version = Version(installed=__version__, latest=latest_version) return version @@ -281,9 +281,9 @@ class TrackingDataset: @strawberry.type class Version: - """The latest and current Kedro Viz versions.""" + """The installed and latest Kedro Viz versions.""" - current: str + installed: str latest: str diff --git a/src/apollo/schema.graphql b/src/apollo/schema.graphql index 0ea60d1cdc..d71c08bf43 100644 --- a/src/apollo/schema.graphql +++ b/src/apollo/schema.graphql @@ -9,6 +9,7 @@ type Query { runsList: [Run!]! runMetadata(runIds: [ID!]!): [Run!]! runTrackingData(runIds: [ID!]!, showDiff: Boolean = false): [TrackingDataset!]! + version: Version! } type Run { @@ -51,6 +52,6 @@ type UpdateRunDetailsSuccess { } type Version { - current: String! + installed: String! latest: String! } From 0f15e6864ebcd689116094c301afcd53d957050d Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Wed, 2 Feb 2022 14:46:57 +0000 Subject: [PATCH 05/12] try again Signed-off-by: Tynan DeBold --- RELEASE.md | 1 + src/apollo/schema.graphql | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 26d415c454..ece4119e9e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -10,6 +10,7 @@ Please follow the established format: ## Bug fixes and other changes - Migrate Kedro-UI buttons to Kedro-viz as Kedro-UI is now deprecated. (#716) - Add a Husky pre-push hook. (#723) +- Create a `version` GraphQL query to get versions of Kedro-Viz. (#727) # Release 4.3.1 diff --git a/src/apollo/schema.graphql b/src/apollo/schema.graphql index d71c08bf43..1ba6a73571 100644 --- a/src/apollo/schema.graphql +++ b/src/apollo/schema.graphql @@ -6,10 +6,10 @@ type Mutation { } type Query { + version: Version! runsList: [Run!]! runMetadata(runIds: [ID!]!): [Run!]! runTrackingData(runIds: [ID!]!, showDiff: Boolean = false): [TrackingDataset!]! - version: Version! } type Run { From 5ed19967e5ec8235be9bc5ea8dbec515ef535083 Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Thu, 3 Feb 2022 11:36:35 +0000 Subject: [PATCH 06/12] add tests; update order of schema; change cli variable names to match version endpoint Signed-off-by: Tynan DeBold --- package/kedro_viz/api/graphql.py | 34 +++++++++++-------- package/kedro_viz/launchers/cli.py | 6 ++-- .../test_api/test_graphql/test_queries.py | 14 ++++++++ package/tests/test_launchers/test_cli.py | 6 ++-- src/apollo/schema.graphql | 16 ++++----- 5 files changed, 48 insertions(+), 28 deletions(-) diff --git a/package/kedro_viz/api/graphql.py b/package/kedro_viz/api/graphql.py index 910ca74638..7c343e925e 100644 --- a/package/kedro_viz/api/graphql.py +++ b/package/kedro_viz/api/graphql.py @@ -71,15 +71,15 @@ def format_run( user_run_details.notes if user_run_details and user_run_details.notes else "" ) run = Run( - id=ID(run_id), author="", + bookmark=bookmark, gitBranch=git_data.get("branch") if git_data else None, gitSha=git_data.get("commit_sha") if git_data else None, - bookmark=bookmark, - title=title, + id=ID(run_id), notes=notes, - timestamp=run_blob["session_id"], runCommand=run_blob["cli"]["command_path"], + timestamp=run_blob["session_id"], + title=title, ) return run @@ -259,24 +259,24 @@ def get_run_tracking_data( class Run: """Run object format""" - id: ID - title: str - timestamp: str author: Optional[str] + bookmark: Optional[bool] gitBranch: Optional[str] gitSha: Optional[str] - bookmark: Optional[bool] + id: ID notes: Optional[str] runCommand: Optional[str] + timestamp: str + title: str @strawberry.type class TrackingDataset: """TrackingDataset object to structure tracking data for a Run.""" + data: Optional[JSONObject] datasetName: Optional[str] datasetType: Optional[str] - data: Optional[JSONObject] @strawberry.type @@ -315,9 +315,14 @@ class Query: @strawberry.field def run_metadata(self, run_ids: List[ID]) -> List[Run]: - """Query to get data for specific runs from the session store""" + """Query to get data for specific run metadata from the session store""" return get_runs(run_ids) + @strawberry.field + def runs_list(self) -> List[Run]: + """Query to get data for all the runs from the session store""" + return get_all_runs() + @strawberry.field def run_tracking_data( self, run_ids: List[ID], show_diff: Optional[bool] = False @@ -325,9 +330,10 @@ def run_tracking_data( """Query to get data for specific runs from the session store""" return get_run_tracking_data(run_ids, show_diff) - version: Version = strawberry.field(resolver=get_version) - - runs_list: List[Run] = strawberry.field(resolver=get_all_runs) + @strawberry.field + def version(self) -> Version: + """Query to get Kedro-Viz version""" + return get_version() schema = strawberry.Schema(query=Query, subscription=Subscription) @@ -338,8 +344,8 @@ class RunInput: """Run input to update bookmark, title and notes""" bookmark: Optional[bool] = None - title: Optional[str] = None notes: Optional[str] = None + title: Optional[str] = None @strawberry.type diff --git a/package/kedro_viz/launchers/cli.py b/package/kedro_viz/launchers/cli.py index b01cfda115..6d34089f7c 100644 --- a/package/kedro_viz/launchers/cli.py +++ b/package/kedro_viz/launchers/cli.py @@ -74,14 +74,14 @@ def commands(): ) def viz(host, port, browser, load_file, save_file, pipeline, env, autoreload): """Visualise a Kedro pipeline using Kedro viz.""" - current_version = VersionInfo.parse(__version__) + installed_version = VersionInfo.parse(__version__) latest_version = get_latest_version() - if latest_version is not None and current_version < latest_version: + if latest_version is not None and installed_version < latest_version: click.echo( click.style( "WARNING: You are using an old version of Kedro Viz. " - f"You are using version {current_version}; " + f"You are using version {installed_version}; " f"however, version {latest_version} is now available.\n" "You should consider upgrading via the `pip install -U kedro-viz` command.\n" "You can view the complete changelog at " diff --git a/package/tests/test_api/test_graphql/test_queries.py b/package/tests/test_api/test_graphql/test_queries.py index 851bb6addc..90c88ec1bc 100644 --- a/package/tests/test_api/test_graphql/test_queries.py +++ b/package/tests/test_api/test_graphql/test_queries.py @@ -1,5 +1,8 @@ import pytest +from kedro_viz import __version__ +from kedro_viz.integrations.pypi import get_latest_version + class TestQueryNoSessionStore: def test_graphql_run_list_endpoint(self, client): @@ -55,6 +58,17 @@ def test_graphql_runs_metadata_endpoint(self, example_run_ids, client): "data": {"runMetadata": [{"id": example_run_ids[0], "bookmark": True}]} } + def test_graphql_version_endpoint(self, client): + response = client.post( + "/graphql", + json={"query": "{{version {{installed latest}}}}"}, + ) + assert response.json() == { + "data": { + "version": {"installed": __version__, "latest": get_latest_version()} + } + } + def test_run_tracking_data_query( self, example_run_ids, diff --git a/package/tests/test_launchers/test_cli.py b/package/tests/test_launchers/test_cli.py index d0b77f3ba2..b18fed78ef 100644 --- a/package/tests/test_launchers/test_cli.py +++ b/package/tests/test_launchers/test_cli.py @@ -62,8 +62,8 @@ def test_kedro_viz_command_run_server(command_options, run_server_args, mocker): def test_kedro_viz_command_should_log_outdated_version(mocker, mock_http_response): - current_version = VersionInfo.parse(__version__) - mock_version = f"{current_version.major + 1}.0.0" + installed_version = VersionInfo.parse(__version__) + mock_version = f"{installed_version.major + 1}.0.0" requests_get = mocker.patch("requests.get") requests_get.return_value = mock_http_response( data={"info": {"version": mock_version}} @@ -77,7 +77,7 @@ def test_kedro_viz_command_should_log_outdated_version(mocker, mock_http_respons mock_click_echo.assert_called_once_with( "\x1b[33mWARNING: You are using an old version of Kedro Viz. " - f"You are using version {current_version}; " + f"You are using version {installed_version}; " f"however, version {mock_version} is now available.\n" "You should consider upgrading via the `pip install -U kedro-viz` command.\n" "You can view the complete changelog at " diff --git a/src/apollo/schema.graphql b/src/apollo/schema.graphql index 1ba6a73571..263f3f598d 100644 --- a/src/apollo/schema.graphql +++ b/src/apollo/schema.graphql @@ -6,28 +6,28 @@ type Mutation { } type Query { - version: Version! - runsList: [Run!]! runMetadata(runIds: [ID!]!): [Run!]! + runsList: [Run!]! runTrackingData(runIds: [ID!]!, showDiff: Boolean = false): [TrackingDataset!]! + version: Version! } type Run { - id: ID! - title: String! - timestamp: String! author: String + bookmark: Boolean gitBranch: String gitSha: String - bookmark: Boolean + id: ID! notes: String runCommand: String + timestamp: String! + title: String! } input RunInput { bookmark: Boolean = null - title: String = null notes: String = null + title: String = null } type Subscription { @@ -35,9 +35,9 @@ type Subscription { } type TrackingDataset { + data: JSONObject datasetName: String datasetType: String - data: JSONObject } type UpdateRunDetailsFailure { From 41044db055a7fd14b3e654bfe7ffe653b3e80b0f Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Thu, 3 Feb 2022 11:52:31 +0000 Subject: [PATCH 07/12] fix failing test Signed-off-by: Tynan DeBold --- package/tests/test_api/test_graphql/test_queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/tests/test_api/test_graphql/test_queries.py b/package/tests/test_api/test_graphql/test_queries.py index 90c88ec1bc..063744f4b4 100644 --- a/package/tests/test_api/test_graphql/test_queries.py +++ b/package/tests/test_api/test_graphql/test_queries.py @@ -61,7 +61,7 @@ def test_graphql_runs_metadata_endpoint(self, example_run_ids, client): def test_graphql_version_endpoint(self, client): response = client.post( "/graphql", - json={"query": "{{version {{installed latest}}}}"}, + json={"query": "{version {installed latest}}"}, ) assert response.json() == { "data": { From 900ccf77603e120586c280f8124d3f1153a79ecb Mon Sep 17 00:00:00 2001 From: Tynan DeBold Date: Thu, 3 Feb 2022 15:29:39 +0000 Subject: [PATCH 08/12] in process of updating tests Signed-off-by: Tynan DeBold --- package/kedro_viz/api/graphql.py | 12 ++++++++--- .../kedro_viz/integrations/pypi/__init__.py | 10 ++++++++++ package/kedro_viz/launchers/cli.py | 4 ++-- .../test_api/test_graphql/test_queries.py | 20 +++++++++++++++++++ package/tests/test_integrations/test_pypi.py | 11 +++++++++- src/apollo/schema.graphql | 1 + 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/package/kedro_viz/api/graphql.py b/package/kedro_viz/api/graphql.py index 7c343e925e..b632fae29b 100644 --- a/package/kedro_viz/api/graphql.py +++ b/package/kedro_viz/api/graphql.py @@ -21,12 +21,13 @@ import strawberry from fastapi import APIRouter +from semver import VersionInfo from strawberry import ID from strawberry.asgi import GraphQL from kedro_viz import __version__ from kedro_viz.data_access import data_access_manager -from kedro_viz.integrations.pypi import get_latest_version +from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version from kedro_viz.models.experiments_tracking import RunModel, UserRunDetailsModel logger = logging.getLogger(__name__) @@ -126,9 +127,13 @@ def get_version() -> Version: Returns: the currently installed and most-recent released version of Viz. """ + installed_version = VersionInfo.parse(__version__) latest_version = get_latest_version() - version = Version(installed=__version__, latest=latest_version) - return version + return Version( + installed=installed_version, + isOutdated=is_running_outdated_version(installed_version, latest_version), + latest=latest_version or "", + ) def get_all_runs() -> List[Run]: @@ -284,6 +289,7 @@ class Version: """The installed and latest Kedro Viz versions.""" installed: str + isOutdated: bool latest: str diff --git a/package/kedro_viz/integrations/pypi/__init__.py b/package/kedro_viz/integrations/pypi/__init__.py index ef8fe97e6b..c4fd6c316f 100644 --- a/package/kedro_viz/integrations/pypi/__init__.py +++ b/package/kedro_viz/integrations/pypi/__init__.py @@ -6,6 +6,8 @@ import requests from semver import VersionInfo +from kedro_viz import __version__ + # PyPI endpoint to query latest Kedro-Viz version available _PYPI_ENDPOINT = "https://pypi.python.org/pypi/kedro-viz/json" logger = logging.getLogger(__name__) @@ -19,3 +21,11 @@ def get_latest_version() -> VersionInfo: except requests.exceptions.RequestException: return None return VersionInfo.parse(pypi_response["info"]["version"]) + + +def is_running_outdated_version( + installed_version: VersionInfo, latest_version: Optional[VersionInfo] +) -> bool: + """Check if the user is running the latest version of Viz.""" + + return latest_version is not None and installed_version < latest_version diff --git a/package/kedro_viz/launchers/cli.py b/package/kedro_viz/launchers/cli.py index 6d34089f7c..787921c1db 100644 --- a/package/kedro_viz/launchers/cli.py +++ b/package/kedro_viz/launchers/cli.py @@ -10,7 +10,7 @@ from watchgod import RegExpWatcher, run_process from kedro_viz import __version__ -from kedro_viz.integrations.pypi import get_latest_version +from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version from kedro_viz.server import DEFAULT_HOST, DEFAULT_PORT, is_localhost, run_server @@ -77,7 +77,7 @@ def viz(host, port, browser, load_file, save_file, pipeline, env, autoreload): installed_version = VersionInfo.parse(__version__) latest_version = get_latest_version() - if latest_version is not None and installed_version < latest_version: + if is_running_outdated_version(installed_version, latest_version): click.echo( click.style( "WARNING: You are using an old version of Kedro Viz. " diff --git a/package/tests/test_api/test_graphql/test_queries.py b/package/tests/test_api/test_graphql/test_queries.py index 063744f4b4..0a3ecb1942 100644 --- a/package/tests/test_api/test_graphql/test_queries.py +++ b/package/tests/test_api/test_graphql/test_queries.py @@ -1,4 +1,5 @@ import pytest +from semver import VersionInfo from kedro_viz import __version__ from kedro_viz.integrations.pypi import get_latest_version @@ -129,3 +130,22 @@ def test_run_tracking_data_query( } } assert response.json() == expected_response + + +class TestVersionQuery: + def test_graphql_version_endpoint(self, client, mocker): + mocker.patch("kedro_viz.integrations.pypi.get_latest_version", + return_value=VersionInfo.parse("1.0.0")) + response = client.post( + "/graphql", + json={"query": "{version {installed isOutdated latest}}"}, + ) + assert response.json() == { + "data": { + "version": { + "installed": __version__, + "isOutdated": True, + "latest": "1.0.0", + } + } + } diff --git a/package/tests/test_integrations/test_pypi.py b/package/tests/test_integrations/test_pypi.py index 6b8753c441..59dc523b4f 100644 --- a/package/tests/test_integrations/test_pypi.py +++ b/package/tests/test_integrations/test_pypi.py @@ -1,6 +1,7 @@ +import pytest from semver import VersionInfo -from kedro_viz.integrations.pypi import get_latest_version +from kedro_viz.integrations.pypi import get_latest_version, is_running_outdated_version def test_get_latest_version(mocker, mock_http_response): @@ -10,3 +11,11 @@ def test_get_latest_version(mocker, mock_http_response): data={"info": {"version": mock_version}} ) assert get_latest_version() == VersionInfo.parse(mock_version) + + +@pytest.mark.parametrize( + "installed_version, latest_version, is_outdated", + [("1.0.0", "1.2.3", True), ("1.2.3", "1.0.0", False), ("1.0.0", None, False)], +) +def test_is_running_outdated_version(installed_version, latest_version, is_outdated): + assert is_running_outdated_version(installed_version, latest_version) == is_outdated diff --git a/src/apollo/schema.graphql b/src/apollo/schema.graphql index 263f3f598d..12ff9659f0 100644 --- a/src/apollo/schema.graphql +++ b/src/apollo/schema.graphql @@ -53,5 +53,6 @@ type UpdateRunDetailsSuccess { type Version { installed: String! + isOutdated: Boolean! latest: String! } From 45cae05e5a0076c4c2833cbc6c9aa4447cb569d4 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Thu, 3 Feb 2022 15:46:20 +0000 Subject: [PATCH 09/12] Fix types in test Signed-off-by: Antony Milne --- package/tests/test_integrations/test_pypi.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package/tests/test_integrations/test_pypi.py b/package/tests/test_integrations/test_pypi.py index 59dc523b4f..398421e64b 100644 --- a/package/tests/test_integrations/test_pypi.py +++ b/package/tests/test_integrations/test_pypi.py @@ -18,4 +18,7 @@ def test_get_latest_version(mocker, mock_http_response): [("1.0.0", "1.2.3", True), ("1.2.3", "1.0.0", False), ("1.0.0", None, False)], ) def test_is_running_outdated_version(installed_version, latest_version, is_outdated): + installed_version = VersionInfo.parse(installed_version) + if latest_version is not None: + latest_version = VersionInfo.parse(latest_version) assert is_running_outdated_version(installed_version, latest_version) == is_outdated From b528387a8a0aa61fd2918805d8cd2b55c0ba573f Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Thu, 3 Feb 2022 16:00:29 +0000 Subject: [PATCH 10/12] Fix mocking Signed-off-by: Antony Milne --- package/tests/test_api/test_graphql/test_queries.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/package/tests/test_api/test_graphql/test_queries.py b/package/tests/test_api/test_graphql/test_queries.py index 0a3ecb1942..7bca17295e 100644 --- a/package/tests/test_api/test_graphql/test_queries.py +++ b/package/tests/test_api/test_graphql/test_queries.py @@ -132,10 +132,12 @@ def test_run_tracking_data_query( assert response.json() == expected_response -class TestVersionQuery: +class TestQueryVersion: def test_graphql_version_endpoint(self, client, mocker): - mocker.patch("kedro_viz.integrations.pypi.get_latest_version", - return_value=VersionInfo.parse("1.0.0")) + mocker.patch( + "kedro_viz.api.graphql.get_latest_version", + return_value=VersionInfo.parse("1.0.0"), + ) response = client.post( "/graphql", json={"query": "{version {installed isOutdated latest}}"}, @@ -144,7 +146,7 @@ def test_graphql_version_endpoint(self, client, mocker): "data": { "version": { "installed": __version__, - "isOutdated": True, + "isOutdated": False, "latest": "1.0.0", } } From 1318c491a9fbec90ff76a2b1d3c132d4f25c194a Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Thu, 3 Feb 2022 16:13:12 +0000 Subject: [PATCH 11/12] Remove old test Signed-off-by: Antony Milne --- package/tests/test_api/test_graphql/test_queries.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/package/tests/test_api/test_graphql/test_queries.py b/package/tests/test_api/test_graphql/test_queries.py index 7bca17295e..aaa9d977df 100644 --- a/package/tests/test_api/test_graphql/test_queries.py +++ b/package/tests/test_api/test_graphql/test_queries.py @@ -59,17 +59,6 @@ def test_graphql_runs_metadata_endpoint(self, example_run_ids, client): "data": {"runMetadata": [{"id": example_run_ids[0], "bookmark": True}]} } - def test_graphql_version_endpoint(self, client): - response = client.post( - "/graphql", - json={"query": "{version {installed latest}}"}, - ) - assert response.json() == { - "data": { - "version": {"installed": __version__, "latest": get_latest_version()} - } - } - def test_run_tracking_data_query( self, example_run_ids, From 988a75a84eafcb93c404fdf53b40ba4fd1df6638 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Thu, 3 Feb 2022 16:25:20 +0000 Subject: [PATCH 12/12] Lint Signed-off-by: Antony Milne --- package/tests/test_api/test_graphql/test_queries.py | 1 - 1 file changed, 1 deletion(-) diff --git a/package/tests/test_api/test_graphql/test_queries.py b/package/tests/test_api/test_graphql/test_queries.py index aaa9d977df..e1821b7a10 100644 --- a/package/tests/test_api/test_graphql/test_queries.py +++ b/package/tests/test_api/test_graphql/test_queries.py @@ -2,7 +2,6 @@ from semver import VersionInfo from kedro_viz import __version__ -from kedro_viz.integrations.pypi import get_latest_version class TestQueryNoSessionStore: