Skip to content

Conversation

@dmuhs
Copy link
Contributor

@dmuhs dmuhs commented Mar 20, 2019

This PR will add:

  • magic methods to the analysis list and detected issues response models
  • delegated property acces for easier access to a model's underlying Analysis object
  • a context handler for the client class to allow easy usage with various accounts
  • jsonschema validation for all requests and responses

Furthermore, the *DecodeError exceptions have been deprecated in favour of the *ValidationError ones. This makes it easier to catch internal PythX errors. As discussed before, an example like this is now possible:

with Client(eth_address="0xF00...", password="my-password") as c:
    print(c.analysis_list())

Next up: Further UX improvements, examples in the readme, actual documentation, and then v1.0 🎉

@dmuhs dmuhs self-assigned this Mar 20, 2019
@dmuhs dmuhs requested a review from cache-monet March 20, 2019 11:36
@dmuhs dmuhs added this to the v1.0 milestone Mar 20, 2019
},
"refresh": {
"type": "string"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these the auth JWT's?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes 👍

}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Whew what an adventure~

schema = None

@classmethod
def validate(cls, candidate):
Copy link
Contributor

Choose a reason for hiding this comment

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

So even when derived classes call BaseResponse's implementation of validate, cls.schema would be the child's schema right?
ie: VersionResponse would have "version.json" as it's class schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. schema is a class property, meaning that it's the same (pointer to) the data for each class. validate then just hooks into that data and interprets it as a schema.
Because the base classes are abstract, we cannot instantiate them directly, so as long as our concrete class definitions override schema with the stuff they need, we should be fine.

Copy link
Contributor Author

@dmuhs dmuhs Mar 21, 2019

Choose a reason for hiding this comment

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

However, there's a hidden bug here. Classes which don't override schema and don't implement validate will fail, because their schema variable is None and the default validate implementation is executed. So in the default implementation we should add another check for None and raise a validation error to notify the user about a missing schema. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch

cache-monet
cache-monet previously approved these changes Mar 21, 2019
@classmethod
def validate(cls, candidate):
if cls.schema is None:
raise TypeError("Cannot use BaseRequest.validate without a schema")
Copy link
Contributor

Choose a reason for hiding this comment

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

Good informative error but I think we could abstract away the extra info. This error will mostly like occur when a derived class tries to call cls.validate(d) without setting the schema.
I'm unsure if we should give reveal too much of our implementation details.
Rephrasing to reveal the most relevant info:

if cls.schema is None:
      raise TypeError("Cannot validate request without a schema. Please load schema")

What do you think?

Copy link
Contributor Author

@dmuhs dmuhs Mar 22, 2019

Choose a reason for hiding this comment

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

Good point. This error will occur when a domain model doesn't have a JSON body (e.g. logout responses or analysis status requests). Maybe we should also bring this in somehow? Otherwise the user will be confused if we ask them to load a schema even though there can't be one. It's most likely a mistaken validate call

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to overridevalidate for those models then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. That's always possible in Python, after all we are all consenting adults here. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohmy that's pretty different from what's taught in class 😂 (The encapsulation part I mean)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants