{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/35037730","id":35037730,"diff_hunk":"@@ -0,0 +1,226 @@\n+\"\"\"\n+Ensure we can write to Vertica data sources.\n+\"\"\"\n+from __future__ import absolute_import\n+\n+import textwrap\n+\n+import luigi\n+import luigi.task\n+\n+from mock import call\n+from mock import MagicMock\n+from mock import patch\n+from mock import sentinel\n+\n+from edx.analytics.tasks.vertica_load import VerticaCopyTask\n+from edx.analytics.tasks.tests import unittest\n+from edx.analytics.tasks.tests.target import FakeTarget\n+from edx.analytics.tasks.tests.config import with_luigi_config\n+\n+\n+class CopyToVerticaDummyTable(VerticaCopyTask):\n+    \"\"\"\n+    Define table for testing.\n+    \"\"\"\n+    @property\n+    def table(self):\n+        return \"dummy_table\"\n+\n+    @property\n+    def columns(self):\n+        return [\n+            ('course_id', 'VARCHAR(255)'),\n+            ('interval_start', 'DATETIME'),\n+            ('interval_end', 'DATETIME'),\n+            ('label', 'VARCHAR(255)'),\n+            ('count', 'INT'),\n+        ]\n+\n+    @property\n+    def insert_source_task(self):\n+        return None\n+\n+\n+class CopyToPredefinedVerticaDummyTable(CopyToVerticaDummyTable):\n+    \"\"\"\n+    Define table for testing without definitions (since table is externally defined).\n+    \"\"\"\n+\n+    @property\n+    def columns(self):\n+        return ['course_id', 'interval_start', 'interval_end', 'label', 'count']\n+\n+\n+class VerticaCopyTaskTest(unittest.TestCase):\n+    \"\"\"\n+    Ensure we can connect to and write data to Vertica data sources.\n+    \"\"\"\n+\n+    def setUp(self):\n+        patcher = patch('edx.analytics.tasks.vertica_load.vertica_python.vertica')\n+        self.mock_vertica_connector = patcher.start()\n+        self.addCleanup(patcher.stop)\n+\n+    def create_task(self, credentials=None, source=None, overwrite=False, cls=CopyToVerticaDummyTable):\n+        \"\"\"\n+         Emulate execution of a generic VerticaTask.\n+        \"\"\"\n+        # Make sure to flush the instance cache so we create\n+        # a new task object.\n+        luigi.task.Register.clear_instance_cache()\n+        task = cls(\n+            credentials=sentinel.ignored,\n+            overwrite=overwrite\n+        )\n+\n+        if not credentials:\n+            credentials = '''\\\n+                {\n+                    \"host\": \"db.example.com\",\n+                    \"port\": 5433,\n+                    \"user\": \"exampleuser\",\n+                    \"password\": \"example password\"\n+                }'''\n+\n+        if not source:\n+            source = self._get_source_string(1)\n+\n+        fake_input = {\n+            'credentials': FakeTarget(textwrap.dedent(credentials)),\n+            'insert_source': FakeTarget(textwrap.dedent(source))\n+        }\n+\n+        fake_output = MagicMock(return_value=self.mock_vertica_connector)\n+\n+        task.input = MagicMock(return_value=fake_input)\n+        task.output = fake_output\n+        return task\n+\n+    def test_run_with_default_credentials(self):\n+        self.create_task(credentials='{}').run()\n+\n+    @with_luigi_config('vertica-export', 'schema', 'foobar')\n+    def test_parameters_from_config(self):\n+        task = CopyToVerticaDummyTable(credentials=sentinel.credentials)\n+        self.assertEquals(task.schema, 'foobar')\n+\n+    def test_run(self):\n+        self.create_task().run()\n+        mock_conn = self.mock_vertica_connector.connect()\n+        self.assertTrue(mock_conn.cursor().execute.called)\n+        self.assertFalse(mock_conn.rollback.called)\n+        self.assertTrue(mock_conn.commit.called)\n+        self.assertTrue(mock_conn.close.called)\n+\n+    def test_run_with_failure(self):\n+        task = self.create_task()\n+        task.output().touch = MagicMock(side_effect=Exception(\"Failed to update marker\"))\n+        with self.assertRaises(Exception):\n+            task.run()\n+        mock_conn = self.mock_vertica_connector.connect()\n+        self.assertTrue(mock_conn.cursor().execute.called)\n+        self.assertTrue(mock_conn.rollback.called)\n+        self.assertFalse(mock_conn.commit.called)\n+        self.assertTrue(mock_conn.close.called)\n+\n+    def test_create_table(self):\n+        connection = MagicMock()\n+        self.create_task().create_table(connection)\n+        connection.cursor().execute.assert_called_once_with(\n+            \"CREATE TABLE IF NOT EXISTS testing.dummy_table \"\n+            \"(id AUTO_INCREMENT PRIMARY KEY,course_id VARCHAR(255),\"\n+            \"interval_start DATETIME,interval_end DATETIME,label VARCHAR(255),\"\n+            \"count INT,created TIMESTAMP DEFAULT NOW(),PRIMARY KEY (id))\"\n+        )\n+\n+    def test_create_table_without_column_definition(self):\n+        connection = MagicMock()\n+        task = self.create_task(cls=CopyToPredefinedVerticaDummyTable)\n+        with self.assertRaises(NotImplementedError):","path":"edx/analytics/tasks/tests/test_vertica_load.py","position":140,"original_position":140,"commit_id":"6caadce3a93d83b020012a7a3c089d1e70397ca2","original_commit_id":"1d1af234e41c1686d3e65ae595dd57d190d1473c","user":{"login":"brianhw","id":2534095,"avatar_url":"https://avatars.githubusercontent.com/u/2534095?v=3","gravatar_id":"","url":"https://api.github.com/users/brianhw","html_url":"https://github.com/brianhw","followers_url":"https://api.github.com/users/brianhw/followers","following_url":"https://api.github.com/users/brianhw/following{/other_user}","gists_url":"https://api.github.com/users/brianhw/gists{/gist_id}","starred_url":"https://api.github.com/users/brianhw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianhw/subscriptions","organizations_url":"https://api.github.com/users/brianhw/orgs","repos_url":"https://api.github.com/users/brianhw/repos","events_url":"https://api.github.com/users/brianhw/events{/privacy}","received_events_url":"https://api.github.com/users/brianhw/received_events","type":"User","site_admin":false},"body":"nit: should this also check the error message to clarify the right error is occurring?  (e.g table vs column).  There's a regexp version of assertRaises that does this...","created_at":"2015-07-20T20:09:04Z","updated_at":"2015-07-20T20:09:04Z","html_url":"https://github.com/edx/edx-analytics-pipeline/pull/125#discussion_r35037730","pull_request_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/35037730"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/125#discussion_r35037730"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125","id":38485056,"html_url":"https://github.com/edx/edx-analytics-pipeline/pull/125","diff_url":"https://github.com/edx/edx-analytics-pipeline/pull/125.diff","patch_url":"https://github.com/edx/edx-analytics-pipeline/pull/125.patch","issue_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/125","number":125,"state":"open","locked":false,"title":"Jamesrowan/course subject integration","user":{"login":"jrowan","id":5571464,"avatar_url":"https://avatars.githubusercontent.com/u/5571464?v=3","gravatar_id":"","url":"https://api.github.com/users/jrowan","html_url":"https://github.com/jrowan","followers_url":"https://api.github.com/users/jrowan/followers","following_url":"https://api.github.com/users/jrowan/following{/other_user}","gists_url":"https://api.github.com/users/jrowan/gists{/gist_id}","starred_url":"https://api.github.com/users/jrowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrowan/subscriptions","organizations_url":"https://api.github.com/users/jrowan/orgs","repos_url":"https://api.github.com/users/jrowan/repos","events_url":"https://api.github.com/users/jrowan/events{/privacy}","received_events_url":"https://api.github.com/users/jrowan/received_events","type":"User","site_admin":false},"body":"Adds pipeline functionality to pull the course subjects information from drupal, store that information on s3, and then load that information into the Vertica data warehouse.  The Vertica luigi target class and Vertica bulkloading luigi task class, modeled off the corresponding mysql tasks, should be usable for other data warehouse loading tasks as well.\r\n\r\n@jab5569 @brianhw @mulby ","created_at":"2015-06-24T20:40:53Z","updated_at":"2015-07-20T20:09:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aaf163afcda21a6171fb2876bdf50bfee58d4bf3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125/commits","review_comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125/comments","review_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/125/comments","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/6caadce3a93d83b020012a7a3c089d1e70397ca2","head":{"label":"edx:jamesrowan/course-subject-integration","ref":"jamesrowan/course-subject-integration","sha":"6caadce3a93d83b020012a7a3c089d1e70397ca2","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":22929261,"name":"edx-analytics-pipeline","full_name":"edx/edx-analytics-pipeline","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/edx-analytics-pipeline","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/releases{/id}","created_at":"2014-08-13T19:57:17Z","updated_at":"2015-04-30T01:54:29Z","pushed_at":"2015-07-20T20:05:35Z","git_url":"git://github.com/edx/edx-analytics-pipeline.git","ssh_url":"git@github.com:edx/edx-analytics-pipeline.git","clone_url":"https://github.com/edx/edx-analytics-pipeline.git","svn_url":"https://github.com/edx/edx-analytics-pipeline","homepage":null,"size":5534,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":12,"forks":21,"open_issues":12,"watchers":7,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"67c3615c0673411a97b7f12061e95feaddac32a2","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":22929261,"name":"edx-analytics-pipeline","full_name":"edx/edx-analytics-pipeline","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/edx-analytics-pipeline","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/releases{/id}","created_at":"2014-08-13T19:57:17Z","updated_at":"2015-04-30T01:54:29Z","pushed_at":"2015-07-20T20:05:35Z","git_url":"git://github.com/edx/edx-analytics-pipeline.git","ssh_url":"git@github.com:edx/edx-analytics-pipeline.git","clone_url":"https://github.com/edx/edx-analytics-pipeline.git","svn_url":"https://github.com/edx/edx-analytics-pipeline","homepage":null,"size":5534,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":12,"forks":21,"open_issues":12,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/125"},"issue":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/125"},"comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/125/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/125/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/6caadce3a93d83b020012a7a3c089d1e70397ca2"}}}}