{"action":"created","comment":{"url":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments/69396090","id":69396090,"diff_hunk":"@@ -0,0 +1,477 @@\n+# This Python file uses the following encoding: utf-8\n+import unittest\n+import bcrypt\n+import arrow\n+import web\n+import ast\n+\n+import db_utils\n+from weasyl import login, macro\n+from weasyl import define as d\n+from weasyl.error import WeasylError\n+\n+# Main test account\n+raw_password = \"0123456789\"\n+bcrypt_hash = login.passhash(raw_password)\n+old_2a_bcrypt_hash = \"$2a$12$qReI924/8pAsoHu6aRTX2ejyujAZ/9FiOOtrjczBIwf8wqXAJ22N.\"\n+\n+class Bag(object):\n+    def __init__(self, **kw):\n+        for kv in kw.items():\n+            setattr(self, *kv)\n+\n+class SigninTestCase(unittest.TestCase):\n+    def testVerifyLoginRecordIsUpdated(self):\n+        user_id = db_utils.create_user(username='testloginsuite')\n+        d.execute(\"UPDATE login SET last_login = '-1' WHERE userid = %i\", [user_id])\n+        # login.signin(user_id) -will- raise an AttributeError when d.web.ctx.weasyl_session\n+        #   tries to execute itself; so catch/handle\n+        try:\n+            login.signin(user_id)\n+        except AttributeError:\n+            print 'Caught AttributeError, as expected'\n+        query = d.execute(\"SELECT last_login FROM login WHERE userid = %i\", [user_id])\n+        self.assertGreater(query[0][0], -1)\n+        d.execute(\"DELETE FROM login WHERE userid = %i\", [user_id])\n+\n+class AuthenticateBcryptTestCase(unittest.TestCase):\n+    def testNoUsernameProvided(self):\n+        result = login.authenticate_bcrypt(username='', password='password')\n+        self.assertTrue(result[0] == 0)\n+        self.assertTrue(result[1] == 'invalid')\n+\n+    def testNoPasswordProvided(self):\n+        result = login.authenticate_bcrypt(username='testloginsuite', password='')\n+        self.assertTrue(result[0] == 0)\n+        self.assertTrue(result[1] == 'invalid')\n+\n+    def testInvalidUsernameProvided(self):\n+        result = login.authenticate_bcrypt(username='InvalidUsername', password=raw_password)\n+        self.assertTrue(result[0] == 0)\n+        self.assertTrue(result[1] == 'invalid')\n+\n+    def testLoginFailsForModsWithInvalidAuthentication(self):\n+        log_path = '%s%s.%s.log' % (macro.MACRO_SYS_LOG_PATH, 'login.fail', d.get_timestamp())\n+        open(log_path, 'w').close()\n+        mod_userid = 2061\n+        user_id = db_utils.create_user(username='ikani')\n+        d.execute(\"UPDATE login SET userid = %i WHERE userid = %i\", [mod_userid, user_id])\n+        user_id = mod_userid\n+        d.execute(\"INSERT INTO authbcrypt VALUES (%i, '%s')\", [user_id, login.passhash(raw_password)])\n+        result = login.authenticate_bcrypt(username='ikani', password='FakePassword')\n+        # Verify we are writing to the log file as expected\n+        last_line = ''\n+        with open(log_path, 'r') as log:\n+            for line in log:\n+                pass\n+            last_line = line\n+        last_line_dict = ast.literal_eval(last_line)","path":"weasyl/test/test_login.py","position":68,"original_position":68,"commit_id":"5093a9afb5ffd1e532996ee14fa779f338069024","original_commit_id":"5093a9afb5ffd1e532996ee14fa779f338069024","user":{"login":"weykent","id":2894801,"avatar_url":"https://avatars.githubusercontent.com/u/2894801?v=3","gravatar_id":"","url":"https://api.github.com/users/weykent","html_url":"https://github.com/weykent","followers_url":"https://api.github.com/users/weykent/followers","following_url":"https://api.github.com/users/weykent/following{/other_user}","gists_url":"https://api.github.com/users/weykent/gists{/gist_id}","starred_url":"https://api.github.com/users/weykent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weykent/subscriptions","organizations_url":"https://api.github.com/users/weykent/orgs","repos_url":"https://api.github.com/users/weykent/repos","events_url":"https://api.github.com/users/weykent/events{/privacy}","received_events_url":"https://api.github.com/users/weykent/received_events","type":"User","site_admin":false},"body":"Yipes! The log is json, so you should read it with a json parser.","created_at":"2016-07-03T19:14:59Z","updated_at":"2016-07-03T19:14:59Z","html_url":"https://github.com/Weasyl/weasyl/pull/92#discussion_r69396090","pull_request_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/92","_links":{"self":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments/69396090"},"html":{"href":"https://github.com/Weasyl/weasyl/pull/92#discussion_r69396090"},"pull_request":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/92"}}},"pull_request":{"url":"https://api.github.com/repos/Weasyl/weasyl/pulls/92","id":76079335,"html_url":"https://github.com/Weasyl/weasyl/pull/92","diff_url":"https://github.com/Weasyl/weasyl/pull/92.diff","patch_url":"https://github.com/Weasyl/weasyl/pull/92.patch","issue_url":"https://api.github.com/repos/Weasyl/weasyl/issues/92","number":92,"state":"open","locked":false,"title":"Enhance Unit Tests","user":{"login":"kfkitsune","id":19718911,"avatar_url":"https://avatars.githubusercontent.com/u/19718911?v=3","gravatar_id":"","url":"https://api.github.com/users/kfkitsune","html_url":"https://github.com/kfkitsune","followers_url":"https://api.github.com/users/kfkitsune/followers","following_url":"https://api.github.com/users/kfkitsune/following{/other_user}","gists_url":"https://api.github.com/users/kfkitsune/gists{/gist_id}","starred_url":"https://api.github.com/users/kfkitsune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kfkitsune/subscriptions","organizations_url":"https://api.github.com/users/kfkitsune/orgs","repos_url":"https://api.github.com/users/kfkitsune/repos","events_url":"https://api.github.com/users/kfkitsune/events{/privacy}","received_events_url":"https://api.github.com/users/kfkitsune/received_events","type":"User","site_admin":false},"body":"TODO:\r\n\r\n- [x] Enhance ``weasyl/login.py``'s unit tests.\r\n- [ ] Write tests for ``weasyl/useralias.py`` (coverage before: 0%)\r\n\r\n----\r\nRenames ``weasyl/test/test_utilities.py`` to ``weasyl/test/test_login.py``; GH detects this as a delete/create.\r\n\r\nAdds as many unit tests as possible for ``login.py``, bringing the coverage for this file per my Codecov account to 89.51%, versus 18.81% currently on the master branch. Unfortunately, I couldn't figure out how to get the ``unicode-error`` branch of ``authenticate_bcrypt`` to trigger, but I did leave the commented out structure for this test.\r\n\r\nFixes ``weasyl/login.py:def sessionid(userid)``. The table ``usersession`` does not exist; substituted in the ``sessions`` table for this query. This was detected during creation of the unit tests.","created_at":"2016-07-03T02:39:21Z","updated_at":"2016-07-03T19:14:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"63bc3ac5734d0723fe9e4632a477a0de0450e8ca","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/92/commits","review_comments_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/92/comments","review_comment_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Weasyl/weasyl/issues/92/comments","statuses_url":"https://api.github.com/repos/Weasyl/weasyl/statuses/5093a9afb5ffd1e532996ee14fa779f338069024","head":{"label":"kfkitsune:add-more-unittests","ref":"add-more-unittests","sha":"5093a9afb5ffd1e532996ee14fa779f338069024","user":{"login":"kfkitsune","id":19718911,"avatar_url":"https://avatars.githubusercontent.com/u/19718911?v=3","gravatar_id":"","url":"https://api.github.com/users/kfkitsune","html_url":"https://github.com/kfkitsune","followers_url":"https://api.github.com/users/kfkitsune/followers","following_url":"https://api.github.com/users/kfkitsune/following{/other_user}","gists_url":"https://api.github.com/users/kfkitsune/gists{/gist_id}","starred_url":"https://api.github.com/users/kfkitsune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kfkitsune/subscriptions","organizations_url":"https://api.github.com/users/kfkitsune/orgs","repos_url":"https://api.github.com/users/kfkitsune/repos","events_url":"https://api.github.com/users/kfkitsune/events{/privacy}","received_events_url":"https://api.github.com/users/kfkitsune/received_events","type":"User","site_admin":false},"repo":{"id":60300859,"name":"weasyl","full_name":"kfkitsune/weasyl","owner":{"login":"kfkitsune","id":19718911,"avatar_url":"https://avatars.githubusercontent.com/u/19718911?v=3","gravatar_id":"","url":"https://api.github.com/users/kfkitsune","html_url":"https://github.com/kfkitsune","followers_url":"https://api.github.com/users/kfkitsune/followers","following_url":"https://api.github.com/users/kfkitsune/following{/other_user}","gists_url":"https://api.github.com/users/kfkitsune/gists{/gist_id}","starred_url":"https://api.github.com/users/kfkitsune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kfkitsune/subscriptions","organizations_url":"https://api.github.com/users/kfkitsune/orgs","repos_url":"https://api.github.com/users/kfkitsune/repos","events_url":"https://api.github.com/users/kfkitsune/events{/privacy}","received_events_url":"https://api.github.com/users/kfkitsune/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kfkitsune/weasyl","description":"The website.","fork":true,"url":"https://api.github.com/repos/kfkitsune/weasyl","forks_url":"https://api.github.com/repos/kfkitsune/weasyl/forks","keys_url":"https://api.github.com/repos/kfkitsune/weasyl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kfkitsune/weasyl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kfkitsune/weasyl/teams","hooks_url":"https://api.github.com/repos/kfkitsune/weasyl/hooks","issue_events_url":"https://api.github.com/repos/kfkitsune/weasyl/issues/events{/number}","events_url":"https://api.github.com/repos/kfkitsune/weasyl/events","assignees_url":"https://api.github.com/repos/kfkitsune/weasyl/assignees{/user}","branches_url":"https://api.github.com/repos/kfkitsune/weasyl/branches{/branch}","tags_url":"https://api.github.com/repos/kfkitsune/weasyl/tags","blobs_url":"https://api.github.com/repos/kfkitsune/weasyl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kfkitsune/weasyl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kfkitsune/weasyl/git/refs{/sha}","trees_url":"https://api.github.com/repos/kfkitsune/weasyl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kfkitsune/weasyl/statuses/{sha}","languages_url":"https://api.github.com/repos/kfkitsune/weasyl/languages","stargazers_url":"https://api.github.com/repos/kfkitsune/weasyl/stargazers","contributors_url":"https://api.github.com/repos/kfkitsune/weasyl/contributors","subscribers_url":"https://api.github.com/repos/kfkitsune/weasyl/subscribers","subscription_url":"https://api.github.com/repos/kfkitsune/weasyl/subscription","commits_url":"https://api.github.com/repos/kfkitsune/weasyl/commits{/sha}","git_commits_url":"https://api.github.com/repos/kfkitsune/weasyl/git/commits{/sha}","comments_url":"https://api.github.com/repos/kfkitsune/weasyl/comments{/number}","issue_comment_url":"https://api.github.com/repos/kfkitsune/weasyl/issues/comments{/number}","contents_url":"https://api.github.com/repos/kfkitsune/weasyl/contents/{+path}","compare_url":"https://api.github.com/repos/kfkitsune/weasyl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kfkitsune/weasyl/merges","archive_url":"https://api.github.com/repos/kfkitsune/weasyl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kfkitsune/weasyl/downloads","issues_url":"https://api.github.com/repos/kfkitsune/weasyl/issues{/number}","pulls_url":"https://api.github.com/repos/kfkitsune/weasyl/pulls{/number}","milestones_url":"https://api.github.com/repos/kfkitsune/weasyl/milestones{/number}","notifications_url":"https://api.github.com/repos/kfkitsune/weasyl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kfkitsune/weasyl/labels{/name}","releases_url":"https://api.github.com/repos/kfkitsune/weasyl/releases{/id}","deployments_url":"https://api.github.com/repos/kfkitsune/weasyl/deployments","created_at":"2016-06-02T22:13:26Z","updated_at":"2016-06-02T22:13:27Z","pushed_at":"2016-07-03T02:21:48Z","git_url":"git://github.com/kfkitsune/weasyl.git","ssh_url":"git@github.com:kfkitsune/weasyl.git","clone_url":"https://github.com/kfkitsune/weasyl.git","svn_url":"https://github.com/kfkitsune/weasyl","homepage":"https://www.weasyl.com/","size":3095,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Weasyl:master","ref":"master","sha":"3d8974809fda3ec091f065d7124d7f63487e7cec","user":{"login":"Weasyl","id":2838769,"avatar_url":"https://avatars.githubusercontent.com/u/2838769?v=3","gravatar_id":"","url":"https://api.github.com/users/Weasyl","html_url":"https://github.com/Weasyl","followers_url":"https://api.github.com/users/Weasyl/followers","following_url":"https://api.github.com/users/Weasyl/following{/other_user}","gists_url":"https://api.github.com/users/Weasyl/gists{/gist_id}","starred_url":"https://api.github.com/users/Weasyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Weasyl/subscriptions","organizations_url":"https://api.github.com/users/Weasyl/orgs","repos_url":"https://api.github.com/users/Weasyl/repos","events_url":"https://api.github.com/users/Weasyl/events{/privacy}","received_events_url":"https://api.github.com/users/Weasyl/received_events","type":"Organization","site_admin":false},"repo":{"id":58244355,"name":"weasyl","full_name":"Weasyl/weasyl","owner":{"login":"Weasyl","id":2838769,"avatar_url":"https://avatars.githubusercontent.com/u/2838769?v=3","gravatar_id":"","url":"https://api.github.com/users/Weasyl","html_url":"https://github.com/Weasyl","followers_url":"https://api.github.com/users/Weasyl/followers","following_url":"https://api.github.com/users/Weasyl/following{/other_user}","gists_url":"https://api.github.com/users/Weasyl/gists{/gist_id}","starred_url":"https://api.github.com/users/Weasyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Weasyl/subscriptions","organizations_url":"https://api.github.com/users/Weasyl/orgs","repos_url":"https://api.github.com/users/Weasyl/repos","events_url":"https://api.github.com/users/Weasyl/events{/privacy}","received_events_url":"https://api.github.com/users/Weasyl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Weasyl/weasyl","description":"The website.","fork":false,"url":"https://api.github.com/repos/Weasyl/weasyl","forks_url":"https://api.github.com/repos/Weasyl/weasyl/forks","keys_url":"https://api.github.com/repos/Weasyl/weasyl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Weasyl/weasyl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Weasyl/weasyl/teams","hooks_url":"https://api.github.com/repos/Weasyl/weasyl/hooks","issue_events_url":"https://api.github.com/repos/Weasyl/weasyl/issues/events{/number}","events_url":"https://api.github.com/repos/Weasyl/weasyl/events","assignees_url":"https://api.github.com/repos/Weasyl/weasyl/assignees{/user}","branches_url":"https://api.github.com/repos/Weasyl/weasyl/branches{/branch}","tags_url":"https://api.github.com/repos/Weasyl/weasyl/tags","blobs_url":"https://api.github.com/repos/Weasyl/weasyl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Weasyl/weasyl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Weasyl/weasyl/git/refs{/sha}","trees_url":"https://api.github.com/repos/Weasyl/weasyl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Weasyl/weasyl/statuses/{sha}","languages_url":"https://api.github.com/repos/Weasyl/weasyl/languages","stargazers_url":"https://api.github.com/repos/Weasyl/weasyl/stargazers","contributors_url":"https://api.github.com/repos/Weasyl/weasyl/contributors","subscribers_url":"https://api.github.com/repos/Weasyl/weasyl/subscribers","subscription_url":"https://api.github.com/repos/Weasyl/weasyl/subscription","commits_url":"https://api.github.com/repos/Weasyl/weasyl/commits{/sha}","git_commits_url":"https://api.github.com/repos/Weasyl/weasyl/git/commits{/sha}","comments_url":"https://api.github.com/repos/Weasyl/weasyl/comments{/number}","issue_comment_url":"https://api.github.com/repos/Weasyl/weasyl/issues/comments{/number}","contents_url":"https://api.github.com/repos/Weasyl/weasyl/contents/{+path}","compare_url":"https://api.github.com/repos/Weasyl/weasyl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Weasyl/weasyl/merges","archive_url":"https://api.github.com/repos/Weasyl/weasyl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Weasyl/weasyl/downloads","issues_url":"https://api.github.com/repos/Weasyl/weasyl/issues{/number}","pulls_url":"https://api.github.com/repos/Weasyl/weasyl/pulls{/number}","milestones_url":"https://api.github.com/repos/Weasyl/weasyl/milestones{/number}","notifications_url":"https://api.github.com/repos/Weasyl/weasyl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Weasyl/weasyl/labels{/name}","releases_url":"https://api.github.com/repos/Weasyl/weasyl/releases{/id}","deployments_url":"https://api.github.com/repos/Weasyl/weasyl/deployments","created_at":"2016-05-07T01:53:26Z","updated_at":"2016-07-02T22:11:44Z","pushed_at":"2016-07-03T02:39:21Z","git_url":"git://github.com/Weasyl/weasyl.git","ssh_url":"git@github.com:Weasyl/weasyl.git","clone_url":"https://github.com/Weasyl/weasyl.git","svn_url":"https://github.com/Weasyl/weasyl","homepage":"https://www.weasyl.com/","size":3185,"stargazers_count":53,"watchers_count":53,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":37,"forks":14,"open_issues":37,"watchers":53,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/92"},"html":{"href":"https://github.com/Weasyl/weasyl/pull/92"},"issue":{"href":"https://api.github.com/repos/Weasyl/weasyl/issues/92"},"comments":{"href":"https://api.github.com/repos/Weasyl/weasyl/issues/92/comments"},"review_comments":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/92/comments"},"review_comment":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/92/commits"},"statuses":{"href":"https://api.github.com/repos/Weasyl/weasyl/statuses/5093a9afb5ffd1e532996ee14fa779f338069024"}}}}
{"actor":{"display_login":"weykent"}}