{"action":"created","comment":{"url":"https://api.github.com/repos/praekelt/junebug/pulls/comments/38204692","id":38204692,"diff_hunk":"@@ -0,0 +1,96 @@\n+from copy import deepcopy\n+import logging\n+from twisted.internet.defer import inlineCallbacks, returnValue\n+from twisted.trial.unittest import TestCase\n+from vumi.tests.helpers import PersistenceHelper, WorkerHelper\n+\n+from junebug.channel import Channel\n+from junebug.service import JunebugService\n+\n+\n+class JunebugTestBase(TestCase):\n+    '''Base test case that all junebug tests inherit from. Contains useful\n+    helper functions'''\n+\n+    default_channel_config = {\n+        'type': 'telnet',\n+        'config': {\n+            'transport_name': 'dummy_transport1',\n+            'twisted_endpoint': 'tcp:0',\n+        },\n+        'mo_url': 'http://foo.bar',\n+    }\n+\n+    def patch_logger(self):\n+        ''' Patches the logger with an in-memory logger, which is acccessable\n+        at \"self.logging_handler\".'''\n+        self.logging_handler = logging.handlers.MemoryHandler(100)\n+        logging.getLogger().addHandler(self.logging_handler)\n+        self.addCleanup(self._cleanup_logging_patch)\n+\n+    def _cleanup_logging_patch(self):\n+        self.logging_handler.close()\n+        logging.getLogger().removeHandler(self.logging_handler)\n+\n+    @inlineCallbacks\n+    def create_channel(\n+            self, service, redis, transport_class,\n+            config=default_channel_config, id=None):\n+        '''Creates and starts, and saves a channel, with a\n+        TelnetServerTransport transport'''\n+        config = deepcopy(config)\n+        channel = Channel(redis._config, {}, config, id=id)\n+        config['config']['worker_name'] = channel.id\n+        transport_worker = yield WorkerHelper().get_worker(\n+            transport_class, config['config'])\n+        yield channel.start(self.service, transport_worker)\n+        yield channel.save()\n+        self.addCleanup(channel.stop)\n+        returnValue(channel)\n+\n+    def create_channel_from_id(self, service, redis, id):\n+        '''Creates an existing channel given the channel id'''\n+        return Channel.from_id(redis._config, {}, id, service)\n+\n+    @inlineCallbacks\n+    def get_redis(self):\n+        '''Creates and returns a redis manager'''\n+        if hasattr(self, 'redis'):\n+            returnValue(self.redis)\n+        persistencehelper = PersistenceHelper()\n+        yield persistencehelper.setup()","path":"junebug/tests/helpers.py","position":61,"original_position":61,"commit_id":"c3d9116fa6ffb27af5e05f493f2ea4845f68a416","original_commit_id":"d785a714d12abb4b4340dbd90142f05e5e92cce8","user":{"login":"hodgestar","id":165551,"avatar_url":"https://avatars.githubusercontent.com/u/165551?v=3","gravatar_id":"","url":"https://api.github.com/users/hodgestar","html_url":"https://github.com/hodgestar","followers_url":"https://api.github.com/users/hodgestar/followers","following_url":"https://api.github.com/users/hodgestar/following{/other_user}","gists_url":"https://api.github.com/users/hodgestar/gists{/gist_id}","starred_url":"https://api.github.com/users/hodgestar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hodgestar/subscriptions","organizations_url":"https://api.github.com/users/hodgestar/orgs","repos_url":"https://api.github.com/users/hodgestar/repos","events_url":"https://api.github.com/users/hodgestar/events{/privacy}","received_events_url":"https://api.github.com/users/hodgestar/received_events","type":"User","site_admin":false},"body":"We should add `persistencehelper.cleanup` as a clean up function.","created_at":"2015-08-28T14:25:22Z","updated_at":"2015-08-28T14:25:22Z","html_url":"https://github.com/praekelt/junebug/pull/7#discussion_r38204692","pull_request_url":"https://api.github.com/repos/praekelt/junebug/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/praekelt/junebug/pulls/comments/38204692"},"html":{"href":"https://github.com/praekelt/junebug/pull/7#discussion_r38204692"},"pull_request":{"href":"https://api.github.com/repos/praekelt/junebug/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/praekelt/junebug/pulls/7","id":43382132,"html_url":"https://github.com/praekelt/junebug/pull/7","diff_url":"https://github.com/praekelt/junebug/pull/7.diff","patch_url":"https://github.com/praekelt/junebug/pull/7.patch","issue_url":"https://api.github.com/repos/praekelt/junebug/issues/7","number":7,"state":"open","locked":false,"title":"Twisted parent and child services","user":{"login":"rudigiesler","id":8234653,"avatar_url":"https://avatars.githubusercontent.com/u/8234653?v=3","gravatar_id":"","url":"https://api.github.com/users/rudigiesler","html_url":"https://github.com/rudigiesler","followers_url":"https://api.github.com/users/rudigiesler/followers","following_url":"https://api.github.com/users/rudigiesler/following{/other_user}","gists_url":"https://api.github.com/users/rudigiesler/gists{/gist_id}","starred_url":"https://api.github.com/users/rudigiesler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudigiesler/subscriptions","organizations_url":"https://api.github.com/users/rudigiesler/orgs","repos_url":"https://api.github.com/users/rudigiesler/repos","events_url":"https://api.github.com/users/rudigiesler/events{/privacy}","received_events_url":"https://api.github.com/users/rudigiesler/received_events","type":"User","site_admin":false},"body":"Have the junebug API run as a twisted multiservice, and add the machinery to launch transports as child services of the API.","created_at":"2015-08-26T09:38:03Z","updated_at":"2015-08-28T14:25:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c8e8660d9e04c3fb0b3134428b139e54b071fb8a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/praekelt/junebug/pulls/7/commits","review_comments_url":"https://api.github.com/repos/praekelt/junebug/pulls/7/comments","review_comment_url":"https://api.github.com/repos/praekelt/junebug/pulls/comments{/number}","comments_url":"https://api.github.com/repos/praekelt/junebug/issues/7/comments","statuses_url":"https://api.github.com/repos/praekelt/junebug/statuses/c3d9116fa6ffb27af5e05f493f2ea4845f68a416","head":{"label":"praekelt:feature/issue-7-twisted-parent-and-child-services","ref":"feature/issue-7-twisted-parent-and-child-services","sha":"c3d9116fa6ffb27af5e05f493f2ea4845f68a416","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":37322817,"name":"junebug","full_name":"praekelt/junebug","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/junebug","description":"A system for managing text messaging transports with via RESTful HTTP interface.","fork":false,"url":"https://api.github.com/repos/praekelt/junebug","forks_url":"https://api.github.com/repos/praekelt/junebug/forks","keys_url":"https://api.github.com/repos/praekelt/junebug/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/junebug/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/junebug/teams","hooks_url":"https://api.github.com/repos/praekelt/junebug/hooks","issue_events_url":"https://api.github.com/repos/praekelt/junebug/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/junebug/events","assignees_url":"https://api.github.com/repos/praekelt/junebug/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/junebug/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/junebug/tags","blobs_url":"https://api.github.com/repos/praekelt/junebug/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/junebug/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/junebug/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/junebug/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/junebug/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/junebug/languages","stargazers_url":"https://api.github.com/repos/praekelt/junebug/stargazers","contributors_url":"https://api.github.com/repos/praekelt/junebug/contributors","subscribers_url":"https://api.github.com/repos/praekelt/junebug/subscribers","subscription_url":"https://api.github.com/repos/praekelt/junebug/subscription","commits_url":"https://api.github.com/repos/praekelt/junebug/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/junebug/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/junebug/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/junebug/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/junebug/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/junebug/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/junebug/merges","archive_url":"https://api.github.com/repos/praekelt/junebug/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/junebug/downloads","issues_url":"https://api.github.com/repos/praekelt/junebug/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/junebug/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/junebug/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/junebug/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/junebug/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/junebug/releases{/id}","created_at":"2015-06-12T13:15:21Z","updated_at":"2015-08-13T11:50:17Z","pushed_at":"2015-08-28T12:49:52Z","git_url":"git://github.com/praekelt/junebug.git","ssh_url":"git@github.com:praekelt/junebug.git","clone_url":"https://github.com/praekelt/junebug.git","svn_url":"https://github.com/praekelt/junebug","homepage":null,"size":332,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"praekelt:develop","ref":"develop","sha":"05f91eb6883bbc2e77c673b868cbfd0a0a6a413a","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":37322817,"name":"junebug","full_name":"praekelt/junebug","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/junebug","description":"A system for managing text messaging transports with via RESTful HTTP interface.","fork":false,"url":"https://api.github.com/repos/praekelt/junebug","forks_url":"https://api.github.com/repos/praekelt/junebug/forks","keys_url":"https://api.github.com/repos/praekelt/junebug/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/junebug/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/junebug/teams","hooks_url":"https://api.github.com/repos/praekelt/junebug/hooks","issue_events_url":"https://api.github.com/repos/praekelt/junebug/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/junebug/events","assignees_url":"https://api.github.com/repos/praekelt/junebug/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/junebug/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/junebug/tags","blobs_url":"https://api.github.com/repos/praekelt/junebug/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/junebug/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/junebug/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/junebug/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/junebug/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/junebug/languages","stargazers_url":"https://api.github.com/repos/praekelt/junebug/stargazers","contributors_url":"https://api.github.com/repos/praekelt/junebug/contributors","subscribers_url":"https://api.github.com/repos/praekelt/junebug/subscribers","subscription_url":"https://api.github.com/repos/praekelt/junebug/subscription","commits_url":"https://api.github.com/repos/praekelt/junebug/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/junebug/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/junebug/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/junebug/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/junebug/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/junebug/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/junebug/merges","archive_url":"https://api.github.com/repos/praekelt/junebug/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/junebug/downloads","issues_url":"https://api.github.com/repos/praekelt/junebug/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/junebug/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/junebug/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/junebug/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/junebug/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/junebug/releases{/id}","created_at":"2015-06-12T13:15:21Z","updated_at":"2015-08-13T11:50:17Z","pushed_at":"2015-08-28T12:49:52Z","git_url":"git://github.com/praekelt/junebug.git","ssh_url":"git@github.com:praekelt/junebug.git","clone_url":"https://github.com/praekelt/junebug.git","svn_url":"https://github.com/praekelt/junebug","homepage":null,"size":332,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/praekelt/junebug/pulls/7"},"html":{"href":"https://github.com/praekelt/junebug/pull/7"},"issue":{"href":"https://api.github.com/repos/praekelt/junebug/issues/7"},"comments":{"href":"https://api.github.com/repos/praekelt/junebug/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/praekelt/junebug/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/praekelt/junebug/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/praekelt/junebug/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/praekelt/junebug/statuses/c3d9116fa6ffb27af5e05f493f2ea4845f68a416"}}}}