-
Notifications
You must be signed in to change notification settings - Fork 220
Add event #139
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
Conversation
|
Hi @kelseymorris95, thanks for the pull request. Before we can merge it, we need you to sign our Contributor License Agreement. You can do so electronically here: http://opensource.box.com/cla Once you have signed, just add a comment to this pull request saying, "CLA signed". Thanks! |
boxsdk/object/event.py
Outdated
| def get_url(self, *args): | ||
| """ | ||
| Base class override. | ||
| Disallow this method for this subclass, should not access Event by event_id. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Note that there is no get method in the box v2 api for Event.
test/unit/object/test_event.py
Outdated
|
|
||
| def test_init_event(mock_box_session): | ||
| event = Event(mock_box_session, "f82c3ba03e41f7e8a7608363cc6c0390183c3f83", { | ||
| "type": "event", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting here... actually travis is probably complaining about this.
we usually use the format like:
event = Event(
arg1,
next_arg_on_new_line_if_we_are_using_multiline,
{
foo: bar,
baz: wing,
ding: {
but_were_not_super_strict_I_didnt_put_the_above_curley_on_its_own_line: value1,
but_we_are_picky_about_the_last_item_having_a_trailing_comma: value2,
},
},
)
test/unit/object/test_events.py
Outdated
| ] | ||
| events = test_events.generate_events_with_long_polling(**stream_type_kwargs) | ||
| assert next(events) == mock_event | ||
| assert next(events) == mock_event_object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having the mock_event_object fixture you could construct the mock Event here based on the mock_event json. Then do the assert check for equality. Then I think you can remove the mock_event fixture.
boxsdk/object/event.py
Outdated
| Base class override. | ||
| Disallow this method for this subclass, should not access Event by event_id. | ||
| """ | ||
| raise AttributeError("'Event' class has no method 'get_url'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad that you noticed this issue.
To me, this sort of thing is a code smell. If a baseclass defines a default behavior, and then a subclass is incapable of performing that behavior, chances are, the subclass should not actually inherit from that baseclass.
I believe that to be the case here. BaseObject is a class that is the root for all possible persistent, addressable resource types in the REST API.
Since we've never thought about non-persistent / non-addressable objects before, we didn't think about this when we first created #15.
I have an idea of what we should do here, but I'm curious for your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same thing - Event should probably not derive directly from BaseObject.
@kelseymorris95 @jmoldow should we get together to discuss the right plan for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had discussed this with Jeremy because I wasn't sure what approach was best. Most methods in BaseObject use get_url(), so I think the only behaviours of BaseObject that we actually want to mimic are init, getitem, repr, object_id, and eq.
Is there an option besides reproducing those behaviors separately in Event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out #140. The first half is unrelated, but the second half overlaps with what we're talking about here.
|
CLA signed |
|
Verified that @kelseymorris95 has just signed the CLA. Thanks, and we look forward to your contribution. |
boxsdk/object/api_json_object.py
Outdated
| @@ -0,0 +1,12 @@ | |||
| # coding: utf-8 | |||
|
|
|||
| from __future__ import unicode_literals | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also be using absolute_import in all files.
boxsdk/object/base_object.py
Outdated
| A Box API endpoint for interacting with a Box object. | ||
| """ | ||
| # Question: | ||
| # Should this item type be a part of other objects? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it isn't necessary. This is just here so that all of its subclasses at least have _item_type defined, even if it is None.
Though this should move to BaseAPIJSONObject, since that is now the base for translation.
|
Something to think about: This has two problems:
Let's not worry about this right now. What we have now works well enough to push what you have as-is. But we'll want to revisit this before or during work on #140. |
| from .base_api_json_object import BaseAPIJSONObject, BaseAPIJSONObjectMeta | ||
|
|
||
|
|
||
| class APIJSONObjectMeta(BaseAPIJSONObjectMeta, ABCMeta): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an empty ABCMeta which is a little strange to me. I don't follow the comment about avoiding conflicts. We get BetaAPIJSONObjectMeta thru BaseAPIJSONObject below in APIJSONObject... so, I'm not sure what this is needed for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thnx for explaining... I think that's worth a link & comment.
http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/
or something saying this addresses the known issue with inheriting from 2 classes with separate metaclasses.
|
👍 |
| A JSON object representing the object returned from a Box API request. | ||
| :type response_object: | ||
| :class:`BoxResponse` | ||
| :`dict` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No colon here and in other places.
|
👍 Thanks @kelseymorris95 ! This all looks great. I'm going to merge it now. Before releasing this to PyPI, over the next few days, let's make sure we're happy with the names of the new classes, make a final decision about |
Added an Event class, edited Events.get_event() to return a list of them. Added basic Event unit test file for future use.
Fixes #15.