Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Closes #389 - Campaign API Helper Classes#652

Closed
kylesalk wants to merge 17 commits into
sendgrid:mainsendgrid/sendgrid-python:mainfrom
kylesalk:masterkylesalk/sendgrid-python:masterCopy head branch name to clipboard
Closed

Closes #389 - Campaign API Helper Classes#652
kylesalk wants to merge 17 commits into
sendgrid:mainsendgrid/sendgrid-python:mainfrom
kylesalk:masterkylesalk/sendgrid-python:masterCopy head branch name to clipboard

Conversation

@kylesalk

@kylesalk kylesalk commented Oct 7, 2018

Copy link
Copy Markdown

Fixes

Adds helper classes for campaigns

Closes #389

Checklist

  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the [Contribution Guide] and my PR follows them.
  • I updated my branch with the master branch.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation about the functionality in the appropriate .md file
  • I have added in line documentation to the code I modified

Short description of what this PR does:

  • Added helper classes for campaign, campaigns, and campaign scheduling
  • Added utility functions for building, sending, and scheduling campaigns

If you have questions, please send an email to SendGrid, or file a GitHub Issue in this repository.

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
@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Oct 7, 2018
@codecov

codecov Bot commented Oct 7, 2018

Copy link
Copy Markdown

Codecov Report

Merging #652 into master will decrease coverage by 0.75%.
The diff coverage is 80.09%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
sendgrid/helpers/campaigns/__init__.py 100% <100%> (ø)
...grid/helpers/campaigns/campaign_build_scheduled.py 20% <20%> (ø)
sendgrid/helpers/campaigns/campaign_build_send.py 20% <20%> (ø)
sendgrid/helpers/campaigns/campaign_build.py 20% <20%> (ø)
sendgrid/helpers/campaigns/campaign.py 87.7% <87.7%> (ø)
sendgrid/helpers/campaigns/schedule.py 92.06% <92.06%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1627df7...65e52e7. Read the comment docs.

@kylesalk

kylesalk commented Oct 7, 2018

Copy link
Copy Markdown
Author

@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...

@kylesalk kylesalk changed the title Closes #389 Closes #389 - Campaign API Helper Classes Oct 8, 2018
@misterdorm misterdorm added status: work in progress Twilio or the community is in the process of implementing hacktoberfest difficulty: hard fix is hard in difficulty and removed status: code review request requesting a community code review or review from Twilio labels Oct 11, 2018
@thinkingserious thinkingserious added status: code review request requesting a community code review or review from Twilio type: community enhancement feature request not on Twilio's roadmap status: hacktoberfest approved and removed status: work in progress Twilio or the community is in the process of implementing labels Oct 23, 2018
@thinkingserious

Copy link
Copy Markdown
Contributor

Hello @kylesalk,

Thanks again for the PR!

It's HACKTOBERFEST! We want to show our appreciation by sending you some special Hacktoberfest swag. If you have not already, could you please fill out this form so we can send it to you? Thanks!

Team SendGrid DX


@subject.setter
def subject(self, value):
if isinstance(value, str) or isinstance(value, type(None)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread test/test_campaigns.py
"suppression_group_id": 5123
}
camp = Campaign(**data)
self.assertDictEqual(camp.get(), data)

@42B 42B Oct 27, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Test that two dictionaries are equal. If not, an error message is constructed that shows the differences in the dictionaries. This method will be used by default to compare dictionaries in calls to assertEqual().

Comment thread test/test_campaigns.py
"subject": "New Products for Fall!",
"title": "August Newsletter"
}
self.assertDictEqual(camp.patch(**new_data), new_data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same as above, self.assertEqual?

Comment thread test/test_campaigns.py
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})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

self.assertEqual?

@misterdorm misterdorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please:

  • address comments by @42B
  • address code coverage CI failures
  • rebase against the v4 branch instead of master.

Thanks!!

@misterdorm misterdorm added status: work in progress Twilio or the community is in the process of implementing and removed status: code review request requesting a community code review or review from Twilio labels Oct 30, 2018
@thinkingserious thinkingserious added status: waiting for feedback waiting for feedback from the submitter and removed status: work in progress Twilio or the community is in the process of implementing labels Oct 30, 2018
@thinkingserious

Copy link
Copy Markdown
Contributor

Hello @kylesalk,

Thanks again for the PR!

You have earned 7 out of the 5 points needed to receive glorious SendGrid Hacktoberfest swag.

Please take a moment to checkout this link to find more issues to get you past the required threshold or to simply continue the celebration.

Also, please be sure you have officially registered with us here by November 1, 2018 to qualify.

If you have any questions you can email us at dx+hacktoberfest2018@sendgrid.com.

Thank you and Happy Hacktobering!

Team SendGrid

@childish-sambino childish-sambino removed the type: community enhancement feature request not on Twilio's roadmap label Jul 20, 2020
@thinkingserious thinkingserious changed the base branch from master to main July 28, 2020 14:35
@childish-sambino

Copy link
Copy Markdown
Contributor

Closing until PR comments have been addressed.

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

Labels

difficulty: hard fix is hard in difficulty status: waiting for feedback waiting for feedback from the submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create and schedule a marketing campaign

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.