{"action":"created","comment":{"url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/comments/23649463","id":23649463,"diff_hunk":"@@ -0,0 +1,128 @@\n+'''\n+Unit Tests for the manage.py command rename_user\n+'''\n+from django.core.management.base import CommandError\n+import unittest\n+from django.contrib.auth.models import User\n+from pymongo import MongoClient\n+from student.tests.factories import UserFactory\n+import datetime\n+from .. import rename_user\n+import sys\n+from StringIO import StringIO\n+\n+\n+class TestUsernameRenameCommand(unittest.TestCase):\n+    '''\n+    Class which contains various unit tests for the manage.py rename_user command line tool\n+    '''\n+    @classmethod\n+    def setUpClass(cls):\n+        client = MongoClient()\n+        # chooses to temporarily write to the forum database\n+        cls.db = client.forum\n+        # maintain arrays of mongo data so that we can delete them when the tests are done\n+        cls.mongo_user_ids = []\n+        cls.mongo_comment_ids = []\n+        cls.sql_user = UserFactory.create()\n+        cls.rename_cmd = rename_user.Command()\n+        cls.seed_mongo_comment()\n+        cls.seed_mongo_user()\n+\n+    @classmethod\n+    def seed_mongo_comment(cls):\n+        '''\n+        Seeds 1 test mongo comment object for each of the test mongo users\n+        '''\n+        comment_1 = {\n+            \"_type\": \"CommentThread\",\n+            \"abuse_flaggers\": [],\n+            \"anonymous\": False,\n+            \"anonymous_to_peers\": False,\n+            \"at_position_list\": [],\n+            \"author_id\": \"1\",\n+            \"author_username\": cls.sql_user.username,\n+            \"body\": \"Architecto suscipit dolores. Velit enim quasi doloribus suscipit maxime laboriosam. Voluptatibus totam dolor dolorem dolorum placeat. Provident necessitatibus fugiat quia aut numquam repudiandae. Cum excepturi doloremque mollitia itaque eum praesentium.\\n\\nEx tempore maiores eum ea sed alias sint. Maiores veritatis commodi dolores aut et dolorem mollitia. Qui neque sed ea placeat.\\n\\nSit voluptas dicta et ut. Voluptas velit beatae veniam magni dolores. Est sed impedit numquam dolorum perspiciatis veniam. Temporibus inventore distinctio ratione labore nobis alias dolores. Est velit nihil dolorem qui nesciunt asperiores veritatis.\",\n+            \"closed\": False,\n+            \"comment_count\": 9,\n+            \"commentable_id\": \"video_1\",\n+            \"course_id\": \"MITx/6.002x/2012_Fall\",\n+            \"created_at\": datetime.datetime.strptime('22092013', \"%d%m%Y\"),\n+            \"historical_abuse_flaggers\": [],\n+            \"last_activity_at\": datetime.datetime.strptime('22092013', \"%d%m%Y\"),\n+            \"tags_array\": [\n+                \"c#\",\n+                \"2012\",\n+                \"java-sucks\"\n+            ],\n+            \"thread_type\": \"discussion\",\n+            \"title\": \"Dolore et molestias quia maxime eaque quos voluptatem et.\",\n+            \"updated_at\": datetime.datetime.strptime('22092013', \"%d%m%Y\"),\n+            \"visible\": True,\n+            \"votes\": {\n+                \"count\": 7,\n+                \"down\": [\n+                    \"1\",\n+                    \"3\",\n+                    \"4\",\n+                    \"5\",\n+                    \"7\"\n+                ],\n+                \"down_count\": 5,\n+                \"point\": -3,\n+                \"up\": [\n+                    \"2\",\n+                    \"6\"\n+                ],\n+                \"up_count\": 2\n+            }\n+\n+        }\n+        cls.mongo_comment_ids.append(cls.db.contents.insert(comment_1))\n+\n+    @classmethod\n+    def seed_mongo_user(cls):\n+        '''\n+        Seeds 3 mongo test users for the tests that follow\n+        '''\n+        user_1 = {\n+            \"default_sort_key\": \"date\",\n+            \"notification_ids\": [],\n+            \"external_id\": \"test_user_1\",\n+            \"username\": cls.sql_user.username\n+        }\n+        cls.mongo_user_ids.append(cls.db.users.insert(user_1))\n+\n+    def test_data_seed(self):\n+        self.assertTrue(len(self.mongo_user_ids) == 1, 'Test mongo users were not properly seeded, rendering tests invalid.')\n+        self.assertTrue(len(self.mongo_comment_ids) == 1, 'Test mongo comments were not properly seeded, rendering the tests invalid.')\n+\n+    def test_incorrect_num_args(self):\n+        zero_args = []\n+        one_arg = ['arg']\n+        three_args = ['arg', 'arg', 'arg']\n+        self.assertRaises(CommandError, self.rename_cmd.handle, *zero_args)\n+        self.assertRaises(CommandError, self.rename_cmd.handle, *one_arg)\n+        self.assertRaises(CommandError, self.rename_cmd.handle, *three_args)\n+\n+    def test_successful_change(self):\n+        saved_stdout = sys.stdout\n+        try:\n+            out = StringIO()\n+            sys.stdout = out\n+            args = [self.sql_user.username, 'someArbitraryUserName']\n+            self.rename_cmd.handle(*args)\n+            output = out.getvalue().strip()\n+            self.assertRegexpMatches(output, 'changed username of user:')","path":"lms/djangoapps/django_comment_client/management/commands/tests/test_rename_user.py","position":116,"original_position":116,"commit_id":"e407492c5a62294c84c17ff9ed37b2bb5830262a","original_commit_id":"e407492c5a62294c84c17ff9ed37b2bb5830262a","user":{"login":"azimpradhan","id":1752973,"avatar_url":"https://avatars.githubusercontent.com/u/1752973?v=3","gravatar_id":"","url":"https://api.github.com/users/azimpradhan","html_url":"https://github.com/azimpradhan","followers_url":"https://api.github.com/users/azimpradhan/followers","following_url":"https://api.github.com/users/azimpradhan/following{/other_user}","gists_url":"https://api.github.com/users/azimpradhan/gists{/gist_id}","starred_url":"https://api.github.com/users/azimpradhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azimpradhan/subscriptions","organizations_url":"https://api.github.com/users/azimpradhan/orgs","repos_url":"https://api.github.com/users/azimpradhan/repos","events_url":"https://api.github.com/users/azimpradhan/events{/privacy}","received_events_url":"https://api.github.com/users/azimpradhan/received_events","type":"User","site_admin":false},"body":"done","created_at":"2015-01-27T22:32:36Z","updated_at":"2015-01-27T22:32:36Z","html_url":"https://github.com/Stanford-Online/edx-platform/pull/187#discussion_r23649463","pull_request_url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187","_links":{"self":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/comments/23649463"},"html":{"href":"https://github.com/Stanford-Online/edx-platform/pull/187#discussion_r23649463"},"pull_request":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187"}}},"pull_request":{"url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187","id":27719224,"html_url":"https://github.com/Stanford-Online/edx-platform/pull/187","diff_url":"https://github.com/Stanford-Online/edx-platform/pull/187.diff","patch_url":"https://github.com/Stanford-Online/edx-platform/pull/187.patch","issue_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/187","number":187,"state":"open","locked":false,"title":"created rename_user command line tool to modify the username of a user, along with unit tests","user":{"login":"azimpradhan","id":1752973,"avatar_url":"https://avatars.githubusercontent.com/u/1752973?v=3","gravatar_id":"","url":"https://api.github.com/users/azimpradhan","html_url":"https://github.com/azimpradhan","followers_url":"https://api.github.com/users/azimpradhan/followers","following_url":"https://api.github.com/users/azimpradhan/following{/other_user}","gists_url":"https://api.github.com/users/azimpradhan/gists{/gist_id}","starred_url":"https://api.github.com/users/azimpradhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azimpradhan/subscriptions","organizations_url":"https://api.github.com/users/azimpradhan/orgs","repos_url":"https://api.github.com/users/azimpradhan/repos","events_url":"https://api.github.com/users/azimpradhan/events{/privacy}","received_events_url":"https://api.github.com/users/azimpradhan/received_events","type":"User","site_admin":false},"body":"Use the command line tool as follows:\r\npython manage.py lms rename_user username1 username2 --settings=devstack\r\n\r\nRun the tests as follows:\r\npython ./manage.py lms test --verbosity=1 lms/djangoapps/django_comment_client/management/commands/tests/test_rename_user.py  --traceback --settings=test\r\n\r\nNote: The tests use a database that is deleted upon completion of the test\r\nThe tests use the forum database on the user's machine and remove the data upon completion of the test\r\n\r\n\r\n\r\n","created_at":"2015-01-20T22:37:01Z","updated_at":"2015-01-27T22:32:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d3b8f6acbd627db6e42d2d90f2b2235391342877","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187/commits","review_comments_url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187/comments","review_comment_url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/187/comments","statuses_url":"https://api.github.com/repos/Stanford-Online/edx-platform/statuses/e407492c5a62294c84c17ff9ed37b2bb5830262a","head":{"label":"Stanford-Online:azimpradhan/forum-username-rename","ref":"azimpradhan/forum-username-rename","sha":"e407492c5a62294c84c17ff9ed37b2bb5830262a","user":{"login":"Stanford-Online","id":2159497,"avatar_url":"https://avatars.githubusercontent.com/u/2159497?v=3","gravatar_id":"","url":"https://api.github.com/users/Stanford-Online","html_url":"https://github.com/Stanford-Online","followers_url":"https://api.github.com/users/Stanford-Online/followers","following_url":"https://api.github.com/users/Stanford-Online/following{/other_user}","gists_url":"https://api.github.com/users/Stanford-Online/gists{/gist_id}","starred_url":"https://api.github.com/users/Stanford-Online/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stanford-Online/subscriptions","organizations_url":"https://api.github.com/users/Stanford-Online/orgs","repos_url":"https://api.github.com/users/Stanford-Online/repos","events_url":"https://api.github.com/users/Stanford-Online/events{/privacy}","received_events_url":"https://api.github.com/users/Stanford-Online/received_events","type":"Organization","site_admin":false},"repo":{"id":11616657,"name":"edx-platform","full_name":"Stanford-Online/edx-platform","owner":{"login":"Stanford-Online","id":2159497,"avatar_url":"https://avatars.githubusercontent.com/u/2159497?v=3","gravatar_id":"","url":"https://api.github.com/users/Stanford-Online","html_url":"https://github.com/Stanford-Online","followers_url":"https://api.github.com/users/Stanford-Online/followers","following_url":"https://api.github.com/users/Stanford-Online/following{/other_user}","gists_url":"https://api.github.com/users/Stanford-Online/gists{/gist_id}","starred_url":"https://api.github.com/users/Stanford-Online/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stanford-Online/subscriptions","organizations_url":"https://api.github.com/users/Stanford-Online/orgs","repos_url":"https://api.github.com/users/Stanford-Online/repos","events_url":"https://api.github.com/users/Stanford-Online/events{/privacy}","received_events_url":"https://api.github.com/users/Stanford-Online/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Stanford-Online/edx-platform","description":"the edX learning management system (LMS) and course authoring tool, Studio","fork":true,"url":"https://api.github.com/repos/Stanford-Online/edx-platform","forks_url":"https://api.github.com/repos/Stanford-Online/edx-platform/forks","keys_url":"https://api.github.com/repos/Stanford-Online/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Stanford-Online/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Stanford-Online/edx-platform/teams","hooks_url":"https://api.github.com/repos/Stanford-Online/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/Stanford-Online/edx-platform/events","assignees_url":"https://api.github.com/repos/Stanford-Online/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/Stanford-Online/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/Stanford-Online/edx-platform/tags","blobs_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Stanford-Online/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/Stanford-Online/edx-platform/languages","stargazers_url":"https://api.github.com/repos/Stanford-Online/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/Stanford-Online/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/Stanford-Online/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/Stanford-Online/edx-platform/subscription","commits_url":"https://api.github.com/repos/Stanford-Online/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/Stanford-Online/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/comments/{number}","contents_url":"https://api.github.com/repos/Stanford-Online/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/Stanford-Online/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Stanford-Online/edx-platform/merges","archive_url":"https://api.github.com/repos/Stanford-Online/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Stanford-Online/edx-platform/downloads","issues_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/Stanford-Online/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/Stanford-Online/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Stanford-Online/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/Stanford-Online/edx-platform/releases{/id}","created_at":"2013-07-23T19:05:46Z","updated_at":"2015-01-27T22:00:21Z","pushed_at":"2015-01-27T22:00:22Z","git_url":"git://github.com/Stanford-Online/edx-platform.git","ssh_url":"git@github.com:Stanford-Online/edx-platform.git","clone_url":"https://github.com/Stanford-Online/edx-platform.git","svn_url":"https://github.com/Stanford-Online/edx-platform","homepage":"http://code.edx.org/","size":370027,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":50,"forks":3,"open_issues":50,"watchers":9,"default_branch":"master"}},"base":{"label":"Stanford-Online:master","ref":"master","sha":"cb4ed08e970d19ab9dee3020709619538985c0cc","user":{"login":"Stanford-Online","id":2159497,"avatar_url":"https://avatars.githubusercontent.com/u/2159497?v=3","gravatar_id":"","url":"https://api.github.com/users/Stanford-Online","html_url":"https://github.com/Stanford-Online","followers_url":"https://api.github.com/users/Stanford-Online/followers","following_url":"https://api.github.com/users/Stanford-Online/following{/other_user}","gists_url":"https://api.github.com/users/Stanford-Online/gists{/gist_id}","starred_url":"https://api.github.com/users/Stanford-Online/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stanford-Online/subscriptions","organizations_url":"https://api.github.com/users/Stanford-Online/orgs","repos_url":"https://api.github.com/users/Stanford-Online/repos","events_url":"https://api.github.com/users/Stanford-Online/events{/privacy}","received_events_url":"https://api.github.com/users/Stanford-Online/received_events","type":"Organization","site_admin":false},"repo":{"id":11616657,"name":"edx-platform","full_name":"Stanford-Online/edx-platform","owner":{"login":"Stanford-Online","id":2159497,"avatar_url":"https://avatars.githubusercontent.com/u/2159497?v=3","gravatar_id":"","url":"https://api.github.com/users/Stanford-Online","html_url":"https://github.com/Stanford-Online","followers_url":"https://api.github.com/users/Stanford-Online/followers","following_url":"https://api.github.com/users/Stanford-Online/following{/other_user}","gists_url":"https://api.github.com/users/Stanford-Online/gists{/gist_id}","starred_url":"https://api.github.com/users/Stanford-Online/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stanford-Online/subscriptions","organizations_url":"https://api.github.com/users/Stanford-Online/orgs","repos_url":"https://api.github.com/users/Stanford-Online/repos","events_url":"https://api.github.com/users/Stanford-Online/events{/privacy}","received_events_url":"https://api.github.com/users/Stanford-Online/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Stanford-Online/edx-platform","description":"the edX learning management system (LMS) and course authoring tool, Studio","fork":true,"url":"https://api.github.com/repos/Stanford-Online/edx-platform","forks_url":"https://api.github.com/repos/Stanford-Online/edx-platform/forks","keys_url":"https://api.github.com/repos/Stanford-Online/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Stanford-Online/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Stanford-Online/edx-platform/teams","hooks_url":"https://api.github.com/repos/Stanford-Online/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/Stanford-Online/edx-platform/events","assignees_url":"https://api.github.com/repos/Stanford-Online/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/Stanford-Online/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/Stanford-Online/edx-platform/tags","blobs_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Stanford-Online/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/Stanford-Online/edx-platform/languages","stargazers_url":"https://api.github.com/repos/Stanford-Online/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/Stanford-Online/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/Stanford-Online/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/Stanford-Online/edx-platform/subscription","commits_url":"https://api.github.com/repos/Stanford-Online/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/Stanford-Online/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/Stanford-Online/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/comments/{number}","contents_url":"https://api.github.com/repos/Stanford-Online/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/Stanford-Online/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Stanford-Online/edx-platform/merges","archive_url":"https://api.github.com/repos/Stanford-Online/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Stanford-Online/edx-platform/downloads","issues_url":"https://api.github.com/repos/Stanford-Online/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/Stanford-Online/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/Stanford-Online/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Stanford-Online/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/Stanford-Online/edx-platform/releases{/id}","created_at":"2013-07-23T19:05:46Z","updated_at":"2015-01-27T22:00:21Z","pushed_at":"2015-01-27T22:00:22Z","git_url":"git://github.com/Stanford-Online/edx-platform.git","ssh_url":"git@github.com:Stanford-Online/edx-platform.git","clone_url":"https://github.com/Stanford-Online/edx-platform.git","svn_url":"https://github.com/Stanford-Online/edx-platform","homepage":"http://code.edx.org/","size":370027,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":50,"forks":3,"open_issues":50,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187"},"html":{"href":"https://github.com/Stanford-Online/edx-platform/pull/187"},"issue":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/187"},"comments":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/issues/187/comments"},"review_comments":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187/comments"},"review_comment":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/pulls/187/commits"},"statuses":{"href":"https://api.github.com/repos/Stanford-Online/edx-platform/statuses/e407492c5a62294c84c17ff9ed37b2bb5830262a"}}}}