Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloning, Model Validation #39

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Cloning, Model Validation #39

wants to merge 10 commits into from

Conversation

dpguthrie
Copy link
Owner

No description provided.

@dpguthrie dpguthrie changed the title Feat/model validation Cloning, Model Validation Sep 27, 2022
git_provider_webhook: Optional[bool] = None


class Job(BaseModel):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-winkler Here's what I was thinking as far as doing validation for a particular resource. This is pydantic and it provides this validation out of the box when you provide the schema for the resource.

@@ -77,10 +59,28 @@ def _header_property(self):

return 'api_key'

def _clone_resource(self, resource: str, **kwargs):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-winkler A private method that we can use for other resources we'd like to clone

def _make_request(
self, path: str, *, method: str = 'get', **kwargs
) -> requests.Response:
"""Make request to API."""

# Model is not an argument that the request method accepts, needs to be removed
model = kwargs.pop('model', None)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-winkler This is where we would pull out the model, if it's been passed. And line 83 below will assign the validated model, with the appropriate defaults, back to the json key.

@@ -291,6 +318,7 @@ def create_job(self, account_id: int, payload: Dict) -> Dict:
f'accounts/{account_id}/jobs/',
method='post',
json=payload,
model=models.Job,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-winkler This is where the appropriate model would be passed.

@dpguthrie dpguthrie marked this pull request as draft September 27, 2022 22:15
@dpguthrie dpguthrie mentioned this pull request Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants