{"action":"created","comment":{"url":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/comments/26811725","id":26811725,"diff_hunk":"@@ -1,5 +1,112 @@\n+\n import unittest\n+import mock\n+from mock import patch\n+from source.lib.utils import Config\n+from source import redirect_checker\n+\n+\n+def stop_cycle(self):\n+    redirect_checker.loop = False\n+\n+config = Config()\n+config.CHECK_URL = 'url'\n+config.HTTP_TIMEOUT = 1\n+config.WORKER_POOL_SIZE = 4\n+config.SLEEP = 1\n+config.LOGGING = 'logging'\n+config.EXIT_CODE = 31\n \n \n class RedirectCheckerTestCase(unittest.TestCase):\n-    pass\n+\n+    def test_main_loop_with_uncorrect_tupe_of_parametr(self):\n+        uncorrect_config = 'everything bad'\n+        with self.assertRaises(AttributeError):\n+            redirect_checker.main_loop(uncorrect_config)\n+\n+    def test_main_loop_check_network_status_bad(self):\n+        mock_stop_cycle = mock.Mock(side_effect=stop_cycle)\n+        mock_check_network_status = mock.Mock(return_value=False)\n+        mock_spawn_workers = mock.Mock()\n+        with patch('source.redirect_checker.check_network_status', mock_check_network_status),\\\n+             patch('source.redirect_checker.spawn_workers', mock_spawn_workers),\\\n+             patch('source.redirect_checker.sleep', mock_stop_cycle):\n+            redirect_checker.main_loop(config)\n+            self.assertEqual(mock_spawn_workers.call_count, 0)\n+            redirect_checker.loop = True\n+\n+    def test_main_loop_check_network_status_ok_and_workers_number_ok(self):\n+        mock_stop_cycle = mock.Mock(side_effect=stop_cycle)\n+        mock_check_network_status = mock.Mock(return_value=True)\n+        mock_spawn_workers = mock.Mock()\n+        mock_active_children = mock.Mock()\n+        with patch('source.redirect_checker.check_network_status', mock_check_network_status),\\\n+             patch('source.redirect_checker.spawn_workers', mock_spawn_workers),\\\n+             patch('source.redirect_checker.active_children', mock.Mock(return_value=[mock_active_children])),\\\n+             patch('source.redirect_checker.sleep', mock_stop_cycle):\n+            redirect_checker.main_loop(config)\n+            self.assertGreater(mock_spawn_workers.call_count, 0)\n+            redirect_checker.loop = True\n+\n+    def test_main_loop_check_network_status_ok_and_workers_number_bad(self):\n+        mock_stop_cycle = mock.Mock(side_effect=stop_cycle)\n+        mock_check_network_status = mock.Mock(return_value=True)\n+        mock_spawn_workers = mock.Mock()\n+        mock_active_children = mock.Mock()\n+        with patch('source.redirect_checker.check_network_status', mock_check_network_status),\\\n+             patch('source.redirect_checker.spawn_workers', mock_spawn_workers),\\\n+             patch('source.redirect_checker.active_children', mock.Mock(return_value=[mock_active_children]*config.WORKER_POOL_SIZE)),\\\n+             patch('source.redirect_checker.sleep', mock_stop_cycle):\n+            redirect_checker.main_loop(config)\n+            self.assertEqual(mock_spawn_workers.call_count, 0)\n+            redirect_checker.loop = True\n+\n+\n+    def test_main_with_uncorrect_tupe_of_parametr(self):\n+        uncorrect_args = 100\n+        with self.assertRaises(TypeError):\n+            redirect_checker.main(uncorrect_args)\n+\n+\n+    def test_main_check_args_is_daemon_and_pidfile(self):\n+        args = mock.MagicMock()\n+        args.daemon = True\n+        args.pidfile = True\n+        mock_load_config_from_pyfile = mock.Mock(return_value=config)\n+        mock_parse_cmd_args = mock.Mock(return_value=args)\n+        mock_daemonize = mock.Mock()\n+        mock_create_pidfile = mock.Mock()\n+        with patch('source.redirect_checker.parse_cmd_args', mock_parse_cmd_args),\\\n+             patch('source.redirect_checker.daemonize', mock_daemonize),\\\n+             patch('source.redirect_checker.create_pidfile', mock_create_pidfile),\\\n+             patch('source.redirect_checker.load_config_from_pyfile', mock_load_config_from_pyfile),\\\n+             patch('source.redirect_checker.dictConfig', mock.Mock()),\\\n+             patch('source.redirect_checker.main_loop', mock.Mock()),\\\n+             patch('source.redirect_checker.os.path.realpath', mock.Mock()),\\\n+             patch('source.redirect_checker.os.path.expanduser', mock.Mock()):\n+            return_exitcode = redirect_checker.main(args)\n+            self.assertEqual(return_exitcode, config.EXIT_CODE)\n+            self.assertTrue(mock_daemonize.assert_called)","path":"source/tests/test_redirect_checker.py","position":91,"original_position":91,"commit_id":"d75d28e294782824483000319f2ad5e196e9d22b","original_commit_id":"d75d28e294782824483000319f2ad5e196e9d22b","user":{"login":"bayandin","id":864213,"avatar_url":"https://avatars.githubusercontent.com/u/864213?v=3","gravatar_id":"","url":"https://api.github.com/users/bayandin","html_url":"https://github.com/bayandin","followers_url":"https://api.github.com/users/bayandin/followers","following_url":"https://api.github.com/users/bayandin/following{/other_user}","gists_url":"https://api.github.com/users/bayandin/gists{/gist_id}","starred_url":"https://api.github.com/users/bayandin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bayandin/subscriptions","organizations_url":"https://api.github.com/users/bayandin/orgs","repos_url":"https://api.github.com/users/bayandin/repos","events_url":"https://api.github.com/users/bayandin/events{/privacy}","received_events_url":"https://api.github.com/users/bayandin/received_events","type":"User","site_admin":false},"body":"Какая-то матрёшка из ассертов получилась.","created_at":"2015-03-20T00:47:19Z","updated_at":"2015-03-20T00:47:19Z","html_url":"https://github.com/bayandin/home-assignment-1/pull/4#discussion_r26811725","pull_request_url":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/comments/26811725"},"html":{"href":"https://github.com/bayandin/home-assignment-1/pull/4#discussion_r26811725"},"pull_request":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4","id":31409151,"html_url":"https://github.com/bayandin/home-assignment-1/pull/4","diff_url":"https://github.com/bayandin/home-assignment-1/pull/4.diff","patch_url":"https://github.com/bayandin/home-assignment-1/pull/4.patch","issue_url":"https://api.github.com/repos/bayandin/home-assignment-1/issues/4","number":4,"state":"open","locked":false,"title":"Покрытие кода тестами, дз №1","user":{"login":"Larionov-Vadim","id":8672199,"avatar_url":"https://avatars.githubusercontent.com/u/8672199?v=3","gravatar_id":"","url":"https://api.github.com/users/Larionov-Vadim","html_url":"https://github.com/Larionov-Vadim","followers_url":"https://api.github.com/users/Larionov-Vadim/followers","following_url":"https://api.github.com/users/Larionov-Vadim/following{/other_user}","gists_url":"https://api.github.com/users/Larionov-Vadim/gists{/gist_id}","starred_url":"https://api.github.com/users/Larionov-Vadim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Larionov-Vadim/subscriptions","organizations_url":"https://api.github.com/users/Larionov-Vadim/orgs","repos_url":"https://api.github.com/users/Larionov-Vadim/repos","events_url":"https://api.github.com/users/Larionov-Vadim/events{/privacy}","received_events_url":"https://api.github.com/users/Larionov-Vadim/received_events","type":"User","site_admin":false},"body":"Домашнее задание выполнили: Ларионов Вадим, Волынец Эмилия","created_at":"2015-03-18T08:45:25Z","updated_at":"2015-03-20T00:47:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b6151519067449ce90d57e23f5480b4d54007e3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4/commits","review_comments_url":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4/comments","review_comment_url":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bayandin/home-assignment-1/issues/4/comments","statuses_url":"https://api.github.com/repos/bayandin/home-assignment-1/statuses/d75d28e294782824483000319f2ad5e196e9d22b","head":{"label":"Larionov-Vadim:master","ref":"master","sha":"d75d28e294782824483000319f2ad5e196e9d22b","user":{"login":"Larionov-Vadim","id":8672199,"avatar_url":"https://avatars.githubusercontent.com/u/8672199?v=3","gravatar_id":"","url":"https://api.github.com/users/Larionov-Vadim","html_url":"https://github.com/Larionov-Vadim","followers_url":"https://api.github.com/users/Larionov-Vadim/followers","following_url":"https://api.github.com/users/Larionov-Vadim/following{/other_user}","gists_url":"https://api.github.com/users/Larionov-Vadim/gists{/gist_id}","starred_url":"https://api.github.com/users/Larionov-Vadim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Larionov-Vadim/subscriptions","organizations_url":"https://api.github.com/users/Larionov-Vadim/orgs","repos_url":"https://api.github.com/users/Larionov-Vadim/repos","events_url":"https://api.github.com/users/Larionov-Vadim/events{/privacy}","received_events_url":"https://api.github.com/users/Larionov-Vadim/received_events","type":"User","site_admin":false},"repo":{"id":32174444,"name":"home-assignment-1","full_name":"Larionov-Vadim/home-assignment-1","owner":{"login":"Larionov-Vadim","id":8672199,"avatar_url":"https://avatars.githubusercontent.com/u/8672199?v=3","gravatar_id":"","url":"https://api.github.com/users/Larionov-Vadim","html_url":"https://github.com/Larionov-Vadim","followers_url":"https://api.github.com/users/Larionov-Vadim/followers","following_url":"https://api.github.com/users/Larionov-Vadim/following{/other_user}","gists_url":"https://api.github.com/users/Larionov-Vadim/gists{/gist_id}","starred_url":"https://api.github.com/users/Larionov-Vadim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Larionov-Vadim/subscriptions","organizations_url":"https://api.github.com/users/Larionov-Vadim/orgs","repos_url":"https://api.github.com/users/Larionov-Vadim/repos","events_url":"https://api.github.com/users/Larionov-Vadim/events{/privacy}","received_events_url":"https://api.github.com/users/Larionov-Vadim/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Larionov-Vadim/home-assignment-1","description":"","fork":true,"url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1","forks_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/forks","keys_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/teams","hooks_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/hooks","issue_events_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/issues/events{/number}","events_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/events","assignees_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/assignees{/user}","branches_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/branches{/branch}","tags_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/tags","blobs_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/statuses/{sha}","languages_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/languages","stargazers_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/stargazers","contributors_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/contributors","subscribers_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/subscribers","subscription_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/subscription","commits_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/contents/{+path}","compare_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/merges","archive_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/downloads","issues_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/issues{/number}","pulls_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/pulls{/number}","milestones_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/milestones{/number}","notifications_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/labels{/name}","releases_url":"https://api.github.com/repos/Larionov-Vadim/home-assignment-1/releases{/id}","created_at":"2015-03-13T18:45:41Z","updated_at":"2015-03-19T22:53:30Z","pushed_at":"2015-03-19T22:53:30Z","git_url":"git://github.com/Larionov-Vadim/home-assignment-1.git","ssh_url":"git@github.com:Larionov-Vadim/home-assignment-1.git","clone_url":"https://github.com/Larionov-Vadim/home-assignment-1.git","svn_url":"https://github.com/Larionov-Vadim/home-assignment-1","homepage":null,"size":329,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bayandin:master","ref":"master","sha":"14964a800aa03f4027ac3d068ee92c2aac60529b","user":{"login":"bayandin","id":864213,"avatar_url":"https://avatars.githubusercontent.com/u/864213?v=3","gravatar_id":"","url":"https://api.github.com/users/bayandin","html_url":"https://github.com/bayandin","followers_url":"https://api.github.com/users/bayandin/followers","following_url":"https://api.github.com/users/bayandin/following{/other_user}","gists_url":"https://api.github.com/users/bayandin/gists{/gist_id}","starred_url":"https://api.github.com/users/bayandin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bayandin/subscriptions","organizations_url":"https://api.github.com/users/bayandin/orgs","repos_url":"https://api.github.com/users/bayandin/repos","events_url":"https://api.github.com/users/bayandin/events{/privacy}","received_events_url":"https://api.github.com/users/bayandin/received_events","type":"User","site_admin":false},"repo":{"id":31509224,"name":"home-assignment-1","full_name":"bayandin/home-assignment-1","owner":{"login":"bayandin","id":864213,"avatar_url":"https://avatars.githubusercontent.com/u/864213?v=3","gravatar_id":"","url":"https://api.github.com/users/bayandin","html_url":"https://github.com/bayandin","followers_url":"https://api.github.com/users/bayandin/followers","following_url":"https://api.github.com/users/bayandin/following{/other_user}","gists_url":"https://api.github.com/users/bayandin/gists{/gist_id}","starred_url":"https://api.github.com/users/bayandin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bayandin/subscriptions","organizations_url":"https://api.github.com/users/bayandin/orgs","repos_url":"https://api.github.com/users/bayandin/repos","events_url":"https://api.github.com/users/bayandin/events{/privacy}","received_events_url":"https://api.github.com/users/bayandin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bayandin/home-assignment-1","description":"","fork":false,"url":"https://api.github.com/repos/bayandin/home-assignment-1","forks_url":"https://api.github.com/repos/bayandin/home-assignment-1/forks","keys_url":"https://api.github.com/repos/bayandin/home-assignment-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bayandin/home-assignment-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bayandin/home-assignment-1/teams","hooks_url":"https://api.github.com/repos/bayandin/home-assignment-1/hooks","issue_events_url":"https://api.github.com/repos/bayandin/home-assignment-1/issues/events{/number}","events_url":"https://api.github.com/repos/bayandin/home-assignment-1/events","assignees_url":"https://api.github.com/repos/bayandin/home-assignment-1/assignees{/user}","branches_url":"https://api.github.com/repos/bayandin/home-assignment-1/branches{/branch}","tags_url":"https://api.github.com/repos/bayandin/home-assignment-1/tags","blobs_url":"https://api.github.com/repos/bayandin/home-assignment-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bayandin/home-assignment-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bayandin/home-assignment-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/bayandin/home-assignment-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bayandin/home-assignment-1/statuses/{sha}","languages_url":"https://api.github.com/repos/bayandin/home-assignment-1/languages","stargazers_url":"https://api.github.com/repos/bayandin/home-assignment-1/stargazers","contributors_url":"https://api.github.com/repos/bayandin/home-assignment-1/contributors","subscribers_url":"https://api.github.com/repos/bayandin/home-assignment-1/subscribers","subscription_url":"https://api.github.com/repos/bayandin/home-assignment-1/subscription","commits_url":"https://api.github.com/repos/bayandin/home-assignment-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/bayandin/home-assignment-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/bayandin/home-assignment-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/bayandin/home-assignment-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/bayandin/home-assignment-1/contents/{+path}","compare_url":"https://api.github.com/repos/bayandin/home-assignment-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bayandin/home-assignment-1/merges","archive_url":"https://api.github.com/repos/bayandin/home-assignment-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bayandin/home-assignment-1/downloads","issues_url":"https://api.github.com/repos/bayandin/home-assignment-1/issues{/number}","pulls_url":"https://api.github.com/repos/bayandin/home-assignment-1/pulls{/number}","milestones_url":"https://api.github.com/repos/bayandin/home-assignment-1/milestones{/number}","notifications_url":"https://api.github.com/repos/bayandin/home-assignment-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bayandin/home-assignment-1/labels{/name}","releases_url":"https://api.github.com/repos/bayandin/home-assignment-1/releases{/id}","created_at":"2015-03-01T20:16:48Z","updated_at":"2015-03-04T16:38:04Z","pushed_at":"2015-03-19T22:53:30Z","git_url":"git://github.com/bayandin/home-assignment-1.git","ssh_url":"git@github.com:bayandin/home-assignment-1.git","clone_url":"https://github.com/bayandin/home-assignment-1.git","svn_url":"https://github.com/bayandin/home-assignment-1","homepage":null,"size":813,"stargazers_count":1,"watchers_count":1,"language":"Lua","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":7,"forks":11,"open_issues":7,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4"},"html":{"href":"https://github.com/bayandin/home-assignment-1/pull/4"},"issue":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/issues/4"},"comments":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/bayandin/home-assignment-1/statuses/d75d28e294782824483000319f2ad5e196e9d22b"}}}}