{"action":"created","comment":{"url":"https://api.github.com/repos/fidals/refarm-catalog/pulls/comments/72420972","id":72420972,"diff_hunk":"@@ -114,6 +114,250 @@ def test_recursive_get_products_custom_sorting(self):\n         self.assertEqual(product[0].name, self.test_unpopular_product.name)\n \n \n+class CategoryToPageRelationTests(TestCase):\n+\n+    @classmethod\n+    def setUpClass(cls):\n+        super(CategoryToPageRelationTests, cls).setUpClass()\n+        cls.root_category = Category.objects.create(\n+            name='All batteries',\n+            slug='all'\n+        )\n+        cls.page_type = cls.root_category.type\n+\n+    def __create_category(self, slug, page=None):\n+        return Category.objects.create(\n+            name='Battery {}'.format(slug),\n+            slug=slug,\n+            page=page,\n+            parent=self.root_category\n+        )\n+\n+    def __create_page(self, slug):\n+        return Page.objects.create(\n+            slug=slug,\n+            type=self.page_type\n+        )\n+\n+    @property\n+    def category_tree_page(self):\n+        return Page.objects.get(slug='category_tree')\n+\n+    def test_category_create_related_page(self):\n+        \"\"\"\n+        Category without related page should create and return related page\n+        by category.save() call\n+        \"\"\"\n+        category = self.__create_category(slug='first')\n+        self.assertEqual(category.type, category.page.type)\n+        self.assertEqual(category.slug, category.page.slug)\n+        self.assertTrue('category' in category.page.type)\n+        self.assertTrue(category.page.model, category)\n+\n+    def test_category_find_related_page_in_db(self):\n+        \"\"\"\n+        Category with related paged in DB but without category-page relation\n+        should find this page in DB and create category-page relation\n+        by category.save() call\n+        \"\"\"\n+        slug = 'second'\n+        page = self.__create_page(slug)\n+        category = self.__create_category(slug)\n+        self.assertTrue(category.page)\n+        self.assertEqual(page, category.page)\n+\n+    def test_category_fix_related_page(self):\n+        \"\"\"\n+        Category with related page,\n+        but wrong data in related page (category.slug != page.slug)\n+        should fix related page data\n+        \"\"\"\n+        slug = 'third'\n+        page = self.__create_page(slug='third-but-wrong')\n+        category = self.__create_category(slug, page)\n+        self.assertEqual(page, category.page)\n+        self.assertEqual(page.slug, category.page.slug)\n+\n+    def test_category_return_related_page(self):\n+        \"\"\"\n+        Category with correct related page should just return it\n+        \"\"\"\n+        slug = 'fourth'\n+        page = self.__create_page(slug)\n+        category = self.__create_category(slug, page)\n+        self.assertEqual(page, category.page)\n+\n+    def test_category_tree_page_parent(self):\n+        \"\"\"\n+        Category tree page should be autocreated as page parent\n+        for every root category. In other words:\n+        category.page.parent == category_tree_page\n+        \"\"\"\n+        slug = 'fifth'\n+        category = Category.objects.create(\n+            name='Battery {}'.format(slug),\n+            slug=slug,\n+            parent=None\n+        )\n+        self.assertEqual(category.page.parent, self.category_tree_page)","path":"tests/tests_models.py","position":114,"original_position":114,"commit_id":"c04578d3a7c7ff2c6149aaf9d10f3c77703002ef","original_commit_id":"c04578d3a7c7ff2c6149aaf9d10f3c77703002ef","user":{"login":"duker33","id":3526796,"avatar_url":"https://avatars.githubusercontent.com/u/3526796?v=3","gravatar_id":"","url":"https://api.github.com/users/duker33","html_url":"https://github.com/duker33","followers_url":"https://api.github.com/users/duker33/followers","following_url":"https://api.github.com/users/duker33/following{/other_user}","gists_url":"https://api.github.com/users/duker33/gists{/gist_id}","starred_url":"https://api.github.com/users/duker33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duker33/subscriptions","organizations_url":"https://api.github.com/users/duker33/orgs","repos_url":"https://api.github.com/users/duker33/repos","events_url":"https://api.github.com/users/duker33/events{/privacy}","received_events_url":"https://api.github.com/users/duker33/received_events","type":"User","site_admin":false},"body":"он создаётся внутри проперти page.parent: этот чудесный код создания мы обсуждали в refarm-site","created_at":"2016-07-27T11:10:22Z","updated_at":"2016-07-27T11:10:22Z","html_url":"https://github.com/fidals/refarm-catalog/pull/27#discussion_r72420972","pull_request_url":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/fidals/refarm-catalog/pulls/comments/72420972"},"html":{"href":"https://github.com/fidals/refarm-catalog/pull/27#discussion_r72420972"},"pull_request":{"href":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27","id":78876906,"html_url":"https://github.com/fidals/refarm-catalog/pull/27","diff_url":"https://github.com/fidals/refarm-catalog/pull/27.diff","patch_url":"https://github.com/fidals/refarm-catalog/pull/27.patch","issue_url":"https://api.github.com/repos/fidals/refarm-catalog/issues/27","number":27,"state":"open","locked":false,"title":"[ 763 ] RF SE Site app","user":{"login":"duker33","id":3526796,"avatar_url":"https://avatars.githubusercontent.com/u/3526796?v=3","gravatar_id":"","url":"https://api.github.com/users/duker33","html_url":"https://github.com/duker33","followers_url":"https://api.github.com/users/duker33/followers","following_url":"https://api.github.com/users/duker33/following{/other_user}","gists_url":"https://api.github.com/users/duker33/gists{/gist_id}","starred_url":"https://api.github.com/users/duker33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duker33/subscriptions","organizations_url":"https://api.github.com/users/duker33/orgs","repos_url":"https://api.github.com/users/duker33/repos","events_url":"https://api.github.com/users/duker33/events{/privacy}","received_events_url":"https://api.github.com/users/duker33/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-26T15:50:39Z","updated_at":"2016-07-27T11:10:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eccb7fd74feca59dcb5de1a166d9e6dbca83448a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27/commits","review_comments_url":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27/comments","review_comment_url":"https://api.github.com/repos/fidals/refarm-catalog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fidals/refarm-catalog/issues/27/comments","statuses_url":"https://api.github.com/repos/fidals/refarm-catalog/statuses/c04578d3a7c7ff2c6149aaf9d10f3c77703002ef","head":{"label":"fidals:f-763_site_app","ref":"f-763_site_app","sha":"c04578d3a7c7ff2c6149aaf9d10f3c77703002ef","user":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"repo":{"id":56064095,"name":"refarm-catalog","full_name":"fidals/refarm-catalog","owner":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fidals/refarm-catalog","description":"Django application with simple eCommerce catalog","fork":false,"url":"https://api.github.com/repos/fidals/refarm-catalog","forks_url":"https://api.github.com/repos/fidals/refarm-catalog/forks","keys_url":"https://api.github.com/repos/fidals/refarm-catalog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/refarm-catalog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/refarm-catalog/teams","hooks_url":"https://api.github.com/repos/fidals/refarm-catalog/hooks","issue_events_url":"https://api.github.com/repos/fidals/refarm-catalog/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/refarm-catalog/events","assignees_url":"https://api.github.com/repos/fidals/refarm-catalog/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/refarm-catalog/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/refarm-catalog/tags","blobs_url":"https://api.github.com/repos/fidals/refarm-catalog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/refarm-catalog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/refarm-catalog/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/refarm-catalog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/refarm-catalog/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/refarm-catalog/languages","stargazers_url":"https://api.github.com/repos/fidals/refarm-catalog/stargazers","contributors_url":"https://api.github.com/repos/fidals/refarm-catalog/contributors","subscribers_url":"https://api.github.com/repos/fidals/refarm-catalog/subscribers","subscription_url":"https://api.github.com/repos/fidals/refarm-catalog/subscription","commits_url":"https://api.github.com/repos/fidals/refarm-catalog/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/refarm-catalog/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/refarm-catalog/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/refarm-catalog/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/refarm-catalog/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/refarm-catalog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/refarm-catalog/merges","archive_url":"https://api.github.com/repos/fidals/refarm-catalog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/refarm-catalog/downloads","issues_url":"https://api.github.com/repos/fidals/refarm-catalog/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/refarm-catalog/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/refarm-catalog/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/refarm-catalog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/refarm-catalog/labels{/name}","releases_url":"https://api.github.com/repos/fidals/refarm-catalog/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/refarm-catalog/deployments","created_at":"2016-04-12T13:10:31Z","updated_at":"2016-04-28T12:45:35Z","pushed_at":"2016-07-27T09:42:00Z","git_url":"git://github.com/fidals/refarm-catalog.git","ssh_url":"git@github.com:fidals/refarm-catalog.git","clone_url":"https://github.com/fidals/refarm-catalog.git","svn_url":"https://github.com/fidals/refarm-catalog","homepage":"","size":72,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"fidals:master","ref":"master","sha":"4400aedcb036d9cefb96726b5c428708a890d5d4","user":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"repo":{"id":56064095,"name":"refarm-catalog","full_name":"fidals/refarm-catalog","owner":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fidals/refarm-catalog","description":"Django application with simple eCommerce catalog","fork":false,"url":"https://api.github.com/repos/fidals/refarm-catalog","forks_url":"https://api.github.com/repos/fidals/refarm-catalog/forks","keys_url":"https://api.github.com/repos/fidals/refarm-catalog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/refarm-catalog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/refarm-catalog/teams","hooks_url":"https://api.github.com/repos/fidals/refarm-catalog/hooks","issue_events_url":"https://api.github.com/repos/fidals/refarm-catalog/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/refarm-catalog/events","assignees_url":"https://api.github.com/repos/fidals/refarm-catalog/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/refarm-catalog/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/refarm-catalog/tags","blobs_url":"https://api.github.com/repos/fidals/refarm-catalog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/refarm-catalog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/refarm-catalog/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/refarm-catalog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/refarm-catalog/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/refarm-catalog/languages","stargazers_url":"https://api.github.com/repos/fidals/refarm-catalog/stargazers","contributors_url":"https://api.github.com/repos/fidals/refarm-catalog/contributors","subscribers_url":"https://api.github.com/repos/fidals/refarm-catalog/subscribers","subscription_url":"https://api.github.com/repos/fidals/refarm-catalog/subscription","commits_url":"https://api.github.com/repos/fidals/refarm-catalog/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/refarm-catalog/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/refarm-catalog/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/refarm-catalog/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/refarm-catalog/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/refarm-catalog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/refarm-catalog/merges","archive_url":"https://api.github.com/repos/fidals/refarm-catalog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/refarm-catalog/downloads","issues_url":"https://api.github.com/repos/fidals/refarm-catalog/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/refarm-catalog/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/refarm-catalog/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/refarm-catalog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/refarm-catalog/labels{/name}","releases_url":"https://api.github.com/repos/fidals/refarm-catalog/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/refarm-catalog/deployments","created_at":"2016-04-12T13:10:31Z","updated_at":"2016-04-28T12:45:35Z","pushed_at":"2016-07-27T09:42:00Z","git_url":"git://github.com/fidals/refarm-catalog.git","ssh_url":"git@github.com:fidals/refarm-catalog.git","clone_url":"https://github.com/fidals/refarm-catalog.git","svn_url":"https://github.com/fidals/refarm-catalog","homepage":"","size":72,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27"},"html":{"href":"https://github.com/fidals/refarm-catalog/pull/27"},"issue":{"href":"https://api.github.com/repos/fidals/refarm-catalog/issues/27"},"comments":{"href":"https://api.github.com/repos/fidals/refarm-catalog/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/fidals/refarm-catalog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fidals/refarm-catalog/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/fidals/refarm-catalog/statuses/c04578d3a7c7ff2c6149aaf9d10f3c77703002ef"}}}}
{"actor":{"display_login":"duker33"}}