Closes #389 - Campaign API Helper Classes#652
Closes #389 - Campaign API Helper Classes#652kylesalk wants to merge 17 commits into
Conversation
These helper classes help generate the correct get/post request information through the `get()` method
A unix timestamp, datetime, or specified year/month/day/etc. are accepted and will all parse to a unix timestamp
These methods will allow optional notify Mail objects to be send on completion
datetime.timedelta does not have a "total_seconds" until python 2.7. By parsing seconds and days from the timedelta, the same can be achieved
Codecov Report
@@ Coverage Diff @@
## master #652 +/- ##
==========================================
- Coverage 84.77% 84.02% -0.76%
==========================================
Files 35 41 +6
Lines 1156 1377 +221
Branches 172 211 +39
==========================================
+ Hits 980 1157 +177
- Misses 90 118 +28
- Partials 86 102 +16
Continue to review full report at Codecov.
|
|
@thinkingserious - sorry about the opening/closing PRs. Not sure if there is a way to make commits after the PR, but the issues with earlier PRs should be fixed. Hope the campaign helpers will be useful. I did have some issues with the schedule API (/campaigns/{campaign_id}/schedules). It follows the API with a {"send_at": timestamp}, but is getting BAD REQUEST. Not sure how to troubleshoot... |
|
Hello @kylesalk, |
|
|
||
| @subject.setter | ||
| def subject(self, value): | ||
| if isinstance(value, str) or isinstance(value, type(None)): |
There was a problem hiding this comment.
Maybe use a tuple to merge these two checks into one?
>>> value = ''
>>> isinstance(value, str) or isinstance(value, type(None))
True
>>> value = None
>>> isinstance(value, str) or isinstance(value, type(None))
True
# use tuple
>>> value = ''
>>> isinstance(value, (str, type(None)))
True
>>> value = None
>>> isinstance(value, (str, type(None)))
True| "suppression_group_id": 5123 | ||
| } | ||
| camp = Campaign(**data) | ||
| self.assertDictEqual(camp.get(), data) |
There was a problem hiding this comment.
self.assertEqual takes care of this already?
(Just below this link)
The list of type-specific methods automatically used by assertEqual() are summarized in the following table. Note that it’s usually not necessary to invoke these methods directly.
| Method | Used to compare | New in |
|---|---|---|
| assertMultiLineEqual(a, b) | strings | 3.1 |
| assertSequenceEqual(a, b) | sequences | 3.1 |
| assertListEqual(a, b) | lists | 3.1 |
| assertTupleEqual(a, b) | tuples | 3.1 |
| assertSetEqual(a, b) | sets or frozensets | 3.1 |
| assertDictEqual(a, b) | dicts | 3.1 |
| "subject": "New Products for Fall!", | ||
| "title": "August Newsletter" | ||
| } | ||
| self.assertDictEqual(camp.patch(**new_data), new_data) |
| t_delta = datetime(2018, 12, 1, 8, 23) - datetime(1970, 1, 1) | ||
| unix_timestamp = t_delta.seconds + t_delta.days * 86400 | ||
| self.assertEqual(schedule.timestamp, unix_timestamp) | ||
| self.assertDictEqual(schedule.get(), {"send_at": unix_timestamp}) |
misterdorm
left a comment
There was a problem hiding this comment.
Please:
- address comments by @42B
- address code coverage CI failures
- rebase against the v4 branch instead of master.
Thanks!!
|
Hello @kylesalk, |
|
Closing until PR comments have been addressed. |
Fixes
Adds helper classes for campaigns
Closes #389
Checklist
Short description of what this PR does:
If you have questions, please send an email to SendGrid, or file a GitHub Issue in this repository.