From fd72c1d37631ccb0af9ae38c3e3181b2e1d28092 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Mon, 25 Oct 2021 13:08:19 +0100 Subject: [PATCH 01/16] Added new graphql request (no backwards compatibility from here) --- README.generated.md | 5 + docs/AnyOfGraphqlQueryVariables.md | 8 + docs/GraphqlData.md | 1 + docs/GraphqlProblemsetQuestionList.md | 10 + docs/GraphqlQuery.md | 2 +- .../GraphqlQueryGetQuestionDetailVariables.md | 9 + ...hqlQueryProblemsetQuestionListVariables.md | 12 + ...blemsetQuestionListVariablesFilterInput.md | 13 + docs/GraphqlQueryVariables.md | 1 - example.py | 6 +- leetcode/__init__.py | 13 + leetcode/models/__init__.py | 13 + .../models/any_of_graphql_query_variables.py | 87 +++++++ leetcode/models/graphql_data.py | 44 +++- .../graphql_problemset_question_list.py | 135 +++++++++++ leetcode/models/graphql_query.py | 6 +- ...hql_query_get_question_detail_variables.py | 111 +++++++++ ...uery_problemset_question_list_variables.py | 195 +++++++++++++++ ...et_question_list_variables_filter_input.py | 225 ++++++++++++++++++ leetcode/models/graphql_query_variables.py | 30 +-- leetcode/models/graphql_question_solution.py | 4 +- leetcode/models/graphql_user.py | 4 +- setup.py | 3 +- test/test_any_of_graphql_query_variables.py | 41 ++++ ...any_of_graphql_question_detail_solution.py | 2 +- test/test_graphql_data.py | 2 +- test/test_graphql_problemset_question_list.py | 41 ++++ ...hql_query_get_question_detail_variables.py | 41 ++++ ...uery_problemset_question_list_variables.py | 41 ++++ ...et_question_list_variables_filter_input.py | 41 ++++ test/test_graphql_question_code_snippet.py | 2 +- test/test_graphql_question_contributor.py | 2 +- test/test_graphql_question_solution.py | 2 +- test/test_graphql_question_topic_tag.py | 2 +- ...est_graphql_request_get_question_detail.py | 10 +- ...raphql_request_problemset_question_list.py | 210 ++++++++++++++++ test/test_graphql_request_user.py | 4 +- test/test_graphql_user.py | 2 +- 38 files changed, 1327 insertions(+), 53 deletions(-) create mode 100644 docs/AnyOfGraphqlQueryVariables.md create mode 100644 docs/GraphqlProblemsetQuestionList.md create mode 100644 docs/GraphqlQueryGetQuestionDetailVariables.md create mode 100644 docs/GraphqlQueryProblemsetQuestionListVariables.md create mode 100644 docs/GraphqlQueryProblemsetQuestionListVariablesFilterInput.md create mode 100644 leetcode/models/any_of_graphql_query_variables.py create mode 100644 leetcode/models/graphql_problemset_question_list.py create mode 100644 leetcode/models/graphql_query_get_question_detail_variables.py create mode 100644 leetcode/models/graphql_query_problemset_question_list_variables.py create mode 100644 leetcode/models/graphql_query_problemset_question_list_variables_filter_input.py create mode 100644 test/test_any_of_graphql_query_variables.py create mode 100644 test/test_graphql_problemset_question_list.py create mode 100644 test/test_graphql_query_get_question_detail_variables.py create mode 100644 test/test_graphql_query_problemset_question_list_variables.py create mode 100644 test/test_graphql_query_problemset_question_list_variables_filter_input.py create mode 100644 test/test_graphql_request_problemset_question_list.py diff --git a/README.generated.md b/README.generated.md index 1e09d88..248de56 100644 --- a/README.generated.md +++ b/README.generated.md @@ -223,11 +223,16 @@ Class | Method | HTTP request | Description ## Documentation For Models + - [AnyOfGraphqlQueryVariables](docs/AnyOfGraphqlQueryVariables.md) - [AnyOfGraphqlQuestionDetailSolution](docs/AnyOfGraphqlQuestionDetailSolution.md) - [BaseSubmissionResult](docs/BaseSubmissionResult.md) - [Difficulty](docs/Difficulty.md) - [GraphqlData](docs/GraphqlData.md) + - [GraphqlProblemsetQuestionList](docs/GraphqlProblemsetQuestionList.md) - [GraphqlQuery](docs/GraphqlQuery.md) + - [GraphqlQueryGetQuestionDetailVariables](docs/GraphqlQueryGetQuestionDetailVariables.md) + - [GraphqlQueryProblemsetQuestionListVariables](docs/GraphqlQueryProblemsetQuestionListVariables.md) + - [GraphqlQueryProblemsetQuestionListVariablesFilterInput](docs/GraphqlQueryProblemsetQuestionListVariablesFilterInput.md) - [GraphqlQueryVariables](docs/GraphqlQueryVariables.md) - [GraphqlQuestionCodeSnippet](docs/GraphqlQuestionCodeSnippet.md) - [GraphqlQuestionContributor](docs/GraphqlQuestionContributor.md) diff --git a/docs/AnyOfGraphqlQueryVariables.md b/docs/AnyOfGraphqlQueryVariables.md new file mode 100644 index 0000000..e310fe2 --- /dev/null +++ b/docs/AnyOfGraphqlQueryVariables.md @@ -0,0 +1,8 @@ +# AnyOfGraphqlQueryVariables + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/docs/GraphqlData.md b/docs/GraphqlData.md index a95ab84..549dc26 100644 --- a/docs/GraphqlData.md +++ b/docs/GraphqlData.md @@ -5,6 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **question** | [**GraphqlQuestionDetail**](GraphqlQuestionDetail.md) | | [optional] **user** | [**GraphqlUser**](GraphqlUser.md) | | [optional] +**problemset_question_list** | [**GraphqlProblemsetQuestionList**](GraphqlProblemsetQuestionList.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/docs/GraphqlProblemsetQuestionList.md b/docs/GraphqlProblemsetQuestionList.md new file mode 100644 index 0000000..5253478 --- /dev/null +++ b/docs/GraphqlProblemsetQuestionList.md @@ -0,0 +1,10 @@ +# GraphqlProblemsetQuestionList + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**total** | **int** | | [optional] +**questions** | [**list[GraphqlQuestionDetail]**](GraphqlQuestionDetail.md) | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/docs/GraphqlQuery.md b/docs/GraphqlQuery.md index 29a35b3..b0bf2f1 100644 --- a/docs/GraphqlQuery.md +++ b/docs/GraphqlQuery.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **query** | **str** | | -**variables** | [**GraphqlQueryVariables**](GraphqlQueryVariables.md) | | +**variables** | [**AnyOfGraphqlQueryVariables**](AnyOfGraphqlQueryVariables.md) | | **operation_name** | **str** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/docs/GraphqlQueryGetQuestionDetailVariables.md b/docs/GraphqlQueryGetQuestionDetailVariables.md new file mode 100644 index 0000000..b56e29f --- /dev/null +++ b/docs/GraphqlQueryGetQuestionDetailVariables.md @@ -0,0 +1,9 @@ +# GraphqlQueryGetQuestionDetailVariables + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**title_slug** | **str** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/docs/GraphqlQueryProblemsetQuestionListVariables.md b/docs/GraphqlQueryProblemsetQuestionListVariables.md new file mode 100644 index 0000000..ee50a54 --- /dev/null +++ b/docs/GraphqlQueryProblemsetQuestionListVariables.md @@ -0,0 +1,12 @@ +# GraphqlQueryProblemsetQuestionListVariables + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**category_slug** | **str** | | [optional] +**limit** | **int** | | [optional] +**skip** | **int** | | [optional] +**filters** | [**GraphqlQueryProblemsetQuestionListVariablesFilterInput**](GraphqlQueryProblemsetQuestionListVariablesFilterInput.md) | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/docs/GraphqlQueryProblemsetQuestionListVariablesFilterInput.md b/docs/GraphqlQueryProblemsetQuestionListVariablesFilterInput.md new file mode 100644 index 0000000..ec69410 --- /dev/null +++ b/docs/GraphqlQueryProblemsetQuestionListVariablesFilterInput.md @@ -0,0 +1,13 @@ +# GraphqlQueryProblemsetQuestionListVariablesFilterInput + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**tags** | **list[str]** | | [optional] +**difficulty** | **str** | | [optional] +**status** | **str** | | [optional] +**list_id** | **str** | | [optional] +**premium_only** | **bool** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/docs/GraphqlQueryVariables.md b/docs/GraphqlQueryVariables.md index cd77fc5..bd9a674 100644 --- a/docs/GraphqlQueryVariables.md +++ b/docs/GraphqlQueryVariables.md @@ -3,7 +3,6 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**title_slug** | **str** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/example.py b/example.py index 3a29181..8d38d7d 100644 --- a/example.py +++ b/example.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import sys from time import sleep @@ -10,9 +12,9 @@ # NOTE: cookies var is just a dict with `csrftoken` and `LEETCODE_SESSION` # fields which contain corresponding cookies from web browser -leetcode_session = os.environ["LEETCODE_SESSION_ID"] +leetcode_session: str = os.environ["LEETCODE_SESSION_ID"] -csrf_token = leetcode.auth.get_csrf_cookie(leetcode_session) +csrf_token: str = leetcode.auth.get_csrf_cookie(leetcode_session) configuration.api_key["x-csrftoken"] = csrf_token configuration.api_key["csrftoken"] = csrf_token diff --git a/leetcode/__init__.py b/leetcode/__init__.py index 0bd925d..707af62 100644 --- a/leetcode/__init__.py +++ b/leetcode/__init__.py @@ -22,13 +22,26 @@ from leetcode.configuration import Configuration # import models into sdk package +from leetcode.models.any_of_graphql_query_variables import AnyOfGraphqlQueryVariables from leetcode.models.any_of_graphql_question_detail_solution import ( AnyOfGraphqlQuestionDetailSolution, ) from leetcode.models.base_submission_result import BaseSubmissionResult from leetcode.models.difficulty import Difficulty from leetcode.models.graphql_data import GraphqlData +from leetcode.models.graphql_problemset_question_list import ( + GraphqlProblemsetQuestionList, +) from leetcode.models.graphql_query import GraphqlQuery +from leetcode.models.graphql_query_get_question_detail_variables import ( + GraphqlQueryGetQuestionDetailVariables, +) +from leetcode.models.graphql_query_problemset_question_list_variables import ( + GraphqlQueryProblemsetQuestionListVariables, +) +from leetcode.models.graphql_query_problemset_question_list_variables_filter_input import ( + GraphqlQueryProblemsetQuestionListVariablesFilterInput, +) from leetcode.models.graphql_query_variables import GraphqlQueryVariables from leetcode.models.graphql_question_code_snippet import GraphqlQuestionCodeSnippet from leetcode.models.graphql_question_contributor import GraphqlQuestionContributor diff --git a/leetcode/models/__init__.py b/leetcode/models/__init__.py index a1cd290..de07276 100644 --- a/leetcode/models/__init__.py +++ b/leetcode/models/__init__.py @@ -14,13 +14,26 @@ from __future__ import absolute_import # import models into model package +from leetcode.models.any_of_graphql_query_variables import AnyOfGraphqlQueryVariables from leetcode.models.any_of_graphql_question_detail_solution import ( AnyOfGraphqlQuestionDetailSolution, ) from leetcode.models.base_submission_result import BaseSubmissionResult from leetcode.models.difficulty import Difficulty from leetcode.models.graphql_data import GraphqlData +from leetcode.models.graphql_problemset_question_list import ( + GraphqlProblemsetQuestionList, +) from leetcode.models.graphql_query import GraphqlQuery +from leetcode.models.graphql_query_get_question_detail_variables import ( + GraphqlQueryGetQuestionDetailVariables, +) +from leetcode.models.graphql_query_problemset_question_list_variables import ( + GraphqlQueryProblemsetQuestionListVariables, +) +from leetcode.models.graphql_query_problemset_question_list_variables_filter_input import ( + GraphqlQueryProblemsetQuestionListVariablesFilterInput, +) from leetcode.models.graphql_query_variables import GraphqlQueryVariables from leetcode.models.graphql_question_code_snippet import GraphqlQuestionCodeSnippet from leetcode.models.graphql_question_contributor import GraphqlQuestionContributor diff --git a/leetcode/models/any_of_graphql_query_variables.py b/leetcode/models/any_of_graphql_query_variables.py new file mode 100644 index 0000000..2fcc4d9 --- /dev/null +++ b/leetcode/models/any_of_graphql_query_variables.py @@ -0,0 +1,87 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" +from __future__ import annotations + +import pprint +import re # noqa: F401 + +import six + + +class AnyOfGraphqlQueryVariables(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = {} + + attribute_map = {} + + def __init__(self) -> None: # noqa: E501 + """AnyOfGraphqlQueryVariables - a model defined in Swagger""" # noqa: E501 + self.discriminator = None + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + if issubclass(AnyOfGraphqlQueryVariables, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self) -> str: + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self) -> str: + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other: AnyOfGraphqlQueryVariables) -> bool: + """Returns true if both objects are equal""" + if not isinstance(other, AnyOfGraphqlQueryVariables): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other) -> bool: + """Returns true if both objects are not equal""" + return not self == other diff --git a/leetcode/models/graphql_data.py b/leetcode/models/graphql_data.py index 3562cbe..5f8b66a 100644 --- a/leetcode/models/graphql_data.py +++ b/leetcode/models/graphql_data.py @@ -30,19 +30,32 @@ class GraphqlData(object): attribute_map (dict): The key is attribute name and the value is json key in definition. """ - swagger_types = {"question": "GraphqlQuestionDetail", "user": "GraphqlUser"} - - attribute_map = {"question": "question", "user": "user"} - - def __init__(self, question=None, user=None) -> None: # noqa: E501 + swagger_types = { + "question": "GraphqlQuestionDetail", + "user": "GraphqlUser", + "problemset_question_list": "GraphqlProblemsetQuestionList", + } + + attribute_map = { + "question": "question", + "user": "user", + "problemset_question_list": "problemsetQuestionList", + } + + def __init__( + self, question=None, user=None, problemset_question_list=None + ) -> None: # noqa: E501 """GraphqlData - a model defined in Swagger""" # noqa: E501 self._question = None self._user = None + self._problemset_question_list = None self.discriminator = None if question is not None: self.question = question if user is not None: self.user = user + if problemset_question_list is not None: + self.problemset_question_list = problemset_question_list @property def question(self): @@ -86,6 +99,27 @@ def user(self, user): self._user = user + @property + def problemset_question_list(self): + """Gets the problemset_question_list of this GraphqlData. # noqa: E501 + + + :return: The problemset_question_list of this GraphqlData. # noqa: E501 + :rtype: GraphqlProblemsetQuestionList + """ + return self._problemset_question_list + + @problemset_question_list.setter + def problemset_question_list(self, problemset_question_list): + """Sets the problemset_question_list of this GraphqlData. + + + :param problemset_question_list: The problemset_question_list of this GraphqlData. # noqa: E501 + :type: GraphqlProblemsetQuestionList + """ + + self._problemset_question_list = problemset_question_list + def to_dict(self): """Returns the model properties as a dict""" result = {} diff --git a/leetcode/models/graphql_problemset_question_list.py b/leetcode/models/graphql_problemset_question_list.py new file mode 100644 index 0000000..890b1e1 --- /dev/null +++ b/leetcode/models/graphql_problemset_question_list.py @@ -0,0 +1,135 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" +from __future__ import annotations + +import pprint +import re # noqa: F401 + +import six + + +class GraphqlProblemsetQuestionList(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = {"total": "int", "questions": "list[GraphqlQuestionDetail]"} + + attribute_map = {"total": "total", "questions": "questions"} + + def __init__(self, total=None, questions=None) -> None: # noqa: E501 + """GraphqlProblemsetQuestionList - a model defined in Swagger""" # noqa: E501 + self._total = None + self._questions = None + self.discriminator = None + if total is not None: + self.total = total + if questions is not None: + self.questions = questions + + @property + def total(self): + """Gets the total of this GraphqlProblemsetQuestionList. # noqa: E501 + + + :return: The total of this GraphqlProblemsetQuestionList. # noqa: E501 + :rtype: int + """ + return self._total + + @total.setter + def total(self, total): + """Sets the total of this GraphqlProblemsetQuestionList. + + + :param total: The total of this GraphqlProblemsetQuestionList. # noqa: E501 + :type: int + """ + + self._total = total + + @property + def questions(self): + """Gets the questions of this GraphqlProblemsetQuestionList. # noqa: E501 + + + :return: The questions of this GraphqlProblemsetQuestionList. # noqa: E501 + :rtype: list[GraphqlQuestionDetail] + """ + return self._questions + + @questions.setter + def questions(self, questions): + """Sets the questions of this GraphqlProblemsetQuestionList. + + + :param questions: The questions of this GraphqlProblemsetQuestionList. # noqa: E501 + :type: list[GraphqlQuestionDetail] + """ + + self._questions = questions + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + if issubclass(GraphqlProblemsetQuestionList, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self) -> str: + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self) -> str: + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other: GraphqlProblemsetQuestionList) -> bool: + """Returns true if both objects are equal""" + if not isinstance(other, GraphqlProblemsetQuestionList): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other) -> bool: + """Returns true if both objects are not equal""" + return not self == other diff --git a/leetcode/models/graphql_query.py b/leetcode/models/graphql_query.py index 6d61ac1..c1b0fff 100644 --- a/leetcode/models/graphql_query.py +++ b/leetcode/models/graphql_query.py @@ -31,7 +31,7 @@ class GraphqlQuery(object): """ swagger_types = { "query": "str", - "variables": "GraphqlQueryVariables", + "variables": "AnyOfGraphqlQueryVariables", "operation_name": "str", } @@ -83,7 +83,7 @@ def variables(self): :return: The variables of this GraphqlQuery. # noqa: E501 - :rtype: GraphqlQueryVariables + :rtype: AnyOfGraphqlQueryVariables """ return self._variables @@ -93,7 +93,7 @@ def variables(self, variables): :param variables: The variables of this GraphqlQuery. # noqa: E501 - :type: GraphqlQueryVariables + :type: AnyOfGraphqlQueryVariables """ if variables is None: raise ValueError( diff --git a/leetcode/models/graphql_query_get_question_detail_variables.py b/leetcode/models/graphql_query_get_question_detail_variables.py new file mode 100644 index 0000000..015c4d7 --- /dev/null +++ b/leetcode/models/graphql_query_get_question_detail_variables.py @@ -0,0 +1,111 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" +from __future__ import annotations + +import pprint +import re # noqa: F401 + +import six + + +class GraphqlQueryGetQuestionDetailVariables(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = {"title_slug": "str"} + + attribute_map = {"title_slug": "titleSlug"} + + def __init__(self, title_slug=None) -> None: # noqa: E501 + """GraphqlQueryGetQuestionDetailVariables - a model defined in Swagger""" # noqa: E501 + self._title_slug = None + self.discriminator = None + if title_slug is not None: + self.title_slug = title_slug + + @property + def title_slug(self): + """Gets the title_slug of this GraphqlQueryGetQuestionDetailVariables. # noqa: E501 + + + :return: The title_slug of this GraphqlQueryGetQuestionDetailVariables. # noqa: E501 + :rtype: str + """ + return self._title_slug + + @title_slug.setter + def title_slug(self, title_slug): + """Sets the title_slug of this GraphqlQueryGetQuestionDetailVariables. + + + :param title_slug: The title_slug of this GraphqlQueryGetQuestionDetailVariables. # noqa: E501 + :type: str + """ + + self._title_slug = title_slug + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + if issubclass(GraphqlQueryGetQuestionDetailVariables, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self) -> str: + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self) -> str: + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other: GraphqlQueryGetQuestionDetailVariables) -> bool: + """Returns true if both objects are equal""" + if not isinstance(other, GraphqlQueryGetQuestionDetailVariables): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other) -> bool: + """Returns true if both objects are not equal""" + return not self == other diff --git a/leetcode/models/graphql_query_problemset_question_list_variables.py b/leetcode/models/graphql_query_problemset_question_list_variables.py new file mode 100644 index 0000000..fdd9358 --- /dev/null +++ b/leetcode/models/graphql_query_problemset_question_list_variables.py @@ -0,0 +1,195 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" +from __future__ import annotations + +import pprint +import re # noqa: F401 + +import six + + +class GraphqlQueryProblemsetQuestionListVariables(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + "category_slug": "str", + "limit": "int", + "skip": "int", + "filters": "GraphqlQueryProblemsetQuestionListVariablesFilterInput", + } + + attribute_map = { + "category_slug": "categorySlug", + "limit": "limit", + "skip": "skip", + "filters": "filters", + } + + def __init__( + self, category_slug=None, limit=None, skip=None, filters=None + ) -> None: # noqa: E501 + """GraphqlQueryProblemsetQuestionListVariables - a model defined in Swagger""" # noqa: E501 + self._category_slug = None + self._limit = None + self._skip = None + self._filters = None + self.discriminator = None + if category_slug is not None: + self.category_slug = category_slug + if limit is not None: + self.limit = limit + if skip is not None: + self.skip = skip + if filters is not None: + self.filters = filters + + @property + def category_slug(self): + """Gets the category_slug of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + + + :return: The category_slug of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :rtype: str + """ + return self._category_slug + + @category_slug.setter + def category_slug(self, category_slug): + """Sets the category_slug of this GraphqlQueryProblemsetQuestionListVariables. + + + :param category_slug: The category_slug of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :type: str + """ + + self._category_slug = category_slug + + @property + def limit(self): + """Gets the limit of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + + + :return: The limit of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :rtype: int + """ + return self._limit + + @limit.setter + def limit(self, limit): + """Sets the limit of this GraphqlQueryProblemsetQuestionListVariables. + + + :param limit: The limit of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :type: int + """ + + self._limit = limit + + @property + def skip(self): + """Gets the skip of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + + + :return: The skip of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :rtype: int + """ + return self._skip + + @skip.setter + def skip(self, skip): + """Sets the skip of this GraphqlQueryProblemsetQuestionListVariables. + + + :param skip: The skip of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :type: int + """ + + self._skip = skip + + @property + def filters(self): + """Gets the filters of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + + + :return: The filters of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :rtype: GraphqlQueryProblemsetQuestionListVariablesFilterInput + """ + return self._filters + + @filters.setter + def filters(self, filters): + """Sets the filters of this GraphqlQueryProblemsetQuestionListVariables. + + + :param filters: The filters of this GraphqlQueryProblemsetQuestionListVariables. # noqa: E501 + :type: GraphqlQueryProblemsetQuestionListVariablesFilterInput + """ + + self._filters = filters + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + if issubclass(GraphqlQueryProblemsetQuestionListVariables, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self) -> str: + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self) -> str: + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other: GraphqlQueryProblemsetQuestionListVariables) -> bool: + """Returns true if both objects are equal""" + if not isinstance(other, GraphqlQueryProblemsetQuestionListVariables): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other) -> bool: + """Returns true if both objects are not equal""" + return not self == other diff --git a/leetcode/models/graphql_query_problemset_question_list_variables_filter_input.py b/leetcode/models/graphql_query_problemset_question_list_variables_filter_input.py new file mode 100644 index 0000000..9394bc8 --- /dev/null +++ b/leetcode/models/graphql_query_problemset_question_list_variables_filter_input.py @@ -0,0 +1,225 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" +from __future__ import annotations + +import pprint +import re # noqa: F401 + +import six + + +class GraphqlQueryProblemsetQuestionListVariablesFilterInput(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + "tags": "list[str]", + "difficulty": "str", + "status": "str", + "list_id": "str", + "premium_only": "bool", + } + + attribute_map = { + "tags": "tags", + "difficulty": "difficulty", + "status": "status", + "list_id": "listId", + "premium_only": "premiumOnly", + } + + def __init__( + self, tags=None, difficulty=None, status=None, list_id=None, premium_only=None + ) -> None: # noqa: E501 + """GraphqlQueryProblemsetQuestionListVariablesFilterInput - a model defined in Swagger""" # noqa: E501 + self._tags = None + self._difficulty = None + self._status = None + self._list_id = None + self._premium_only = None + self.discriminator = None + if tags is not None: + self.tags = tags + if difficulty is not None: + self.difficulty = difficulty + if status is not None: + self.status = status + if list_id is not None: + self.list_id = list_id + if premium_only is not None: + self.premium_only = premium_only + + @property + def tags(self): + """Gets the tags of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + + + :return: The tags of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :rtype: list[str] + """ + return self._tags + + @tags.setter + def tags(self, tags): + """Sets the tags of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. + + + :param tags: The tags of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :type: list[str] + """ + + self._tags = tags + + @property + def difficulty(self): + """Gets the difficulty of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + + + :return: The difficulty of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :rtype: str + """ + return self._difficulty + + @difficulty.setter + def difficulty(self, difficulty): + """Sets the difficulty of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. + + + :param difficulty: The difficulty of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :type: str + """ + + self._difficulty = difficulty + + @property + def status(self): + """Gets the status of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + + + :return: The status of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. + + + :param status: The status of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :type: str + """ + + self._status = status + + @property + def list_id(self): + """Gets the list_id of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + + + :return: The list_id of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :rtype: str + """ + return self._list_id + + @list_id.setter + def list_id(self, list_id): + """Sets the list_id of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. + + + :param list_id: The list_id of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :type: str + """ + + self._list_id = list_id + + @property + def premium_only(self): + """Gets the premium_only of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + + + :return: The premium_only of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :rtype: bool + """ + return self._premium_only + + @premium_only.setter + def premium_only(self, premium_only): + """Sets the premium_only of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. + + + :param premium_only: The premium_only of this GraphqlQueryProblemsetQuestionListVariablesFilterInput. # noqa: E501 + :type: bool + """ + + self._premium_only = premium_only + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + if issubclass(GraphqlQueryProblemsetQuestionListVariablesFilterInput, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self) -> str: + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self) -> str: + """For `print` and `pprint`""" + return self.to_str() + + def __eq__( + self, other: GraphqlQueryProblemsetQuestionListVariablesFilterInput + ) -> bool: + """Returns true if both objects are equal""" + if not isinstance( + other, GraphqlQueryProblemsetQuestionListVariablesFilterInput + ): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other) -> bool: + """Returns true if both objects are not equal""" + return not self == other diff --git a/leetcode/models/graphql_query_variables.py b/leetcode/models/graphql_query_variables.py index 71ebcf5..7c61a37 100644 --- a/leetcode/models/graphql_query_variables.py +++ b/leetcode/models/graphql_query_variables.py @@ -29,37 +29,13 @@ class GraphqlQueryVariables(object): attribute_map (dict): The key is attribute name and the value is json key in definition. """ - swagger_types = {"title_slug": "str"} + swagger_types = {} - attribute_map = {"title_slug": "titleSlug"} + attribute_map = {} - def __init__(self, title_slug=None): # noqa: E501 + def __init__(self): # noqa: E501 """GraphqlQueryVariables - a model defined in Swagger""" # noqa: E501 - self._title_slug = None self.discriminator = None - if title_slug is not None: - self.title_slug = title_slug - - @property - def title_slug(self): - """Gets the title_slug of this GraphqlQueryVariables. # noqa: E501 - - - :return: The title_slug of this GraphqlQueryVariables. # noqa: E501 - :rtype: str - """ - return self._title_slug - - @title_slug.setter - def title_slug(self, title_slug): - """Sets the title_slug of this GraphqlQueryVariables. - - - :param title_slug: The title_slug of this GraphqlQueryVariables. # noqa: E501 - :type: str - """ - - self._title_slug = title_slug def to_dict(self): """Returns the model properties as a dict""" diff --git a/leetcode/models/graphql_question_solution.py b/leetcode/models/graphql_question_solution.py index 56d9f53..c8089a5 100644 --- a/leetcode/models/graphql_question_solution.py +++ b/leetcode/models/graphql_question_solution.py @@ -38,7 +38,9 @@ class GraphqlQuestionSolution(object): "typename": "__typename", } - def __init__(self, id=None, can_see_detail=None, typename=None) -> None: # noqa: E501 + def __init__( + self, id=None, can_see_detail=None, typename=None + ) -> None: # noqa: E501 """GraphqlQuestionSolution - a model defined in Swagger""" # noqa: E501 self._id = None self._can_see_detail = None diff --git a/leetcode/models/graphql_user.py b/leetcode/models/graphql_user.py index 0c98fd3..6bd0173 100644 --- a/leetcode/models/graphql_user.py +++ b/leetcode/models/graphql_user.py @@ -37,7 +37,9 @@ class GraphqlUser(object): "is_current_user_premium": "isCurrentUserPremium", } - def __init__(self, username=None, is_current_user_premium=None) -> None: # noqa: E501 + def __init__( + self, username=None, is_current_user_premium=None + ) -> None: # noqa: E501 """GraphqlUser - a model defined in Swagger""" # noqa: E501 self._username = None self._is_current_user_premium = None diff --git a/setup.py b/setup.py index a57af48..79bf053 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,11 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ from __future__ import annotations + from setuptools import find_packages, setup # noqa: H301 NAME = "python-leetcode" -VERSION = "1.0.10" +VERSION = "1.1.0" with open("README.md") as readme: DESCRIPTION: str = readme.read() diff --git a/test/test_any_of_graphql_query_variables.py b/test/test_any_of_graphql_query_variables.py new file mode 100644 index 0000000..afcd76e --- /dev/null +++ b/test/test_any_of_graphql_query_variables.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import, annotations + +import unittest + +import leetcode +from leetcode.models.any_of_graphql_query_variables import ( # noqa: E501 + AnyOfGraphqlQueryVariables, +) +from leetcode.rest import ApiException + + +class TestAnyOfGraphqlQueryVariables(unittest.TestCase): + """AnyOfGraphqlQueryVariables unit test stubs""" + + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def testAnyOfGraphqlQueryVariables(self) -> None: + """Test AnyOfGraphqlQueryVariables""" + # FIXME: construct object with mandatory attributes with example values + # model = leetcode.models.any_of_graphql_query_variables.AnyOfGraphqlQueryVariables() # noqa: E501 + pass + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_any_of_graphql_question_detail_solution.py b/test/test_any_of_graphql_question_detail_solution.py index 2b0f0c9..1c6952d 100644 --- a/test/test_any_of_graphql_question_detail_solution.py +++ b/test/test_any_of_graphql_question_detail_solution.py @@ -10,7 +10,7 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ -from __future__ import annotations, absolute_import +from __future__ import absolute_import, annotations import unittest diff --git a/test/test_graphql_data.py b/test/test_graphql_data.py index 35c4ac5..d1dfb3a 100644 --- a/test/test_graphql_data.py +++ b/test/test_graphql_data.py @@ -10,7 +10,7 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ -from __future__ import annotations, absolute_import +from __future__ import absolute_import, annotations import unittest diff --git a/test/test_graphql_problemset_question_list.py b/test/test_graphql_problemset_question_list.py new file mode 100644 index 0000000..ebb882f --- /dev/null +++ b/test/test_graphql_problemset_question_list.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import, annotations + +import unittest + +import leetcode +from leetcode.models.graphql_problemset_question_list import ( # noqa: E501 + GraphqlProblemsetQuestionList, +) +from leetcode.rest import ApiException + + +class TestGraphqlProblemsetQuestionList(unittest.TestCase): + """GraphqlProblemsetQuestionList unit test stubs""" + + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def testGraphqlProblemsetQuestionList(self) -> None: + """Test GraphqlProblemsetQuestionList""" + # FIXME: construct object with mandatory attributes with example values + # model = leetcode.models.graphql_problemset_question_list.GraphqlProblemsetQuestionList() # noqa: E501 + pass + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_graphql_query_get_question_detail_variables.py b/test/test_graphql_query_get_question_detail_variables.py new file mode 100644 index 0000000..710e8d5 --- /dev/null +++ b/test/test_graphql_query_get_question_detail_variables.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import, annotations + +import unittest + +import leetcode +from leetcode.models.graphql_query_get_question_detail_variables import ( # noqa: E501 + GraphqlQueryGetQuestionDetailVariables, +) +from leetcode.rest import ApiException + + +class TestGraphqlQueryGetQuestionDetailVariables(unittest.TestCase): + """GraphqlQueryGetQuestionDetailVariables unit test stubs""" + + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def testGraphqlQueryGetQuestionDetailVariables(self) -> None: + """Test GraphqlQueryGetQuestionDetailVariables""" + # FIXME: construct object with mandatory attributes with example values + # model = leetcode.models.graphql_query_get_question_detail_variables.GraphqlQueryGetQuestionDetailVariables() # noqa: E501 + pass + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_graphql_query_problemset_question_list_variables.py b/test/test_graphql_query_problemset_question_list_variables.py new file mode 100644 index 0000000..c99f4e9 --- /dev/null +++ b/test/test_graphql_query_problemset_question_list_variables.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import, annotations + +import unittest + +import leetcode +from leetcode.models.graphql_query_problemset_question_list_variables import ( # noqa: E501 + GraphqlQueryProblemsetQuestionListVariables, +) +from leetcode.rest import ApiException + + +class TestGraphqlQueryProblemsetQuestionListVariables(unittest.TestCase): + """GraphqlQueryProblemsetQuestionListVariables unit test stubs""" + + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def testGraphqlQueryProblemsetQuestionListVariables(self) -> None: + """Test GraphqlQueryProblemsetQuestionListVariables""" + # FIXME: construct object with mandatory attributes with example values + # model = leetcode.models.graphql_query_problemset_question_list_variables.GraphqlQueryProblemsetQuestionListVariables() # noqa: E501 + pass + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_graphql_query_problemset_question_list_variables_filter_input.py b/test/test_graphql_query_problemset_question_list_variables_filter_input.py new file mode 100644 index 0000000..40440f3 --- /dev/null +++ b/test/test_graphql_query_problemset_question_list_variables_filter_input.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +""" + Leetcode API + + Leetcode API implementation. # noqa: E501 + + OpenAPI spec version: 1.0.1-1 + Contact: pv.safronov@gmail.com + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import, annotations + +import unittest + +import leetcode +from leetcode.models.graphql_query_problemset_question_list_variables_filter_input import ( # noqa: E501 + GraphqlQueryProblemsetQuestionListVariablesFilterInput, +) +from leetcode.rest import ApiException + + +class TestGraphqlQueryProblemsetQuestionListVariablesFilterInput(unittest.TestCase): + """GraphqlQueryProblemsetQuestionListVariablesFilterInput unit test stubs""" + + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def testGraphqlQueryProblemsetQuestionListVariablesFilterInput(self) -> None: + """Test GraphqlQueryProblemsetQuestionListVariablesFilterInput""" + # FIXME: construct object with mandatory attributes with example values + # model = leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput() # noqa: E501 + pass + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_graphql_question_code_snippet.py b/test/test_graphql_question_code_snippet.py index 71638c5..5116b4b 100644 --- a/test/test_graphql_question_code_snippet.py +++ b/test/test_graphql_question_code_snippet.py @@ -10,7 +10,7 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ -from __future__ import annotations, absolute_import +from __future__ import absolute_import, annotations import unittest diff --git a/test/test_graphql_question_contributor.py b/test/test_graphql_question_contributor.py index 5b2e60a..4b0843e 100644 --- a/test/test_graphql_question_contributor.py +++ b/test/test_graphql_question_contributor.py @@ -10,7 +10,7 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ -from __future__ import annotations, absolute_import +from __future__ import absolute_import, annotations import unittest diff --git a/test/test_graphql_question_solution.py b/test/test_graphql_question_solution.py index 5667853..6262508 100644 --- a/test/test_graphql_question_solution.py +++ b/test/test_graphql_question_solution.py @@ -10,7 +10,7 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ -from __future__ import annotations, absolute_import +from __future__ import absolute_import, annotations import unittest diff --git a/test/test_graphql_question_topic_tag.py b/test/test_graphql_question_topic_tag.py index 9884de0..125e2d3 100644 --- a/test/test_graphql_question_topic_tag.py +++ b/test/test_graphql_question_topic_tag.py @@ -10,7 +10,7 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ -from __future__ import annotations, absolute_import +from __future__ import absolute_import, annotations import unittest diff --git a/test/test_graphql_request_get_question_detail.py b/test/test_graphql_request_get_question_detail.py index 2c0991e..088893e 100644 --- a/test/test_graphql_request_get_question_detail.py +++ b/test/test_graphql_request_get_question_detail.py @@ -2,7 +2,9 @@ import test.base from leetcode.models.graphql_query import GraphqlQuery -from leetcode.models.graphql_query_variables import GraphqlQueryVariables +from leetcode.models.graphql_query_get_question_detail_variables import ( + GraphqlQueryGetQuestionDetailVariables, +) from leetcode.models.graphql_question_code_snippet import GraphqlQuestionCodeSnippet from leetcode.models.graphql_question_topic_tag import GraphqlQuestionTopicTag @@ -73,7 +75,7 @@ def test_request(self) -> None: } } """, - variables=GraphqlQueryVariables(title_slug="two-sum"), + variables=GraphqlQueryGetQuestionDetailVariables(title_slug="two-sum"), operation_name="getQuestionDetail", ) @@ -83,6 +85,10 @@ def test_request(self) -> None: assert data + problemset_question_list = data.problemset_question_list + + assert problemset_question_list is None + question = data.question user = data.user diff --git a/test/test_graphql_request_problemset_question_list.py b/test/test_graphql_request_problemset_question_list.py new file mode 100644 index 0000000..86ef410 --- /dev/null +++ b/test/test_graphql_request_problemset_question_list.py @@ -0,0 +1,210 @@ +import json +import test.base + +from leetcode.models.graphql_query import GraphqlQuery +from leetcode.models.graphql_query_problemset_question_list_variables import ( + GraphqlQueryProblemsetQuestionListVariables, +) +from leetcode.models.graphql_query_problemset_question_list_variables_filter_input import ( + GraphqlQueryProblemsetQuestionListVariablesFilterInput, +) +from leetcode.models.graphql_question_code_snippet import GraphqlQuestionCodeSnippet +from leetcode.models.graphql_question_topic_tag import GraphqlQuestionTopicTag + + +class TestGraphqlGetQuestionDetail(test.base.BaseTest): + def test_request(self) -> None: + graphql_request = GraphqlQuery( + query=""" + query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) { + problemsetQuestionList: questionList( + categorySlug: $categorySlug + limit: $limit + skip: $skip + filters: $filters + ) { + total: totalNum + questions: data { + questionId + questionFrontendId + boundTopicId + title + frequency + freqBar + content + translatedTitle + isPaidOnly + difficulty + likes + dislikes + isLiked + isFavor + similarQuestions + contributors { + username + profileUrl + avatarUrl + __typename + } + langToValidPlayground + topicTags { + name + slug + translatedName + __typename + } + companyTagStats + codeSnippets { + lang + langSlug + code + __typename + } + stats + acRate + codeDefinition + hints + solution { + id + canSeeDetail + __typename + } + hasSolution + hasVideoSolution + status + sampleTestCase + enableRunCode + metaData + translatedContent + judgerAvailable + judgeType + mysqlSchemas + enableTestMode + envInfo + __typename + } + } + } + """, + variables=GraphqlQueryProblemsetQuestionListVariables( + category_slug="algorithms", + limit=1, + skip=2, + filters=GraphqlQueryProblemsetQuestionListVariablesFilterInput( + tags=["array"], + difficulty="MEDIUM", + status="NOT_STARTED", + list_id="7p5x763", # Top Amazon Questions + premium_only=False, + ), + ), + operation_name="problemsetQuestionList", + ) + + response = self._api_instance.graphql_post(body=graphql_request) + + data = response.data + + question = data.question + + assert question is None + + assert data + + assert data.problemset_question_list.total > 0 + + question_list = data.problemset_question_list.questions + user = data.user + + question = question_list[0] + + assert user is None + + assert question.question_id is not None + assert question.question_frontend_id is not None + assert question.bound_topic_id is None + assert question.title is not None + assert question.frequency == 0.0 + assert question.freq_bar > 0 + assert len(question.content) > 10 + assert question.translated_title is None + assert question.is_paid_only in (True, False) + assert question.difficulty == "Medium" + assert question.likes > 0 + assert question.dislikes > 0 + assert question.is_liked is None + assert question.is_favor in (True, False) + + json.loads(question.similar_questions) + + assert len(question.contributors) == 0 + assert "python" in list(json.loads(question.lang_to_valid_playground).keys()) + topic_tag = question.topic_tags[0] + assert isinstance(topic_tag, GraphqlQuestionTopicTag) + assert len(topic_tag.name) > 0 + assert len(topic_tag.slug) > 0 + assert question.topic_tags[0].translated_name is None + assert len(topic_tag.typename) > 0 + + tag_stat = list(json.loads(question.company_tag_stats).values())[0][0] + + assert tag_stat["taggedByAdmin"] in (True, False) + assert len(tag_stat["name"]) > 0 + assert len(tag_stat["slug"]) > 0 + assert tag_stat["timesEncountered"] > 0 + + code_snippet = question.code_snippets[0] + + assert isinstance(code_snippet, GraphqlQuestionCodeSnippet) + assert len(code_snippet.code) > 0 + assert len(code_snippet.lang) > 0 + assert len(code_snippet.lang_slug) > 0 + assert code_snippet.typename == "CodeSnippetNode" + + stats = json.loads(question.stats) + + assert len(stats["totalAccepted"]) > 0 + assert len(stats["totalSubmission"]) > 0 + assert int(stats["totalAcceptedRaw"]) > 0 + assert int(stats["totalSubmissionRaw"]) > 0 + + assert question.ac_rate > 0 + + code_definition = json.loads(question.code_definition)[0] + + assert len(code_definition["value"]) > 0 + assert len(code_definition["text"]) > 0 + assert len(code_definition["defaultCode"]) > 0 + + assert [len(hint) > 0 for hint in question.hints] + + question.solution + + assert question.has_solution in (True, False) + assert question.has_video_solution in (True, False) + + assert question.status in ("ac", "not_started", "tried", None) + + assert len(question.sample_test_case) > 0 + + assert question.enable_run_code in (True, False) + + meta_data = json.loads(question.meta_data) + + assert meta_data["name"] is not None + assert meta_data["params"][0]["name"] + assert meta_data["params"][0]["type"] + assert meta_data["return"]["type"] + + assert question.translated_content is None + + assert question.judger_available is True + assert question.judge_type in ("large", "small") + + assert question.mysql_schemas == [] + + assert question.enable_test_mode in (True, False) + + env_info = json.loads(question.env_info) + + assert env_info["cpp"][0] == "C++" diff --git a/test/test_graphql_request_user.py b/test/test_graphql_request_user.py index 0d19102..8ddbc8f 100644 --- a/test/test_graphql_request_user.py +++ b/test/test_graphql_request_user.py @@ -1,7 +1,7 @@ import json import test.base -import leetcode +import leetcode.models.graphql_query_variables class TestGraphqlGetUser(test.base.BaseTest): @@ -15,7 +15,7 @@ def test_request(self) -> None: } } """, - variables=leetcode.GraphqlQueryVariables(), + variables=leetcode.models.graphql_query_variables.GraphqlQueryVariables(), operation_name="", ) diff --git a/test/test_graphql_user.py b/test/test_graphql_user.py index 9e07da2..856a5c1 100644 --- a/test/test_graphql_user.py +++ b/test/test_graphql_user.py @@ -10,7 +10,7 @@ Generated by: https://github.com/swagger-api/swagger-codegen.git """ -from __future__ import annotations, absolute_import +from __future__ import absolute_import, annotations import unittest From 7fdb28d17f731e67a53909292dfdb6cf35f7f5ed Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Tue, 26 Oct 2021 17:31:49 +0100 Subject: [PATCH 02/16] Added titleSlug field to question details and fixed totalNum field name of problemset list reponse --- docs/GraphqlProblemsetQuestionList.md | 2 +- docs/GraphqlQuestionDetail.md | 1 + .../graphql_problemset_question_list.py | 30 +++++++++---------- leetcode/models/graphql_question_detail.py | 27 +++++++++++++++++ setup.py | 2 +- ...est_graphql_request_get_question_detail.py | 2 ++ ...raphql_request_problemset_question_list.py | 4 +-- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/docs/GraphqlProblemsetQuestionList.md b/docs/GraphqlProblemsetQuestionList.md index 5253478..3bd62e0 100644 --- a/docs/GraphqlProblemsetQuestionList.md +++ b/docs/GraphqlProblemsetQuestionList.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**total** | **int** | | [optional] +**total_num** | **int** | | [optional] **questions** | [**list[GraphqlQuestionDetail]**](GraphqlQuestionDetail.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/docs/GraphqlQuestionDetail.md b/docs/GraphqlQuestionDetail.md index c91d96f..e97b286 100644 --- a/docs/GraphqlQuestionDetail.md +++ b/docs/GraphqlQuestionDetail.md @@ -7,6 +7,7 @@ Name | Type | Description | Notes **question_frontend_id** | **str** | | [optional] **bound_topic_id** | **str** | | [optional] **title** | **str** | | [optional] +**title_slug** | **str** | | [optional] **frequency** | **float** | | [optional] **freq_bar** | **float** | | [optional] **content** | **str** | | [optional] diff --git a/leetcode/models/graphql_problemset_question_list.py b/leetcode/models/graphql_problemset_question_list.py index 890b1e1..b0f1e11 100644 --- a/leetcode/models/graphql_problemset_question_list.py +++ b/leetcode/models/graphql_problemset_question_list.py @@ -30,40 +30,40 @@ class GraphqlProblemsetQuestionList(object): attribute_map (dict): The key is attribute name and the value is json key in definition. """ - swagger_types = {"total": "int", "questions": "list[GraphqlQuestionDetail]"} + swagger_types = {"total_num": "int", "questions": "list[GraphqlQuestionDetail]"} - attribute_map = {"total": "total", "questions": "questions"} + attribute_map = {"total_num": "totalNum", "questions": "questions"} - def __init__(self, total=None, questions=None) -> None: # noqa: E501 + def __init__(self, total_num=None, questions=None) -> None: # noqa: E501 """GraphqlProblemsetQuestionList - a model defined in Swagger""" # noqa: E501 - self._total = None + self._total_num = None self._questions = None self.discriminator = None - if total is not None: - self.total = total + if total_num is not None: + self.total_num = total_num if questions is not None: self.questions = questions @property - def total(self): - """Gets the total of this GraphqlProblemsetQuestionList. # noqa: E501 + def total_num(self): + """Gets the total_num of this GraphqlProblemsetQuestionList. # noqa: E501 - :return: The total of this GraphqlProblemsetQuestionList. # noqa: E501 + :return: The total_num of this GraphqlProblemsetQuestionList. # noqa: E501 :rtype: int """ - return self._total + return self._total_num - @total.setter - def total(self, total): - """Sets the total of this GraphqlProblemsetQuestionList. + @total_num.setter + def total_num(self, total_num): + """Sets the total_num of this GraphqlProblemsetQuestionList. - :param total: The total of this GraphqlProblemsetQuestionList. # noqa: E501 + :param total_num: The total_num of this GraphqlProblemsetQuestionList. # noqa: E501 :type: int """ - self._total = total + self._total_num = total_num @property def questions(self): diff --git a/leetcode/models/graphql_question_detail.py b/leetcode/models/graphql_question_detail.py index 215b67d..9fdb0fd 100644 --- a/leetcode/models/graphql_question_detail.py +++ b/leetcode/models/graphql_question_detail.py @@ -34,6 +34,7 @@ class GraphqlQuestionDetail(object): "question_frontend_id": "str", "bound_topic_id": "str", "title": "str", + "title_slug": "str", "frequency": "float", "freq_bar": "float", "content": "str", @@ -74,6 +75,7 @@ class GraphqlQuestionDetail(object): "question_frontend_id": "questionFrontendId", "bound_topic_id": "boundTopicId", "title": "title", + "title_slug": "titleSlug", "frequency": "frequency", "freq_bar": "freqBar", "content": "content", @@ -115,6 +117,7 @@ def __init__( question_frontend_id=None, bound_topic_id=None, title=None, + title_slug=None, frequency=None, freq_bar=None, content=None, @@ -154,6 +157,7 @@ def __init__( self._question_frontend_id = None self._bound_topic_id = None self._title = None + self._title_slug = None self._frequency = None self._freq_bar = None self._content = None @@ -196,6 +200,8 @@ def __init__( self.bound_topic_id = bound_topic_id if title is not None: self.title = title + if title_slug is not None: + self.title_slug = title_slug if frequency is not None: self.frequency = frequency if freq_bar is not None: @@ -347,6 +353,27 @@ def title(self, title): self._title = title + @property + def title_slug(self): + """Gets the title_slug of this GraphqlQuestionDetail. # noqa: E501 + + + :return: The title_slug of this GraphqlQuestionDetail. # noqa: E501 + :rtype: str + """ + return self._title_slug + + @title_slug.setter + def title_slug(self, title_slug): + """Sets the title_slug of this GraphqlQuestionDetail. + + + :param title_slug: The title_slug of this GraphqlQuestionDetail. # noqa: E501 + :type: str + """ + + self._title_slug = title_slug + @property def frequency(self): """Gets the frequency of this GraphqlQuestionDetail. # noqa: E501 diff --git a/setup.py b/setup.py index 79bf053..2810149 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import find_packages, setup # noqa: H301 NAME = "python-leetcode" -VERSION = "1.1.0" +VERSION = "1.2.0" with open("README.md") as readme: DESCRIPTION: str = readme.read() diff --git a/test/test_graphql_request_get_question_detail.py b/test/test_graphql_request_get_question_detail.py index 088893e..6e3fc83 100644 --- a/test/test_graphql_request_get_question_detail.py +++ b/test/test_graphql_request_get_question_detail.py @@ -19,6 +19,7 @@ def test_request(self) -> None: questionFrontendId boundTopicId title + titleSlug frequency freqBar content @@ -98,6 +99,7 @@ def test_request(self) -> None: assert question.question_frontend_id == "1" assert question.bound_topic_id is None assert question.title == "Two Sum" + assert question.title_slug == "two-sum" assert question.frequency == 0.0 assert question.freq_bar > 0 assert len(question.content) > 10 diff --git a/test/test_graphql_request_problemset_question_list.py b/test/test_graphql_request_problemset_question_list.py index 86ef410..c5801a4 100644 --- a/test/test_graphql_request_problemset_question_list.py +++ b/test/test_graphql_request_problemset_question_list.py @@ -23,7 +23,7 @@ def test_request(self) -> None: skip: $skip filters: $filters ) { - total: totalNum + totalNum questions: data { questionId questionFrontendId @@ -111,7 +111,7 @@ def test_request(self) -> None: assert data - assert data.problemset_question_list.total > 0 + assert data.problemset_question_list.total_num > 0 question_list = data.problemset_question_list.questions user = data.user From 1787fff62a1b6b1e191c7ae033d3f16856884bc6 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Tue, 26 Oct 2021 21:10:40 +0100 Subject: [PATCH 03/16] Added category title field --- docs/GraphqlQuestionDetail.md | 1 + leetcode/models/graphql_question_detail.py | 27 ++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/GraphqlQuestionDetail.md b/docs/GraphqlQuestionDetail.md index e97b286..c02634f 100644 --- a/docs/GraphqlQuestionDetail.md +++ b/docs/GraphqlQuestionDetail.md @@ -8,6 +8,7 @@ Name | Type | Description | Notes **bound_topic_id** | **str** | | [optional] **title** | **str** | | [optional] **title_slug** | **str** | | [optional] +**category_title** | **str** | | [optional] **frequency** | **float** | | [optional] **freq_bar** | **float** | | [optional] **content** | **str** | | [optional] diff --git a/leetcode/models/graphql_question_detail.py b/leetcode/models/graphql_question_detail.py index 9fdb0fd..0d3498a 100644 --- a/leetcode/models/graphql_question_detail.py +++ b/leetcode/models/graphql_question_detail.py @@ -35,6 +35,7 @@ class GraphqlQuestionDetail(object): "bound_topic_id": "str", "title": "str", "title_slug": "str", + "category_title": "str", "frequency": "float", "freq_bar": "float", "content": "str", @@ -76,6 +77,7 @@ class GraphqlQuestionDetail(object): "bound_topic_id": "boundTopicId", "title": "title", "title_slug": "titleSlug", + "category_title": "categoryTitle", "frequency": "frequency", "freq_bar": "freqBar", "content": "content", @@ -118,6 +120,7 @@ def __init__( bound_topic_id=None, title=None, title_slug=None, + category_title=None, frequency=None, freq_bar=None, content=None, @@ -158,6 +161,7 @@ def __init__( self._bound_topic_id = None self._title = None self._title_slug = None + self._category_title = None self._frequency = None self._freq_bar = None self._content = None @@ -202,6 +206,8 @@ def __init__( self.title = title if title_slug is not None: self.title_slug = title_slug + if category_title is not None: + self.category_title = category_title if frequency is not None: self.frequency = frequency if freq_bar is not None: @@ -374,6 +380,27 @@ def title_slug(self, title_slug): self._title_slug = title_slug + @property + def category_title(self): + """Gets the category_title of this GraphqlQuestionDetail. # noqa: E501 + + + :return: The category_title of this GraphqlQuestionDetail. # noqa: E501 + :rtype: str + """ + return self._category_title + + @category_title.setter + def category_title(self, category_title): + """Sets the category_title of this GraphqlQuestionDetail. + + + :param category_title: The category_title of this GraphqlQuestionDetail. # noqa: E501 + :type: str + """ + + self._category_title = category_title + @property def frequency(self): """Gets the frequency of this GraphqlQuestionDetail. # noqa: E501 diff --git a/setup.py b/setup.py index 2810149..1323596 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import find_packages, setup # noqa: H301 NAME = "python-leetcode" -VERSION = "1.2.0" +VERSION = "1.2.1" with open("README.md") as readme: DESCRIPTION: str = readme.read() From 833d92bf04a8da9c21253aebb908ad8ca9fa785f Mon Sep 17 00:00:00 2001 From: dimaglushkov Date: Thu, 24 Feb 2022 13:58:48 +0300 Subject: [PATCH 04/16] #14 add requriements loading from requriements.txt --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1323596..4b7b0c9 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,8 @@ # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools -REQUIRES = ["urllib3 >= 1.15", "six >= 1.10", "certifi", "python-dateutil", "requests"] +with open("requirements.txt") as requirements: + REQUIRES = [req.replace('\n', '') for req in requirements.readlines()] setup( name=NAME, From 08779329c90e63aa989fef56cca01b4a36ece9cc Mon Sep 17 00:00:00 2001 From: dimaglushkov Date: Thu, 24 Feb 2022 14:06:40 +0300 Subject: [PATCH 05/16] #17 fix argument type in example.py --- example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.py b/example.py index 8d38d7d..bb61f76 100644 --- a/example.py +++ b/example.py @@ -96,7 +96,7 @@ } } """, - variables=leetcode.GraphqlQueryVariables(title_slug="two-sum"), + variables=leetcode.GraphqlQueryGetQuestionDetailVariables(title_slug="two-sum"), operation_name="getQuestionDetail", ) From a4f29e6b0bfc2e774950d93da544490d9435a10b Mon Sep 17 00:00:00 2001 From: Dima Glushkov <38703979+dimaglushkov@users.noreply.github.com> Date: Sun, 6 Mar 2022 19:36:12 +0300 Subject: [PATCH 06/16] Update setup.py Co-authored-by: Pavel Safronov --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4b7b0c9..ae727f1 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ # http://pypi.python.org/pypi/setuptools with open("requirements.txt") as requirements: - REQUIRES = [req.replace('\n', '') for req in requirements.readlines()] + REQUIRES = [req.replace("\n", "") for req in requirements.readlines()] setup( name=NAME, From 904b03c408b5b5cbec933de6d80d811d90b4626e Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Sun, 6 Mar 2022 17:28:30 +0000 Subject: [PATCH 07/16] Changed a test question to make tests work --- test/test_graphql_request_problemset_question_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_graphql_request_problemset_question_list.py b/test/test_graphql_request_problemset_question_list.py index c5801a4..3a79707 100644 --- a/test/test_graphql_request_problemset_question_list.py +++ b/test/test_graphql_request_problemset_question_list.py @@ -89,7 +89,7 @@ def test_request(self) -> None: variables=GraphqlQueryProblemsetQuestionListVariables( category_slug="algorithms", limit=1, - skip=2, + skip=3, filters=GraphqlQueryProblemsetQuestionListVariablesFilterInput( tags=["array"], difficulty="MEDIUM", From c86206a13f75b67b21e89df27080761513bfe194 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Sun, 6 Mar 2022 17:31:11 +0000 Subject: [PATCH 08/16] Bump the version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ae727f1..9ed8dc3 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import find_packages, setup # noqa: H301 NAME = "python-leetcode" -VERSION = "1.2.1" +VERSION = "1.2.2" with open("README.md") as readme: DESCRIPTION: str = readme.read() From a9c17c58d8a8a7f79ecd0bd4d1a7d851eaae876b Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Wed, 26 Feb 2025 22:24:04 +0000 Subject: [PATCH 09/16] remove csrf auth method, because it doesnt work --- .github/workflows/pytest.yml | 1 + README.md | 14 +++++--------- example.py | 4 +--- leetcode/auth.py | 12 ------------ setup.py | 2 +- test/base.py | 5 ++--- 6 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 leetcode/auth.py diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 477d11b..bda6762 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -23,3 +23,4 @@ jobs: run: pytest -vvvv -s env: LEETCODE_SESSION_ID: ${{ secrets.LEETCODE_SESSION }} + LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN}} diff --git a/README.md b/README.md index caaa3b7..3d90fcd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -![build](https://github.com/prius/python-leetcode/actions/workflows/publish-to-pypi.yml/badge.svg) -![tests](https://github.com/prius/python-leetcode/actions/workflows/pytest.yml/badge.svg) +![build](https://github.com/fspv/python-leetcode/actions/workflows/publish-to-pypi.yml/badge.svg) +![tests](https://github.com/fspv/python-leetcode/actions/workflows/pytest.yml/badge.svg) ![pypi](https://badge.fury.io/py/python-leetcode.svg) ![pypi-downloads](https://img.shields.io/pypi/dm/python-leetcode) ![python-versions](https://img.shields.io/pypi/pyversions/python-leetcode) @@ -9,7 +9,7 @@ This repo contains a python client to access all known so far methods of Leetcode API. -The code is autogenerated by swagger. Swagger reference can be found here: [https://github.com/prius/leetcode-swagger](https://github.com/prius/leetcode-swagger) +The code is autogenerated by swagger. Swagger reference can be found here: [https://github.com/fspv/leetcode-swagger](https://github.com/fspv/leetcode-swagger) PyPi package link: [https://pypi.org/project/python-leetcode/](https://pypi.org/project/python-leetcode/) @@ -30,10 +30,6 @@ import leetcode leetcode_session = "yyy" csrf_token = "xxx" -# Experimental: Or CSRF token can be obtained automatically -import leetcode.auth -csrf_token = leetcode.auth.get_csrf_cookie(leetcode_session) - configuration = leetcode.Configuration() configuration.api_key["x-csrftoken"] = csrf_token @@ -168,8 +164,8 @@ In this case memoization topic is one of the targets for improvement, so I can g ## Example services using this library -* Anki cards generator [https://github.com/prius/leetcode-anki](https://github.com/prius/leetcode-anki) -* Leetcode helper website [https://github.com/prius/grind-helper](https://github.com/prius/grind-helper) +* Anki cards generator [https://github.com/fspv/leetcode-anki](https://github.com/fspv/leetcode-anki) +* Leetcode helper website [https://github.com/fspv/grind-helper](https://github.com/fspv/grind-helper) ## Additional info You can find other examples of usage in `example.py` diff --git a/example.py b/example.py index bb61f76..1fc29cb 100644 --- a/example.py +++ b/example.py @@ -1,11 +1,9 @@ from __future__ import annotations import os -import sys from time import sleep import leetcode -import leetcode.auth # Initialize client configuration = leetcode.Configuration() @@ -14,7 +12,7 @@ # fields which contain corresponding cookies from web browser leetcode_session: str = os.environ["LEETCODE_SESSION_ID"] -csrf_token: str = leetcode.auth.get_csrf_cookie(leetcode_session) +csrf_token = os.environ["LEETCODE_CSRF_TOKEN"] configuration.api_key["x-csrftoken"] = csrf_token configuration.api_key["csrftoken"] = csrf_token diff --git a/leetcode/auth.py b/leetcode/auth.py deleted file mode 100644 index d9efd68..0000000 --- a/leetcode/auth.py +++ /dev/null @@ -1,12 +0,0 @@ -import requests - - -def get_csrf_cookie(session_id: str) -> str: - response = requests.get( - "https://leetcode.com/", - cookies={ - "LEETCODE_SESSION": session_id, - }, - ) - - return response.cookies["csrftoken"] diff --git a/setup.py b/setup.py index 9ed8dc3..92a2c8a 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import find_packages, setup # noqa: H301 NAME = "python-leetcode" -VERSION = "1.2.2" +VERSION = "1.2.3" with open("README.md") as readme: DESCRIPTION: str = readme.read() diff --git a/test/base.py b/test/base.py index dca44f6..a6fa2a9 100644 --- a/test/base.py +++ b/test/base.py @@ -3,7 +3,6 @@ import leetcode.api.default_api import leetcode.api_client -import leetcode.auth import leetcode.configuration @@ -25,9 +24,9 @@ def _api_instance( ) -> None: self._api_instance_containter = value - def setup(self) -> None: + def setup_method(self) -> None: session_id = os.environ["LEETCODE_SESSION_ID"] - csrftoken = leetcode.auth.get_csrf_cookie(session_id) + csrftoken = os.environ["LEETCODE_CSRF_TOKEN"] configuration = leetcode.configuration.Configuration() From 000a8df6dd7596642a139521e9dfc46ce319c823 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Wed, 26 Feb 2025 22:47:51 +0000 Subject: [PATCH 10/16] bump python version --- .github/workflows/publish-to-pypi.yml | 4 ++-- .github/workflows/pytest.yml | 4 ++-- setup.py | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 09fcc54..9f649a7 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - name: Set up Python 3.9 + - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.9 + python-version: 3.13 - name: Build a binary wheel and a source tarball run: python setup.py sdist - name: Publish distribution package to Test PyPI diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index bda6762..dbf95f2 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - name: Set up Python 3.9 + - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.9 + python-version: 3.13 - name: Install requirements run: pip install -r requirements.txt - name: Install test requirements diff --git a/setup.py b/setup.py index 92a2c8a..1bc1fed 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import find_packages, setup # noqa: H301 NAME = "python-leetcode" -VERSION = "1.2.3" +VERSION = "1.2.4" with open("README.md") as readme: DESCRIPTION: str = readme.read() @@ -35,7 +35,7 @@ description="Leetcode API", author="Pavel Safronov", author_email="pv.safronov@gmail.com", - url="https://github.com/prius/python-leetcode", + url="https://github.com/fspv/python-leetcode", keywords=["leetcode", "faang", "interview", "api"], install_requires=REQUIRES, packages=find_packages(), @@ -50,6 +50,10 @@ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ], python_requires=">=3.8", ) From 54d72029fda49d5328cfdc8eeda0646501b4ed56 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Wed, 26 Feb 2025 22:51:15 +0000 Subject: [PATCH 11/16] Try python 3.12 --- .github/workflows/publish-to-pypi.yml | 2 +- .github/workflows/pytest.yml | 2 +- setup.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 9f649a7..e8f8d17 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -10,7 +10,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.13 + python-version: 3.12 - name: Build a binary wheel and a source tarball run: python setup.py sdist - name: Publish distribution package to Test PyPI diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index dbf95f2..1a161de 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -10,7 +10,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.13 + python-version: 3.12 - name: Install requirements run: pip install -r requirements.txt - name: Install test requirements diff --git a/setup.py b/setup.py index 1bc1fed..e88deb7 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,6 @@ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", ], python_requires=">=3.8", ) From d0ecdf6c829242005c0321545c12f53b32e38ee7 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Wed, 26 Feb 2025 22:52:59 +0000 Subject: [PATCH 12/16] install requirements --- .github/workflows/publish-to-pypi.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index e8f8d17..b704c43 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -11,6 +11,8 @@ jobs: uses: actions/setup-python@v1 with: python-version: 3.12 + - name: Install requirements + run: pip install -r requirements.txt - name: Build a binary wheel and a source tarball run: python setup.py sdist - name: Publish distribution package to Test PyPI From 9d306b4e75fef7bc8746c20385ba4360048fd4a0 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Wed, 26 Feb 2025 23:00:01 +0000 Subject: [PATCH 13/16] fix build --- git_push.sh | 2 +- setup.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/git_push.sh b/git_push.sh index 1410312..e31c23b 100644 --- a/git_push.sh +++ b/git_push.sh @@ -8,7 +8,7 @@ git_repo_id=$2 release_note=$3 if [ "$git_user_id" = "" ]; then - git_user_id="prius" + git_user_id="fspv" echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" fi diff --git a/setup.py b/setup.py index e88deb7..1c22946 100644 --- a/setup.py +++ b/setup.py @@ -26,9 +26,6 @@ # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools -with open("requirements.txt") as requirements: - REQUIRES = [req.replace("\n", "") for req in requirements.readlines()] - setup( name=NAME, version=VERSION, @@ -37,7 +34,14 @@ author_email="pv.safronov@gmail.com", url="https://github.com/fspv/python-leetcode", keywords=["leetcode", "faang", "interview", "api"], - install_requires=REQUIRES, + install_requires=[ + "certifi >= 14.05.14", + "six >= 1.10", + "python_dateutil >= 2.5.3", + "setuptools >= 21.0.0", + "urllib3 >= 1.15.1", + "requests", + ], packages=find_packages(), include_package_data=True, long_description=DESCRIPTION, From 8b20a845cb883d08faeaed11d710196024949dd2 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Wed, 26 Feb 2025 23:02:25 +0000 Subject: [PATCH 14/16] bump version + instructions --- README.md | 14 ++++++++++++++ setup.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d90fcd..ca6ce6d 100644 --- a/README.md +++ b/README.md @@ -171,3 +171,17 @@ In this case memoization topic is one of the targets for improvement, so I can g You can find other examples of usage in `example.py` Autogenerated by swagger documentation can be found [here](/README.generated.md). + +## Development + +Test new created package before publishing +```sh +pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ python-leetcode==1.2.4 +``` + +Publish package +```sh +git tag 1.2.4 +git push --tags + +``` diff --git a/setup.py b/setup.py index 1c22946..55b7541 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import find_packages, setup # noqa: H301 NAME = "python-leetcode" -VERSION = "1.2.4" +VERSION = "1.2.5" with open("README.md") as readme: DESCRIPTION: str = readme.read() From e0e8463c564a92c1fe6489ba81969622536600fb Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Sat, 22 Mar 2025 19:11:40 +0000 Subject: [PATCH 15/16] add some tests --- test/base.py | 39 +++++- test/test_default_api.py | 117 +++++++++++++++--- test/test_difficulty.py | 6 +- ...est_graphql_request_get_question_detail.py | 16 +-- ...raphql_request_problemset_question_list.py | 18 +-- 5 files changed, 158 insertions(+), 38 deletions(-) diff --git a/test/base.py b/test/base.py index a6fa2a9..4e7689f 100644 --- a/test/base.py +++ b/test/base.py @@ -1,10 +1,47 @@ import os -from typing import Optional +from typing import Any, Optional import leetcode.api.default_api import leetcode.api_client import leetcode.configuration +def validate_stat_status_pair(stat_status_pair: Any) -> None: + assert isinstance(stat_status_pair, leetcode.StatStatusPair) + assert isinstance(stat_status_pair.difficulty, leetcode.Difficulty) + assert isinstance(stat_status_pair.difficulty.level, int) + assert isinstance(stat_status_pair.frequency, float) + assert isinstance(stat_status_pair.is_favor, bool) + assert isinstance(stat_status_pair.paid_only, bool) + assert isinstance(stat_status_pair.stat, leetcode.Stat) + if stat_status_pair.status is not None: + assert isinstance(stat_status_pair.status, str) + + assert isinstance(stat_status_pair.stat.frontend_question_id, int) + assert isinstance(stat_status_pair.stat.is_new_question, bool) + if stat_status_pair.stat.question__article__live is not None: + assert isinstance(stat_status_pair.stat.question__article__live, bool) + if stat_status_pair.stat.question__article__slug is not None: + assert isinstance(stat_status_pair.stat.question__article__slug, str) + assert isinstance(stat_status_pair.stat.question__hide, bool) + assert isinstance(stat_status_pair.stat.question__title, str) + assert isinstance(stat_status_pair.stat.question__title_slug, str) + assert isinstance(stat_status_pair.stat.question_id, int) + assert isinstance(stat_status_pair.stat.total_acs, int) + assert isinstance(stat_status_pair.stat.total_submitted, int) + +def validate_problems(problems: Any, category_slug: str) -> None: + assert isinstance(problems, leetcode.Problems) + assert isinstance(problems.ac_easy, int) + assert isinstance(problems.ac_hard, int) + assert isinstance(problems.ac_medium, int) + assert problems.category_slug == category_slug + assert isinstance(problems.num_solved, int) + assert isinstance(problems.num_total, int) + assert isinstance(problems.stat_status_pairs, list) + + for stat_status_pair in problems.stat_status_pairs: + validate_stat_status_pair(stat_status_pair) + class BaseTest: _api_instance_containter: Optional[leetcode.api.default_api.DefaultApi] = None diff --git a/test/test_default_api.py b/test/test_default_api.py index 91b85bb..49af474 100644 --- a/test/test_default_api.py +++ b/test/test_default_api.py @@ -12,41 +12,120 @@ from __future__ import absolute_import +from time import sleep import unittest +from leetcode.models.interpretation import Interpretation +from leetcode.models.submission_id import SubmissionId +import test.base import leetcode from leetcode.api.default_api import DefaultApi # noqa: E501 from leetcode.rest import ApiException -class TestDefaultApi(unittest.TestCase): - """DefaultApi unit test stubs""" - - def setUp(self): - self.api = DefaultApi() # noqa: E501 +class TestDefaultApi(test.base.BaseTest): + def test_api_problems_topic_get(self): + result = self._api_instance.api_problems_topic_get(topic="algorithms") + test.base.validate_problems(result, "algorithms") - def tearDown(self): - pass + result = self._api_instance.api_problems_topic_get(topic="nonexistent") + test.base.validate_problems(result, "nonexistent") - def test_api_problems_topic_get(self): - """Test case for api_problems_topic_get""" - pass + try: + self._api_instance.api_problems_topic_get(topic="") + assert False + except ApiException as e: + assert e.status == 404 def test_graphql_post(self): - """Test case for graphql_post""" pass def test_problems_problem_interpret_solution_post(self): - """Test case for problems_problem_interpret_solution_post""" - pass + code = """ + class Solution: + def twoSum(self, nums, target): + print("stdout") + return [1] + """ + test_submission = leetcode.TestSubmission( + data_input="[2,7,11,15]\n9", + typed_code=code, + question_id=1, + test_mode=False, + lang="python", + ) + + result = self._api_instance.problems_problem_interpret_solution_post( + problem="two-sum", + body=test_submission, + ) + + assert isinstance(result, Interpretation) - def test_problems_problem_submit_post(self): - """Test case for problems_problem_submit_post""" - pass - def test_submissions_detail_id_check_get(self): - """Test case for submissions_detail_id_check_get""" - pass + def test_problems_problem_submit_post(self): + code = """ + class Solution: + def twoSum(self, nums, target): + print("stdout") + return [1] + """ + + submission = leetcode.Submission( + judge_type="large", + typed_code=code, + question_id=1, + test_mode=False, + lang="python", + ) + submission_id = self._api_instance.problems_problem_submit_post( + problem="two-sum", body=submission + ) + assert isinstance(submission_id, SubmissionId) + + + sleep(5) # FIXME: should probably be a busy-waiting loop + + submission_result = self._api_instance.submissions_detail_id_check_get( + id=submission_id.submission_id + ) + # assert isinstance( + # submission_result, + # leetcode.SubmissionResult, + # ) or isinstance( + # submission_result, + # leetcode.TestSubmissionResult, + # ) + + # if isinstance(submission_result, leetcode.SubmissionResult): + # assert isinstance(submission_result.compare_result, str) + # assert isinstance(submission_result.std_output, str) + # assert isinstance(submission_result.last_testcase, str) + # assert isinstance(submission_result.expected_output, str) + # assert isinstance(submission_result.input_formatted, str) + # assert isinstance(submission_result.input, str) + # # Missing or incorrect fields + # # task_name: str + # # finished: bool + # elif isinstance(submission_result, leetcode.TestSubmissionResult): + # assert isinstance(submission_result.code_answer, list) + # assert isinstance(submission_result.correct_answer, bool) + # assert isinstance(submission_result.expected_status_code, int) + # assert isinstance(submission_result.expected_lang, str) + # assert isinstance(submission_result.expected_run_success, bool) + # assert isinstance(submission_result.expected_status_runtime, str) + # assert isinstance(submission_result.expected_memory, int) + # assert isinstance(submission_result.expected_code_answer, list) + # assert isinstance(submission_result.expected_code_output, list) + # assert isinstance(submission_result.expected_elapsed_time, int) + # assert isinstance(submission_result.expected_task_finish_time, int) + + # def test_submissions_detail_id_check_get(self): + # try: + # self._api_instance.submissions_detail_id_check_get(id="nonexistent") + # assert False + # except ApiException as e: + # assert e.status == 404 if __name__ == "__main__": diff --git a/test/test_difficulty.py b/test/test_difficulty.py index ca69804..41baf05 100644 --- a/test/test_difficulty.py +++ b/test/test_difficulty.py @@ -13,13 +13,14 @@ from __future__ import absolute_import import unittest +import test.base import leetcode from leetcode.models.difficulty import Difficulty # noqa: E501 from leetcode.rest import ApiException -class TestDifficulty(unittest.TestCase): +class TestDifficulty(test.base.BaseTest): """Difficulty unit test stubs""" def setUp(self): @@ -29,9 +30,6 @@ def tearDown(self): pass def testDifficulty(self): - """Test Difficulty""" - # FIXME: construct object with mandatory attributes with example values - # model = leetcode.models.difficulty.Difficulty() # noqa: E501 pass diff --git a/test/test_graphql_request_get_question_detail.py b/test/test_graphql_request_get_question_detail.py index 6e3fc83..b4713f5 100644 --- a/test/test_graphql_request_get_question_detail.py +++ b/test/test_graphql_request_get_question_detail.py @@ -101,7 +101,8 @@ def test_request(self) -> None: assert question.title == "Two Sum" assert question.title_slug == "two-sum" assert question.frequency == 0.0 - assert question.freq_bar > 0 + if question.freq_bar is not None: # only available for premium users + assert question.freq_bar > 0 assert len(question.content) > 10 assert question.translated_title is None assert question.is_paid_only is False @@ -124,12 +125,13 @@ def test_request(self) -> None: assert question.topic_tags[0].translated_name is None assert len(topic_tag.typename) > 0 - tag_stat = list(json.loads(question.company_tag_stats).values())[0][0] + if question.company_tag_stats is not None: # only available for premium users + tag_stat = list(json.loads(question.company_tag_stats).values())[0][0] - assert tag_stat["taggedByAdmin"] in (True, False) - assert len(tag_stat["name"]) > 0 - assert len(tag_stat["slug"]) > 0 - assert tag_stat["timesEncountered"] > 0 + assert tag_stat["taggedByAdmin"] in (True, False) + assert len(tag_stat["name"]) > 0 + assert len(tag_stat["slug"]) > 0 + assert tag_stat["timesEncountered"] > 0 code_snippet = question.code_snippets[0] @@ -169,7 +171,7 @@ def test_request(self) -> None: assert question.has_solution in (True, False) assert question.has_video_solution in (True, False) - assert question.status in ("ac", "not_started", "tried") + assert question.status in ("ac", "not_started", "tried", None) assert len(question.sample_test_case) > 0 diff --git a/test/test_graphql_request_problemset_question_list.py b/test/test_graphql_request_problemset_question_list.py index 3a79707..e57771d 100644 --- a/test/test_graphql_request_problemset_question_list.py +++ b/test/test_graphql_request_problemset_question_list.py @@ -125,7 +125,8 @@ def test_request(self) -> None: assert question.bound_topic_id is None assert question.title is not None assert question.frequency == 0.0 - assert question.freq_bar > 0 + if question.freq_bar is not None: # only available for premium users + assert question.freq_bar > 0 assert len(question.content) > 10 assert question.translated_title is None assert question.is_paid_only in (True, False) @@ -146,12 +147,13 @@ def test_request(self) -> None: assert question.topic_tags[0].translated_name is None assert len(topic_tag.typename) > 0 - tag_stat = list(json.loads(question.company_tag_stats).values())[0][0] + if question.company_tag_stats is not None: # only available for premium users + tag_stat = list(json.loads(question.company_tag_stats).values())[0][0] - assert tag_stat["taggedByAdmin"] in (True, False) - assert len(tag_stat["name"]) > 0 - assert len(tag_stat["slug"]) > 0 - assert tag_stat["timesEncountered"] > 0 + assert tag_stat["taggedByAdmin"] in (True, False) + assert len(tag_stat["name"]) > 0 + assert len(tag_stat["slug"]) > 0 + assert tag_stat["timesEncountered"] > 0 code_snippet = question.code_snippets[0] @@ -176,7 +178,9 @@ def test_request(self) -> None: assert len(code_definition["text"]) > 0 assert len(code_definition["defaultCode"]) > 0 - assert [len(hint) > 0 for hint in question.hints] + # TODO: check if the field has disappeared or if this is just a premium + # feature + # assert [len(hint) > 0 for hint in question.hints] question.solution From 9de718962af9071aab4a7bfb29457078940f143d Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Sat, 22 Mar 2025 19:12:24 +0000 Subject: [PATCH 16/16] some build infrastructure --- .github/workflows/publish-to-pypi.yml | 2 +- Dockerfile | 19 +++++++++++++++++++ README.md | 21 ++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index b704c43..34c6a9b 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -14,7 +14,7 @@ jobs: - name: Install requirements run: pip install -r requirements.txt - name: Build a binary wheel and a source tarball - run: python setup.py sdist + run: python setup.py sdist bdist_wheel - name: Publish distribution package to Test PyPI uses: pypa/gh-action-pypi-publish@master with: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6a14094 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# Test docker file +# `docker build .` verifies that the project builds and runs pytest +FROM python:3.12-slim + +# Verify wheel can be built +RUN pip install setuptools twine wheel + +WORKDIR /app + +COPY . /app/ + +RUN pip install --no-cache-dir . + +RUN python setup.py sdist bdist_wheel + +RUN python -c "import sys, leetcode; print(f'Package installed successfully in Python {sys.version}'); leetcode.DefaultApi(leetcode.ApiClient(leetcode.Configuration())); print('leetcode package is installed and functional')" + +RUN pip install pytest +RUN pytest -vvvv -s diff --git a/README.md b/README.md index ca6ce6d..0ed37ea 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ virtualenv -p python3 leetcode pip3 install python-leetcode ``` -Then in python shell initialize the client (if you're using chrome, cookies can be found here [chrome://settings/cookies/detail?site=leetcode.com](chrome://settings/cookies/detail?site=leetcode.com)) +Then in python shell initialize necessary environment variables. You can get it directly from your browser cookies (csrftoken and LEETCODE_SESSION) ```python import leetcode @@ -174,14 +174,29 @@ Autogenerated by swagger documentation can be found [here](/README.generated.md) ## Development +Build package locally and upload to test pypi +```sh +virtualenv .venv +. .venv/bin/activate +pip install setuptools twine wheel +rm -rf build/ dist/ *.egg-info/ *.egg +python setup.py sdist bdist_wheel +twine upload --repository-url https://test.pypi.org/legacy/ dist/*.whl +``` + +To run tests set up env variables and run this + +```sh +docker build --env LEETCODE_SESSION_ID=$LEETCODE_SESSION_ID --env LEETCODE_CSRF_TOKEN=$LEETCODE_CSRF_TOKEN . +``` + Test new created package before publishing ```sh -pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ python-leetcode==1.2.4 +pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ python-leetcode==1.2.5 ``` Publish package ```sh git tag 1.2.4 git push --tags - ```