{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/comments/53607049","id":53607049,"diff_hunk":"@@ -0,0 +1,113 @@\n+import uuid\n+import datetime\n+import sys\n+import re\n+import time\n+import imaplib\n+import email as email_lib\n+import email.header\n+import pytest\n+from requests import session\n+from config import Config\n+from tests.utils import (retrieve_sms_with_wait,\n+                         delete_sms_messge,\n+                         find_csrf_token,\n+                         get_sms)\n+\n+\n+def _generate_unique_email(email, uuid_):\n+    parts = email.split('@')\n+    return \"{}+{}@{}\".format(parts[0], uuid_, parts[1])\n+\n+\n+def _get_sms_code(email):\n+    # Test will fail if there is not 1 message (we expect only 1 message)\n+    m = None\n+    try:\n+        messages = retrieve_sms_with_wait(email)\n+        assert len(messages) == 1, ('Expecting to retrieve 1 sms message in functional'\n+                                    ' test for user: {}').format(email)\n+        m = messages[0]\n+        return m.body\n+    finally:\n+        if m:\n+            delete_sms_messge(m.sid)\n+\n+\n+def _get_email_code(email, pwd, email_folder):\n+    timer = 0\n+    gimap = None\n+    while timer < Config.EMAIL_TIMEOUT:\n+        try:\n+            gimap = imaplib.IMAP4_SSL('imap.gmail.com')\n+            try:\n+                rv, data = gimap.login(email, pwd)\n+            except imaplib.IMAP4.error:\n+                    pytest.fail(\"Login to email account has failed.\")\n+            rv, data = gimap.select(email_folder)\n+            rv, data = gimap.search(None, \"ALL\")\n+            ids_count = len(data[0].split())\n+            if ids_count > 1:\n+                pytest.fail(\"There is more than token email\")\n+            elif ids_count == 1:\n+                num = data[0].split()[0]\n+                rv, data = gimap.fetch(num, '(UID BODY[TEXT])')\n+                msg = email_lib.message_from_bytes(data[0][1])\n+                gimap.store(num, '+FLAGS', '\\\\Deleted')\n+                gimap.expunge()\n+                return msg.get_payload().strip()","path":"tests/test_register_flow.py","position":58,"original_position":58,"commit_id":"d47dc045d9bfe17b92ba3692588536859c6a6fab","original_commit_id":"64d91566655a7669ca1ca778584b76bca5402a34","user":{"login":"quis","id":355079,"avatar_url":"https://avatars.githubusercontent.com/u/355079?v=3","gravatar_id":"","url":"https://api.github.com/users/quis","html_url":"https://github.com/quis","followers_url":"https://api.github.com/users/quis/followers","following_url":"https://api.github.com/users/quis/following{/other_user}","gists_url":"https://api.github.com/users/quis/gists{/gist_id}","starred_url":"https://api.github.com/users/quis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quis/subscriptions","organizations_url":"https://api.github.com/users/quis/orgs","repos_url":"https://api.github.com/users/quis/repos","events_url":"https://api.github.com/users/quis/events{/privacy}","received_events_url":"https://api.github.com/users/quis/received_events","type":"User","site_admin":false},"body":"eg\r\n\r\n**test.py**\r\n```python\r\nimport pytest\r\n\r\nclosed = False\r\n\r\ndef f():\r\n     try:\r\n         pytest.fail(\"fail\")\r\n     finally:\r\n         closed = True\r\n         \r\nassert closed\r\n```\r\n\r\n```shell\r\npy.test test.py\r\n>>> E   assert False\r\n```","created_at":"2016-02-22T10:24:47Z","updated_at":"2016-02-22T10:24:47Z","html_url":"https://github.com/alphagov/notifications-functional-tests/pull/4#discussion_r53607049","pull_request_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/comments/53607049"},"html":{"href":"https://github.com/alphagov/notifications-functional-tests/pull/4#discussion_r53607049"},"pull_request":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4","id":59527854,"html_url":"https://github.com/alphagov/notifications-functional-tests/pull/4","diff_url":"https://github.com/alphagov/notifications-functional-tests/pull/4.diff","patch_url":"https://github.com/alphagov/notifications-functional-tests/pull/4.patch","issue_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/4","number":4,"state":"open","locked":false,"title":"Registration flow","user":{"login":"mannickutd","id":1556623,"avatar_url":"https://avatars.githubusercontent.com/u/1556623?v=3","gravatar_id":"","url":"https://api.github.com/users/mannickutd","html_url":"https://github.com/mannickutd","followers_url":"https://api.github.com/users/mannickutd/followers","following_url":"https://api.github.com/users/mannickutd/following{/other_user}","gists_url":"https://api.github.com/users/mannickutd/gists{/gist_id}","starred_url":"https://api.github.com/users/mannickutd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mannickutd/subscriptions","organizations_url":"https://api.github.com/users/mannickutd/orgs","repos_url":"https://api.github.com/users/mannickutd/repos","events_url":"https://api.github.com/users/mannickutd/events{/privacy}","received_events_url":"https://api.github.com/users/mannickutd/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-16T17:51:01Z","updated_at":"2016-02-22T10:24:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"74e1fbade06a6511eb3076298a053aca4c9a5b3d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4/commits","review_comments_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4/comments","review_comment_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/4/comments","statuses_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/statuses/d47dc045d9bfe17b92ba3692588536859c6a6fab","head":{"label":"alphagov:registration_flow","ref":"registration_flow","sha":"d47dc045d9bfe17b92ba3692588536859c6a6fab","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":46422367,"name":"notifications-functional-tests","full_name":"alphagov/notifications-functional-tests","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/notifications-functional-tests","description":"Functional tests for Notify","fork":false,"url":"https://api.github.com/repos/alphagov/notifications-functional-tests","forks_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/forks","keys_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/teams","hooks_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/hooks","issue_events_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/events","assignees_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/tags","blobs_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/languages","stargazers_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/stargazers","contributors_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/contributors","subscribers_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/subscribers","subscription_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/subscription","commits_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/merges","archive_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/downloads","issues_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/deployments","created_at":"2015-11-18T14:01:37Z","updated_at":"2016-02-10T15:08:10Z","pushed_at":"2016-02-22T10:10:35Z","git_url":"git://github.com/alphagov/notifications-functional-tests.git","ssh_url":"git@github.com:alphagov/notifications-functional-tests.git","clone_url":"https://github.com/alphagov/notifications-functional-tests.git","svn_url":"https://github.com/alphagov/notifications-functional-tests","homepage":null,"size":59,"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":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"d5c516b199dc3e44a29cd58662fb1fd65fb7ad74","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":46422367,"name":"notifications-functional-tests","full_name":"alphagov/notifications-functional-tests","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/notifications-functional-tests","description":"Functional tests for Notify","fork":false,"url":"https://api.github.com/repos/alphagov/notifications-functional-tests","forks_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/forks","keys_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/teams","hooks_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/hooks","issue_events_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/events","assignees_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/tags","blobs_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/languages","stargazers_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/stargazers","contributors_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/contributors","subscribers_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/subscribers","subscription_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/subscription","commits_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/merges","archive_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/downloads","issues_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/notifications-functional-tests/deployments","created_at":"2015-11-18T14:01:37Z","updated_at":"2016-02-10T15:08:10Z","pushed_at":"2016-02-22T10:10:35Z","git_url":"git://github.com/alphagov/notifications-functional-tests.git","ssh_url":"git@github.com:alphagov/notifications-functional-tests.git","clone_url":"https://github.com/alphagov/notifications-functional-tests.git","svn_url":"https://github.com/alphagov/notifications-functional-tests","homepage":null,"size":59,"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":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4"},"html":{"href":"https://github.com/alphagov/notifications-functional-tests/pull/4"},"issue":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/4"},"comments":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/notifications-functional-tests/statuses/d47dc045d9bfe17b92ba3692588536859c6a6fab"}}}}