{"action":"created","comment":{"url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/comments/57693977","id":57693977,"diff_hunk":"@@ -0,0 +1,330 @@\n+import json\n+\n+from django.test import TestCase, Client\n+from django.db.utils import IntegrityError\n+from django.core.exceptions import ValidationError\n+\n+from .models import SegmentsConfig, CHECK_URL_NOT_VALID, CHECK_URL_UNKNOWN\n+\n+# Create your tests here.\n+\n+GOOD_RULES_SET = \"\"\"\n+@product\n+*/product/*\n+\n+@article\n+*article.html\n+\n+@comments\n+*/comments/*.html\n+\"\"\"\n+\n+KEY_REPEATED_RULES_SET = \"\"\"\n+@product\n+*/product/*\n+\n+@product\n+*/vendor/*\n+\n+@article\n+*article.html\n+\n+@comments\n+*/comments/*.html\n+\"\"\"\n+\n+BAD_KEY_RULES_SET = \"\"\"\n+product\n+*/product/*\n+\n+@article\n+*article.html\n+\n+@comments\n+*/comments/*.html\n+\"\"\"\n+\n+\n+MALFORMED_RULES_SET = \"\"\"\n+@product\n+*/product/*\n+\n+@article\n+*article.html\n+\n+@comments\n+*/comments/*.html\n+\n+@ad\n+\"\"\"\n+\n+BAD_RULE_RULES_SET = \"\"\"\n+@product\n+*/product/*\n+\n+@article\n+*article or product\n+\n+@comments\n+*/comments/*.html\n+\"\"\"\n+\n+URLS_TO_CHECK = [\n+    \"http://www.amazon.com/product/ps4.html\",\n+    \"http://www.amazon.com/ps4/games/article.html\",\n+    \"http://www.amazon.com/\",\n+    \"http://amazon.com/ps4/the-division/comments/page1.html\",\n+    \"http://amazoncom/ps4/fifa16/comments/page1.html\",\n+]\n+\n+EXPECTED_RESPONSE = [\n+    {\n+        'url': \"http://www.amazon.com/product/ps4.html\",\n+        'value': 'product'\n+    },\n+    {\n+        'url': \"http://www.amazon.com/ps4/games/article.html\",\n+        'value': 'article'\n+    },\n+    {\n+        'url': \"http://www.amazon.com/\",\n+        'value': CHECK_URL_UNKNOWN\n+    },\n+    {\n+        'url': \"http://amazon.com/ps4/the-division/comments/page1.html\",\n+        'value': \"comments\"\n+    },\n+    {\n+        'url': \"http://amazoncom/ps4/fifa16/comments/page1.html\",\n+        'value': CHECK_URL_NOT_VALID\n+    },\n+]\n+\n+\n+class SegmentsConfigTestCase(TestCase):\n+\n+    def setUp(self):\n+        config = SegmentsConfig(\n+            name='fake',\n+            rules_set=GOOD_RULES_SET,\n+        )\n+        config.full_clean()\n+        config.save()\n+\n+    def test_unique_name(self):\n+        with self.assertRaises(IntegrityError):\n+            SegmentsConfig.objects.create(\n+                name='fake',\n+                rules_set=GOOD_RULES_SET,\n+            )\n+\n+    def test_alphanum_name(self):\n+        with self.assertRaises(ValidationError):\n+            config = SegmentsConfig(\n+                name='fake_id',\n+                rules_set=GOOD_RULES_SET,\n+            )\n+            config.full_clean()\n+            config.save()\n+\n+    def test_key_repeated_in_rules_set(self):\n+        with self.assertRaises(ValidationError):\n+            config = SegmentsConfig(\n+                name='123',\n+                rules_set=KEY_REPEATED_RULES_SET\n+            )\n+            config.full_clean()\n+            config.save()\n+\n+    def test_bad_key_in_rules_set(self):\n+        with self.assertRaises(ValidationError):\n+            config = SegmentsConfig(\n+                name='123',\n+                rules_set=BAD_KEY_RULES_SET\n+            )\n+            config.full_clean()\n+            config.save()\n+\n+    def test_bad_rule_in_rules_set(self):\n+        with self.assertRaises(ValidationError):\n+            config = SegmentsConfig(\n+                name='123',\n+                rules_set=BAD_RULE_RULES_SET\n+            )\n+            config.full_clean()\n+            config.save()\n+\n+    def test_bad_format_rules_set(self):\n+        with self.assertRaises(ValidationError):\n+            config = SegmentsConfig(\n+                name='123',\n+                rules_set=MALFORMED_RULES_SET\n+            )\n+            config.full_clean()\n+            config.save()\n+\n+    def test_order_in_rules_set(self):\n+        order_expected = [\n+            ('@product', '*/product/*'),\n+            ('@article', '*article.html'),\n+            ('@comments', '*/comments/*.html')\n+        ]\n+\n+        for i in range(10):\n+            with self.subTest('Round {}'.format(i)):\n+                item = SegmentsConfig.objects.get(\n+                    name='fake'\n+                )\n+\n+                self.assertEqual(\n+                    order_expected, list(item.config_rules_set)\n+                )\n+\n+    def test_check_url_not_valid_url(self):\n+        url = \"https://www.amazoncom/product/\"\n+        expected = CHECK_URL_NOT_VALID\n+\n+        for i in range(10):\n+            with self.subTest('Round {}'.format(i)):\n+                item = SegmentsConfig.objects.get(\n+                    name='fake'\n+                )\n+\n+                self.assertEqual(\n+                    expected, item.check_url(url)\n+                )\n+\n+    def test_check_url_unknown_url(self):\n+        url = \"https://www.amazon.com\"\n+        expected = CHECK_URL_UNKNOWN\n+\n+        for i in range(10):","path":"segments_config/tests.py","position":201,"original_position":201,"commit_id":"13f1cdeb16ff484888391e45eafb19709bb946f3","original_commit_id":"13f1cdeb16ff484888391e45eafb19709bb946f3","user":{"login":"pleasedontbelong","id":1785603,"avatar_url":"https://avatars.githubusercontent.com/u/1785603?v=3","gravatar_id":"","url":"https://api.github.com/users/pleasedontbelong","html_url":"https://github.com/pleasedontbelong","followers_url":"https://api.github.com/users/pleasedontbelong/followers","following_url":"https://api.github.com/users/pleasedontbelong/following{/other_user}","gists_url":"https://api.github.com/users/pleasedontbelong/gists{/gist_id}","starred_url":"https://api.github.com/users/pleasedontbelong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleasedontbelong/subscriptions","organizations_url":"https://api.github.com/users/pleasedontbelong/orgs","repos_url":"https://api.github.com/users/pleasedontbelong/repos","events_url":"https://api.github.com/users/pleasedontbelong/events{/privacy}","received_events_url":"https://api.github.com/users/pleasedontbelong/received_events","type":"User","site_admin":false},"body":"why?","created_at":"2016-03-29T09:21:58Z","updated_at":"2016-03-29T09:21:58Z","html_url":"https://github.com/pleasedontbelong/test_landry/pull/1#discussion_r57693977","pull_request_url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/comments/57693977"},"html":{"href":"https://github.com/pleasedontbelong/test_landry/pull/1#discussion_r57693977"},"pull_request":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/1","id":64431701,"html_url":"https://github.com/pleasedontbelong/test_landry/pull/1","diff_url":"https://github.com/pleasedontbelong/test_landry/pull/1.diff","patch_url":"https://github.com/pleasedontbelong/test_landry/pull/1.patch","issue_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/1","number":1,"state":"open","locked":false,"title":"Test Landry","user":{"login":"pleasedontbelong","id":1785603,"avatar_url":"https://avatars.githubusercontent.com/u/1785603?v=3","gravatar_id":"","url":"https://api.github.com/users/pleasedontbelong","html_url":"https://github.com/pleasedontbelong","followers_url":"https://api.github.com/users/pleasedontbelong/followers","following_url":"https://api.github.com/users/pleasedontbelong/following{/other_user}","gists_url":"https://api.github.com/users/pleasedontbelong/gists{/gist_id}","starred_url":"https://api.github.com/users/pleasedontbelong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleasedontbelong/subscriptions","organizations_url":"https://api.github.com/users/pleasedontbelong/orgs","repos_url":"https://api.github.com/users/pleasedontbelong/repos","events_url":"https://api.github.com/users/pleasedontbelong/events{/privacy}","received_events_url":"https://api.github.com/users/pleasedontbelong/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-29T08:46:04Z","updated_at":"2016-03-29T09:21:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d9fb15bf978a406e095074576c4448c860386c7c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/1/commits","review_comments_url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/1/comments","review_comment_url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/1/comments","statuses_url":"https://api.github.com/repos/pleasedontbelong/test_landry/statuses/13f1cdeb16ff484888391e45eafb19709bb946f3","head":{"label":"pleasedontbelong:code","ref":"code","sha":"13f1cdeb16ff484888391e45eafb19709bb946f3","user":{"login":"pleasedontbelong","id":1785603,"avatar_url":"https://avatars.githubusercontent.com/u/1785603?v=3","gravatar_id":"","url":"https://api.github.com/users/pleasedontbelong","html_url":"https://github.com/pleasedontbelong","followers_url":"https://api.github.com/users/pleasedontbelong/followers","following_url":"https://api.github.com/users/pleasedontbelong/following{/other_user}","gists_url":"https://api.github.com/users/pleasedontbelong/gists{/gist_id}","starred_url":"https://api.github.com/users/pleasedontbelong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleasedontbelong/subscriptions","organizations_url":"https://api.github.com/users/pleasedontbelong/orgs","repos_url":"https://api.github.com/users/pleasedontbelong/repos","events_url":"https://api.github.com/users/pleasedontbelong/events{/privacy}","received_events_url":"https://api.github.com/users/pleasedontbelong/received_events","type":"User","site_admin":false},"repo":{"id":54959308,"name":"test_landry","full_name":"pleasedontbelong/test_landry","owner":{"login":"pleasedontbelong","id":1785603,"avatar_url":"https://avatars.githubusercontent.com/u/1785603?v=3","gravatar_id":"","url":"https://api.github.com/users/pleasedontbelong","html_url":"https://github.com/pleasedontbelong","followers_url":"https://api.github.com/users/pleasedontbelong/followers","following_url":"https://api.github.com/users/pleasedontbelong/following{/other_user}","gists_url":"https://api.github.com/users/pleasedontbelong/gists{/gist_id}","starred_url":"https://api.github.com/users/pleasedontbelong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleasedontbelong/subscriptions","organizations_url":"https://api.github.com/users/pleasedontbelong/orgs","repos_url":"https://api.github.com/users/pleasedontbelong/repos","events_url":"https://api.github.com/users/pleasedontbelong/events{/privacy}","received_events_url":"https://api.github.com/users/pleasedontbelong/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pleasedontbelong/test_landry","description":"","fork":false,"url":"https://api.github.com/repos/pleasedontbelong/test_landry","forks_url":"https://api.github.com/repos/pleasedontbelong/test_landry/forks","keys_url":"https://api.github.com/repos/pleasedontbelong/test_landry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pleasedontbelong/test_landry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pleasedontbelong/test_landry/teams","hooks_url":"https://api.github.com/repos/pleasedontbelong/test_landry/hooks","issue_events_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/events{/number}","events_url":"https://api.github.com/repos/pleasedontbelong/test_landry/events","assignees_url":"https://api.github.com/repos/pleasedontbelong/test_landry/assignees{/user}","branches_url":"https://api.github.com/repos/pleasedontbelong/test_landry/branches{/branch}","tags_url":"https://api.github.com/repos/pleasedontbelong/test_landry/tags","blobs_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/refs{/sha}","trees_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pleasedontbelong/test_landry/statuses/{sha}","languages_url":"https://api.github.com/repos/pleasedontbelong/test_landry/languages","stargazers_url":"https://api.github.com/repos/pleasedontbelong/test_landry/stargazers","contributors_url":"https://api.github.com/repos/pleasedontbelong/test_landry/contributors","subscribers_url":"https://api.github.com/repos/pleasedontbelong/test_landry/subscribers","subscription_url":"https://api.github.com/repos/pleasedontbelong/test_landry/subscription","commits_url":"https://api.github.com/repos/pleasedontbelong/test_landry/commits{/sha}","git_commits_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/commits{/sha}","comments_url":"https://api.github.com/repos/pleasedontbelong/test_landry/comments{/number}","issue_comment_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/comments{/number}","contents_url":"https://api.github.com/repos/pleasedontbelong/test_landry/contents/{+path}","compare_url":"https://api.github.com/repos/pleasedontbelong/test_landry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pleasedontbelong/test_landry/merges","archive_url":"https://api.github.com/repos/pleasedontbelong/test_landry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pleasedontbelong/test_landry/downloads","issues_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues{/number}","pulls_url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls{/number}","milestones_url":"https://api.github.com/repos/pleasedontbelong/test_landry/milestones{/number}","notifications_url":"https://api.github.com/repos/pleasedontbelong/test_landry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pleasedontbelong/test_landry/labels{/name}","releases_url":"https://api.github.com/repos/pleasedontbelong/test_landry/releases{/id}","deployments_url":"https://api.github.com/repos/pleasedontbelong/test_landry/deployments","created_at":"2016-03-29T08:33:53Z","updated_at":"2016-03-29T08:33:53Z","pushed_at":"2016-03-29T08:46:04Z","git_url":"git://github.com/pleasedontbelong/test_landry.git","ssh_url":"git@github.com:pleasedontbelong/test_landry.git","clone_url":"https://github.com/pleasedontbelong/test_landry.git","svn_url":"https://github.com/pleasedontbelong/test_landry","homepage":null,"size":8,"stargazers_count":0,"watchers_count":0,"language":null,"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":"pleasedontbelong:master","ref":"master","sha":"59996a3f5c0bf23d6f31c6d64a4527b4cda3b445","user":{"login":"pleasedontbelong","id":1785603,"avatar_url":"https://avatars.githubusercontent.com/u/1785603?v=3","gravatar_id":"","url":"https://api.github.com/users/pleasedontbelong","html_url":"https://github.com/pleasedontbelong","followers_url":"https://api.github.com/users/pleasedontbelong/followers","following_url":"https://api.github.com/users/pleasedontbelong/following{/other_user}","gists_url":"https://api.github.com/users/pleasedontbelong/gists{/gist_id}","starred_url":"https://api.github.com/users/pleasedontbelong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleasedontbelong/subscriptions","organizations_url":"https://api.github.com/users/pleasedontbelong/orgs","repos_url":"https://api.github.com/users/pleasedontbelong/repos","events_url":"https://api.github.com/users/pleasedontbelong/events{/privacy}","received_events_url":"https://api.github.com/users/pleasedontbelong/received_events","type":"User","site_admin":false},"repo":{"id":54959308,"name":"test_landry","full_name":"pleasedontbelong/test_landry","owner":{"login":"pleasedontbelong","id":1785603,"avatar_url":"https://avatars.githubusercontent.com/u/1785603?v=3","gravatar_id":"","url":"https://api.github.com/users/pleasedontbelong","html_url":"https://github.com/pleasedontbelong","followers_url":"https://api.github.com/users/pleasedontbelong/followers","following_url":"https://api.github.com/users/pleasedontbelong/following{/other_user}","gists_url":"https://api.github.com/users/pleasedontbelong/gists{/gist_id}","starred_url":"https://api.github.com/users/pleasedontbelong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleasedontbelong/subscriptions","organizations_url":"https://api.github.com/users/pleasedontbelong/orgs","repos_url":"https://api.github.com/users/pleasedontbelong/repos","events_url":"https://api.github.com/users/pleasedontbelong/events{/privacy}","received_events_url":"https://api.github.com/users/pleasedontbelong/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pleasedontbelong/test_landry","description":"","fork":false,"url":"https://api.github.com/repos/pleasedontbelong/test_landry","forks_url":"https://api.github.com/repos/pleasedontbelong/test_landry/forks","keys_url":"https://api.github.com/repos/pleasedontbelong/test_landry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pleasedontbelong/test_landry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pleasedontbelong/test_landry/teams","hooks_url":"https://api.github.com/repos/pleasedontbelong/test_landry/hooks","issue_events_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/events{/number}","events_url":"https://api.github.com/repos/pleasedontbelong/test_landry/events","assignees_url":"https://api.github.com/repos/pleasedontbelong/test_landry/assignees{/user}","branches_url":"https://api.github.com/repos/pleasedontbelong/test_landry/branches{/branch}","tags_url":"https://api.github.com/repos/pleasedontbelong/test_landry/tags","blobs_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/refs{/sha}","trees_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pleasedontbelong/test_landry/statuses/{sha}","languages_url":"https://api.github.com/repos/pleasedontbelong/test_landry/languages","stargazers_url":"https://api.github.com/repos/pleasedontbelong/test_landry/stargazers","contributors_url":"https://api.github.com/repos/pleasedontbelong/test_landry/contributors","subscribers_url":"https://api.github.com/repos/pleasedontbelong/test_landry/subscribers","subscription_url":"https://api.github.com/repos/pleasedontbelong/test_landry/subscription","commits_url":"https://api.github.com/repos/pleasedontbelong/test_landry/commits{/sha}","git_commits_url":"https://api.github.com/repos/pleasedontbelong/test_landry/git/commits{/sha}","comments_url":"https://api.github.com/repos/pleasedontbelong/test_landry/comments{/number}","issue_comment_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/comments{/number}","contents_url":"https://api.github.com/repos/pleasedontbelong/test_landry/contents/{+path}","compare_url":"https://api.github.com/repos/pleasedontbelong/test_landry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pleasedontbelong/test_landry/merges","archive_url":"https://api.github.com/repos/pleasedontbelong/test_landry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pleasedontbelong/test_landry/downloads","issues_url":"https://api.github.com/repos/pleasedontbelong/test_landry/issues{/number}","pulls_url":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls{/number}","milestones_url":"https://api.github.com/repos/pleasedontbelong/test_landry/milestones{/number}","notifications_url":"https://api.github.com/repos/pleasedontbelong/test_landry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pleasedontbelong/test_landry/labels{/name}","releases_url":"https://api.github.com/repos/pleasedontbelong/test_landry/releases{/id}","deployments_url":"https://api.github.com/repos/pleasedontbelong/test_landry/deployments","created_at":"2016-03-29T08:33:53Z","updated_at":"2016-03-29T08:33:53Z","pushed_at":"2016-03-29T08:46:04Z","git_url":"git://github.com/pleasedontbelong/test_landry.git","ssh_url":"git@github.com:pleasedontbelong/test_landry.git","clone_url":"https://github.com/pleasedontbelong/test_landry.git","svn_url":"https://github.com/pleasedontbelong/test_landry","homepage":null,"size":8,"stargazers_count":0,"watchers_count":0,"language":null,"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/pleasedontbelong/test_landry/pulls/1"},"html":{"href":"https://github.com/pleasedontbelong/test_landry/pull/1"},"issue":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/1"},"comments":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/pleasedontbelong/test_landry/statuses/13f1cdeb16ff484888391e45eafb19709bb946f3"}}}}