{"action":"created","comment":{"url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/comments/62246288","id":62246288,"diff_hunk":"@@ -0,0 +1,14 @@\n+from sailthru_import import sailthru_import\n+from sailthru.sailthru_client import SailthruClient\n+\n+import unittest\n+import mock\n+from mock import patch\n+\n+\n+@patch('sailthru.sailthru_client')\n+class SailThruTestCase(unittest.TestCase):\n+    def test_upload_csv_to_sailthru(self, mock_client):\n+        mock_client.return_value.api_get.response.body.status.return_value = \"completed\"\n+        mock_client.upload_csv_to_sailthru('test.csv', 'list name', 'bfohl@edx.org', mock_client)\n+        mock_client.upload_csv_to_sailthru.assert_called_once()","path":"sailthru_import/test/test_sailthru_import.py","position":14,"original_position":14,"commit_id":"250ddc0f8c1a2e6d531f5ed96ee6d040d002dd91","original_commit_id":"250ddc0f8c1a2e6d531f5ed96ee6d040d002dd91","user":{"login":"cpennington","id":30236,"avatar_url":"https://avatars.githubusercontent.com/u/30236?v=3","gravatar_id":"","url":"https://api.github.com/users/cpennington","html_url":"https://github.com/cpennington","followers_url":"https://api.github.com/users/cpennington/followers","following_url":"https://api.github.com/users/cpennington/following{/other_user}","gists_url":"https://api.github.com/users/cpennington/gists{/gist_id}","starred_url":"https://api.github.com/users/cpennington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpennington/subscriptions","organizations_url":"https://api.github.com/users/cpennington/orgs","repos_url":"https://api.github.com/users/cpennington/repos","events_url":"https://api.github.com/users/cpennington/events{/privacy}","received_events_url":"https://api.github.com/users/cpennington/received_events","type":"User","site_admin":false},"body":"As we talked about: use `sailthru_import.upload_csv_to_sailthru`, and then `mock_client.api_post.assert_called_once`.\r\n\r\nAlso, `assert_called_once_with(...)` will allow you to validate the arguments that are passed to sailthru.","created_at":"2016-05-05T20:08:08Z","updated_at":"2016-05-05T20:08:08Z","html_url":"https://github.com/edx/ecommerce-scripts/pull/3#discussion_r62246288","pull_request_url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/comments/62246288"},"html":{"href":"https://github.com/edx/ecommerce-scripts/pull/3#discussion_r62246288"},"pull_request":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3","id":68404189,"html_url":"https://github.com/edx/ecommerce-scripts/pull/3","diff_url":"https://github.com/edx/ecommerce-scripts/pull/3.diff","patch_url":"https://github.com/edx/ecommerce-scripts/pull/3.patch","issue_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues/3","number":3,"state":"open","locked":false,"title":"SailThru user import script","user":{"login":"brianfohl","id":121490,"avatar_url":"https://avatars.githubusercontent.com/u/121490?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfohl","html_url":"https://github.com/brianfohl","followers_url":"https://api.github.com/users/brianfohl/followers","following_url":"https://api.github.com/users/brianfohl/following{/other_user}","gists_url":"https://api.github.com/users/brianfohl/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfohl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfohl/subscriptions","organizations_url":"https://api.github.com/users/brianfohl/orgs","repos_url":"https://api.github.com/users/brianfohl/repos","events_url":"https://api.github.com/users/brianfohl/events{/privacy}","received_events_url":"https://api.github.com/users/brianfohl/received_events","type":"User","site_admin":false},"body":"Please advise on how to best write unit tests for these. The import script itself only has one function, which will upload a file into SailThru's API. There is no way to \"mock\" this or mark the import as only a test, so the users will actually get added in SailThru. We could add them to a dev-only list in the Dev account, and then make a GET call to verify the users added, but it's arguable this approach falls outside the scope of unit testing; as the processing of the import happens on SailThru's side. There would be dependency there which is outside of our codebase.\r\n\r\nIt could be possible to write a simple unit test for the CSV splitter script, but this would require mocking up user data in CSV and including that with the test file in GitHub.\r\n\r\nIn my opinion, these steps seem unnecessary for scripts which have already been functionally tested and will only need to be run a few times at most.\r\n\r\nIt should be noted that the auditing script also found in this repository does not have unit tests.","created_at":"2016-04-29T17:15:07Z","updated_at":"2016-05-05T20:08:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0592fe0c26d9b2a6007efbc5cb8b30b8d0b16f1d","assignee":{"login":"cpennington","id":30236,"avatar_url":"https://avatars.githubusercontent.com/u/30236?v=3","gravatar_id":"","url":"https://api.github.com/users/cpennington","html_url":"https://github.com/cpennington","followers_url":"https://api.github.com/users/cpennington/followers","following_url":"https://api.github.com/users/cpennington/following{/other_user}","gists_url":"https://api.github.com/users/cpennington/gists{/gist_id}","starred_url":"https://api.github.com/users/cpennington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpennington/subscriptions","organizations_url":"https://api.github.com/users/cpennington/orgs","repos_url":"https://api.github.com/users/cpennington/repos","events_url":"https://api.github.com/users/cpennington/events{/privacy}","received_events_url":"https://api.github.com/users/cpennington/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3/commits","review_comments_url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3/comments","review_comment_url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues/3/comments","statuses_url":"https://api.github.com/repos/edx/ecommerce-scripts/statuses/250ddc0f8c1a2e6d531f5ed96ee6d040d002dd91","head":{"label":"edx:sailthru_import","ref":"sailthru_import","sha":"250ddc0f8c1a2e6d531f5ed96ee6d040d002dd91","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":38325946,"name":"ecommerce-scripts","full_name":"edx/ecommerce-scripts","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce-scripts","description":"","fork":false,"url":"https://api.github.com/repos/edx/ecommerce-scripts","forks_url":"https://api.github.com/repos/edx/ecommerce-scripts/forks","keys_url":"https://api.github.com/repos/edx/ecommerce-scripts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce-scripts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce-scripts/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce-scripts/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce-scripts/events","assignees_url":"https://api.github.com/repos/edx/ecommerce-scripts/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce-scripts/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce-scripts/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce-scripts/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce-scripts/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce-scripts/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce-scripts/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce-scripts/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce-scripts/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce-scripts/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce-scripts/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce-scripts/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce-scripts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce-scripts/merges","archive_url":"https://api.github.com/repos/edx/ecommerce-scripts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce-scripts/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce-scripts/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce-scripts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce-scripts/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce-scripts/releases{/id}","deployments_url":"https://api.github.com/repos/edx/ecommerce-scripts/deployments","created_at":"2015-06-30T18:27:03Z","updated_at":"2016-04-14T14:20:11Z","pushed_at":"2016-05-05T15:32:06Z","git_url":"git://github.com/edx/ecommerce-scripts.git","ssh_url":"git@github.com:edx/ecommerce-scripts.git","clone_url":"https://github.com/edx/ecommerce-scripts.git","svn_url":"https://github.com/edx/ecommerce-scripts","homepage":null,"size":44,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"ff9d8935d68ae482266d6389af0bd2c0640c8a26","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":38325946,"name":"ecommerce-scripts","full_name":"edx/ecommerce-scripts","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce-scripts","description":"","fork":false,"url":"https://api.github.com/repos/edx/ecommerce-scripts","forks_url":"https://api.github.com/repos/edx/ecommerce-scripts/forks","keys_url":"https://api.github.com/repos/edx/ecommerce-scripts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce-scripts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce-scripts/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce-scripts/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce-scripts/events","assignees_url":"https://api.github.com/repos/edx/ecommerce-scripts/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce-scripts/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce-scripts/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce-scripts/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce-scripts/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce-scripts/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce-scripts/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce-scripts/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce-scripts/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce-scripts/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce-scripts/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce-scripts/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce-scripts/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce-scripts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce-scripts/merges","archive_url":"https://api.github.com/repos/edx/ecommerce-scripts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce-scripts/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce-scripts/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce-scripts/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce-scripts/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce-scripts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce-scripts/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce-scripts/releases{/id}","deployments_url":"https://api.github.com/repos/edx/ecommerce-scripts/deployments","created_at":"2015-06-30T18:27:03Z","updated_at":"2016-04-14T14:20:11Z","pushed_at":"2016-05-05T15:32:06Z","git_url":"git://github.com/edx/ecommerce-scripts.git","ssh_url":"git@github.com:edx/ecommerce-scripts.git","clone_url":"https://github.com/edx/ecommerce-scripts.git","svn_url":"https://github.com/edx/ecommerce-scripts","homepage":null,"size":44,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3"},"html":{"href":"https://github.com/edx/ecommerce-scripts/pull/3"},"issue":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/issues/3"},"comments":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/edx/ecommerce-scripts/statuses/250ddc0f8c1a2e6d531f5ed96ee6d040d002dd91"}}}}