Skip to content

Commit

Permalink
feat(validate): add script for local testing and minor wording change
Browse files Browse the repository at this point in the history
  • Loading branch information
hugotiburtino committed Oct 29, 2024
1 parent 8cda6c5 commit ae2ba94
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lint = "pylint *.py"
format = "black ."
format_check = "black . --check"
test = "pytest -vv tests/"
validate_local = "pipenv run env USE_LOCAL_API=1 python download_metadata.py public/serlo-metadata.json && pipenv run python validate_nodes.py"

[requires]
python_version = "3.11"
7 changes: 5 additions & 2 deletions serlo_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport

import os

def fetch_metadata(first=500, after=None) -> Dict[str, Any]:
query = graphql(
Expand Down Expand Up @@ -41,7 +41,10 @@ def fetch_publisher() -> Dict[str, Any]:


def execute(query: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
transport = RequestsHTTPTransport(url="https://api.serlo.org/graphql")
api_url = "https://api.serlo.org/graphql"
if os.getenv("USE_LOCAL_API"):
api_url = "http://localhost:3001/graphql"
transport = RequestsHTTPTransport(url=api_url)
client = Client(transport=transport, fetch_schema_from_transport=True)
graphql_query = gql(query)
return client.execute(graphql_query, variable_values=params)
Expand Down
2 changes: 1 addition & 1 deletion validate_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
except fastjsonschema.JsonSchemaException as e:
failures.append(
# pylint: disable=E1101
f"Failed at {learning_resource['id']} . Error: {e}, instead of {e.value}"
f"Failed at {learning_resource['id']} Error: {e}, instead of {e.value}"
# pylint: enable=E1101
)

Expand Down

0 comments on commit ae2ba94

Please sign in to comment.