-
Notifications
You must be signed in to change notification settings - Fork 72
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
Adding documentation and object to 'create' function. #56
Changes from 12 commits
f558da3
ded0b9e
d6c6b76
c676039
36d6fe5
21e0daf
86e2a19
025320a
b9112ab
fba343e
52916d8
6de014c
767480b
4454fdf
c0d2fe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,11 +71,38 @@ def create(self, **kwargs): | |
if "requester_id" in kwargs: | ||
extra_headers["From"] = kwargs.pop("requester_id") | ||
|
||
data[self.sname] = kwargs | ||
new_kwargs = {} | ||
|
||
for kwarg_key, kwarg_value in kwargs.iteritems(): | ||
if kwarg_key.endswith('_id'): | ||
new_kwargs = Collection.id_to_obj(kwarg_key, kwarg_value) | ||
elif kwarg_key.endswith('_ids'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe if it ends in
This seems to be doing the same thing as |
||
new_kwargs = Collection.ids_to_objs(kwarg_key, kwarg_value) | ||
else: | ||
new_kwargs[kwarg_key] = kwarg_value | ||
data[self.sname] = new_kwargs | ||
|
||
response = self.pagerduty.request("POST", path, data=_json_dumper(data), extra_headers=extra_headers) | ||
return self.container(self, **response.get(self.sname, {})) | ||
|
||
@staticmethod | ||
def id_to_obj(key, value): | ||
new_key = key[:-3] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gmjosack I struggled with figuring out where to put the string slice. Originally I left it inside of the create function but found that hard to test. Putting it in both
My solution was to only do it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One option is to only pass values to these functions and worry about renaming the key in the outer function that I suggested. |
||
if key.endswith('_ids'): | ||
new_key = key[:-4] + "s" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any resources that end in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see anywhere where
compared to in v2:
|
||
return { | ||
"id": value, | ||
"type": new_key | ||
} | ||
|
||
@staticmethod | ||
def ids_to_objs(key, value): | ||
new_kwargs = [] | ||
for v in value: | ||
new_kwarg = Collection.id_to_obj(key, v) | ||
new_kwargs.append(new_kwarg) | ||
return new_kwargs | ||
|
||
def update(self, entity_id, **kwargs): | ||
path = "{0}/{1}".format(self.name, entity_id) | ||
if self.base_container: | ||
|
@@ -268,6 +295,9 @@ def update(self, entity_id, **kwargs): | |
|
||
|
||
class ScheduleUsers(Collection): | ||
"""This class exists because Users returned from a Schedule query are not | ||
paginated, whereas responses for Users class are. This causes a pagination | ||
bug if removed.""" | ||
name = 'users' | ||
paginated = False | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import absolute_import | ||
|
||
import pygerduty.v2 | ||
|
||
################### | ||
# Version 2 Tests # | ||
################### | ||
|
||
def test_id_to_obj(): | ||
|
||
kwarg = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these tabs for indents? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been having issues with my tabs, sometimes it does tabs = four spaces and other times it does not. I will check on it. |
||
"escalation_policy_id": "PIJ90N7", | ||
} | ||
|
||
new_kwarg = pygerduty.v2.Collection.id_to_obj("escalation_policy_id", kwarg["escalation_policy_id"]) | ||
|
||
assert new_kwarg == { | ||
"id": "PIJ90N7", | ||
"type": "escalation_policy" | ||
} | ||
|
||
|
||
def test_ids_to_objs(): | ||
|
||
kwarg = { | ||
"service_ids": [ | ||
"PF9KMXH", | ||
"PIJ90N7" | ||
] | ||
} | ||
|
||
new_kwargs = pygerduty.v2.Collection.ids_to_objs("service_ids", kwarg["service_ids"]) | ||
|
||
assert new_kwargs == [ | ||
{ | ||
"id": "PF9KMXH", | ||
"type": "services" | ||
}, | ||
{ | ||
"id": "PIJ90N7", | ||
"type": "services" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gmjosack Actually I just looked back and this is the reference thing we talked about before:
You said that you think it won't mind right? I will go ahead and change it to service if you think that will work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, pretty sure it happily takes either |
||
} | ||
] |
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.
Looks like you're overwriting new_kwargs here? Can you move this entire loop into a function and add a test for it to make sure we're not losing kwargs? The test should have kwargs that are and aren't transformed and test both id and ids types.