{"action":"created","comment":{"url":"https://api.github.com/repos/fidals/refarm-site/pulls/comments/72468814","id":72468814,"diff_hunk":"@@ -3,152 +3,133 @@\n \"\"\"\n \n from django.test import TestCase\n-from pages.models import Post, get_crumbs\n from django.core.urlresolvers import reverse\n-from .model_factory import set_default_posts\n from django.conf import settings\n \n+from pages.models import Page, get_or_create_struct_page\n \n-class PostTests(TestCase):\n \n-    urls = 'tests.urls'\n-\n-    def setUp(self):\n-        set_default_posts(self)\n-\n-    def tearDown(self):\n-        Post.objects.all().delete()\n-\n-    def test_posts_types_list(self):\n-        \"\"\"\n-        Blog pages list should contain all post types\n-        \"\"\"\n-        url = reverse('pages:post_types')\n-        response = self.client.get(url)\n-        self.assertEqual(response.status_code, 200)\n-        self.assertContains(response,\n-                            settings.APP_BLOG_POST_TYPES['navigation']['name'])\n-        self.assertContains(response,\n-                            settings.APP_BLOG_POST_TYPES['news']['name'])\n+class PageTests(TestCase):\n \n-    def test_empty_posts_list(self):\n-        \"\"\"\n-        Empty pages list should return 200 response\n-         and user friendly message\n-        \"\"\"\n-        self.tearDown()\n-        url = reverse('pages:posts', args=('news',))\n-        response = self.client.get(url)\n-        self.assertEqual(response.status_code, 200)\n-        self.assertContains(response, 'There are no posts yet')\n-        self.setUp()  # restore mock objects after over removing\n-\n-    def test_not_found_posts_list(self):\n-        \"\"\"Not existing posts list should return 404 status code\"\"\"\n-        url = '/pages/se-ipo/'\n-        response = self.client.get(url)\n-        self.assertEqual(response.status_code, 404)\n-\n-    def test_posts_list(self):\n-        \"\"\"\n-        List of existing pages should return 200 response\n-        And list names, of course\n-        \"\"\"\n-\n-        url = reverse('pages:posts', args=('article',))\n-        response = self.client.get(url)\n-        self.assertEqual(response.status_code, 200)\n-        self.assertContains(response, \"Why Fenich called as new Steve Jobs\")\n+    urls = 'tests.urls'\n \n-    def test_post_not_found(self):\n-        \"\"\"Not found page should return 404 code.\"\"\"\n+    @classmethod\n+    def setUpClass(cls):\n+        super(PageTests, cls).setUpClass()\n \n-        url = reverse(\n-            'pages:navigation',\n-            kwargs={'slug_': 987654}  # not existing id\n+        # -- set up section navi --\n+        cls.section_navi = Page.objects.create(\n+            title='Navigation on SE web portal',\n+            slug='navigation'\n         )\n-        response = self.client.get(url)\n-        self.assertEqual(response.status_code, 404)\n-\n-    def test_post_by_id(self):\n-        \"\"\"Existing page should return 200 response\"\"\"\n \n-        url = reverse(\n-            'pages:news',\n-            kwargs={'slug_': self.test_news_post.slug}\n+        cls.page_default_contacts = Page.objects.create(\n+            slug='contacts',\n+            parent=cls.section_navi,\n+            title='Here you can see Fenichs contacts. He reads every mail!',\n+            menu_title='contacts',\n         )\n-        response = self.client.get(url)\n-        self.assertEqual(response.status_code, 200)\n-\n \n-class BreadcrumbsTests(TestCase):\n+        cls.page_default_delivery = Page.objects.create(\n+            slug='delivery',\n+            parent=cls.section_navi,\n+            title='How SE logistic system works',\n+            menu_title='delivery'\n+        )\n \n-    urls = 'tests.urls'\n+        # -- set up section news --\n+        cls.section_news = Page.objects.create(\n+            title='News of SE corporation',\n+            slug='news'\n+        )\n \n-    def setUp(self):\n-        set_default_posts(self)\n+        cls.page_default_ipo = Page.objects.create(\n+            slug='se-ipo',\n+            parent=cls.section_news,\n+            title='ShopElectro go to IPO only after 15-n investment rounds'\n+        )\n \n-    def tearDown(self):\n-        Post.objects.all().delete()\n+        cls.page_default_jobs = Page.objects.create(\n+            slug='fenich-new-jobs',\n+            parent=cls.section_news,\n+            title='Why Fenich called as new Steve Jobs'\n+        )\n \n-    def test_get_crumbs_names_by_post(self):\n+    def test_empty_pages_list(self):\n         \"\"\"\n-        by given post _get_crumbs should return valid crumb names\n+        Empty pages list should return 200 response and user friendly message\n         \"\"\"\n-        crumbs = get_crumbs(self.test_news_post)\n-        self.assertEqual(crumbs[0].name, settings.CRUMBS['main'])\n-        self.assertEqual(crumbs[1].name, self.test_news_post.get_type_name())\n-        self.assertEqual(crumbs[2].name, self.test_news_post.name)\n+        section_empty = Page.objects.create(\n+            slug='empty-section',\n+            title='Empty pages list'\n+        )\n+        response = self.client.get(section_empty.get_absolute_url())\n+        self.assertEqual(response.status_code, 200)\n+        self.assertContains(response, 'No sub pages')\n+\n+    def test_pages_list(self):\n+        \"\"\"Page section should contain it's children\"\"\"\n+        section = self.section_navi\n+        child_fist = self.page_default_contacts\n+        child_second = self.page_default_delivery\n+        response = self.client.get(section.get_absolute_url())\n+        self.assertEqual(response.status_code, 200)\n \n-    def test_get_crumbs_aliases_by_post(self):\n-        \"\"\"\n-        by given post _get_crumbs should return crumbs with:\n-            1. empty alias for last crumb\n-            2. filled aliases for every other crumb\n-        \"\"\"\n-        crumbs = get_crumbs(self.test_news_post)\n-        self.assertEqual(crumbs[0].alias, '/')\n-        self.assertEqual(crumbs[1].alias,\n-                         reverse('pages:posts', args=('news',)))\n-        self.assertEqual(crumbs[2].alias, '')\n+        self.assertContains(response, child_fist.title)\n+        self.assertContains(response, child_fist.get_absolute_url())\n \n-    def test_get_crumbs_names_by_page(self):\n+        self.assertContains(response, child_second.title)\n+        self.assertContains(response, child_second.get_absolute_url())\n+\n+    def test_nested_page_redirects(self):\n         \"\"\"\n-        by given page _get_crumbs should return valid crumb names\n+        Suppose page \"contacts\" in DB have url /navi/contacts/. Then:\n+        /contacts/ --301--> /navi/contacts/\n         \"\"\"\n-        crumbs = get_crumbs(settings.CRUMBS['pages'])\n-        self.assertEqual(crumbs[0].name, settings.CRUMBS['main'])\n-        self.assertEqual(crumbs[1].name, settings.CRUMBS['pages'])\n+        page = self.page_default_contacts\n+        url = '/contacts/'\n+        response = self.client.get(url)\n+        self.assertEqual(response.status_code, 301)\n+        self.assertEqual(response.url, page.get_absolute_url())\n \n-    def test_get_crumbs_aliases_by_page(self):\n+    def test_nested_page_not_found(self):\n         \"\"\"\n-        by given page _get_crumbs should return valid crumbs\n+        Suppose page \"contacts\" in DB have url /navi/contacts/. Then:\n+        /news/contacts/ return 404 status code\n         \"\"\"\n-        crumbs = get_crumbs(settings.CRUMBS['pages'])\n-        self.assertEqual(crumbs[0].alias, '/')\n-        self.assertEqual(crumbs[1].alias, '')\n+        url = '/news/contacts/'","path":"tests/tests_views.py","position":197,"original_position":197,"commit_id":"bc81a03112fcbc965df5b5bc2519d3c5fb18d084","original_commit_id":"bc81a03112fcbc965df5b5bc2519d3c5fb18d084","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":"@YozhEzhi , переменная url нужна для того, чтобы тесты можно было легко копипастить, искать и переопределять.\r\n\r\nОбсуждали похожую мысль про page в шаблонах:\r\nhttps://github.com/fidals/refarm-catalog/pull/27#discussion-diff-72397247R60","created_at":"2016-07-27T16:01:22Z","updated_at":"2016-07-27T16:01:22Z","html_url":"https://github.com/fidals/refarm-site/pull/15#discussion_r72468814","pull_request_url":"https://api.github.com/repos/fidals/refarm-site/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/fidals/refarm-site/pulls/comments/72468814"},"html":{"href":"https://github.com/fidals/refarm-site/pull/15#discussion_r72468814"},"pull_request":{"href":"https://api.github.com/repos/fidals/refarm-site/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/fidals/refarm-site/pulls/15","id":78876874,"html_url":"https://github.com/fidals/refarm-site/pull/15","diff_url":"https://github.com/fidals/refarm-site/pull/15.diff","patch_url":"https://github.com/fidals/refarm-site/pull/15.patch","issue_url":"https://api.github.com/repos/fidals/refarm-site/issues/15","number":15,"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:28Z","updated_at":"2016-07-27T16:01:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"63d14bab70164f9ae381f8f9c45427e29983ad50","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/fidals/refarm-site/pulls/15/commits","review_comments_url":"https://api.github.com/repos/fidals/refarm-site/pulls/15/comments","review_comment_url":"https://api.github.com/repos/fidals/refarm-site/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fidals/refarm-site/issues/15/comments","statuses_url":"https://api.github.com/repos/fidals/refarm-site/statuses/bc81a03112fcbc965df5b5bc2519d3c5fb18d084","head":{"label":"fidals:f-763_site_app","ref":"f-763_site_app","sha":"bc81a03112fcbc965df5b5bc2519d3c5fb18d084","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":55603017,"name":"refarm-site","full_name":"fidals/refarm-site","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-site","description":"Django application with simple blog functions","fork":false,"url":"https://api.github.com/repos/fidals/refarm-site","forks_url":"https://api.github.com/repos/fidals/refarm-site/forks","keys_url":"https://api.github.com/repos/fidals/refarm-site/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/refarm-site/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/refarm-site/teams","hooks_url":"https://api.github.com/repos/fidals/refarm-site/hooks","issue_events_url":"https://api.github.com/repos/fidals/refarm-site/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/refarm-site/events","assignees_url":"https://api.github.com/repos/fidals/refarm-site/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/refarm-site/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/refarm-site/tags","blobs_url":"https://api.github.com/repos/fidals/refarm-site/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/refarm-site/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/refarm-site/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/refarm-site/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/refarm-site/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/refarm-site/languages","stargazers_url":"https://api.github.com/repos/fidals/refarm-site/stargazers","contributors_url":"https://api.github.com/repos/fidals/refarm-site/contributors","subscribers_url":"https://api.github.com/repos/fidals/refarm-site/subscribers","subscription_url":"https://api.github.com/repos/fidals/refarm-site/subscription","commits_url":"https://api.github.com/repos/fidals/refarm-site/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/refarm-site/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/refarm-site/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/refarm-site/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/refarm-site/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/refarm-site/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/refarm-site/merges","archive_url":"https://api.github.com/repos/fidals/refarm-site/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/refarm-site/downloads","issues_url":"https://api.github.com/repos/fidals/refarm-site/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/refarm-site/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/refarm-site/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/refarm-site/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/refarm-site/labels{/name}","releases_url":"https://api.github.com/repos/fidals/refarm-site/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/refarm-site/deployments","created_at":"2016-04-06T12:14:48Z","updated_at":"2016-07-07T09:13:32Z","pushed_at":"2016-07-26T15:50:28Z","git_url":"git://github.com/fidals/refarm-site.git","ssh_url":"git@github.com:fidals/refarm-site.git","clone_url":"https://github.com/fidals/refarm-site.git","svn_url":"https://github.com/fidals/refarm-site","homepage":"","size":40,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"fidals:master","ref":"master","sha":"f89201d35f394141e2da215f4521e138c9647888","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":55603017,"name":"refarm-site","full_name":"fidals/refarm-site","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-site","description":"Django application with simple blog functions","fork":false,"url":"https://api.github.com/repos/fidals/refarm-site","forks_url":"https://api.github.com/repos/fidals/refarm-site/forks","keys_url":"https://api.github.com/repos/fidals/refarm-site/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/refarm-site/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/refarm-site/teams","hooks_url":"https://api.github.com/repos/fidals/refarm-site/hooks","issue_events_url":"https://api.github.com/repos/fidals/refarm-site/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/refarm-site/events","assignees_url":"https://api.github.com/repos/fidals/refarm-site/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/refarm-site/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/refarm-site/tags","blobs_url":"https://api.github.com/repos/fidals/refarm-site/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/refarm-site/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/refarm-site/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/refarm-site/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/refarm-site/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/refarm-site/languages","stargazers_url":"https://api.github.com/repos/fidals/refarm-site/stargazers","contributors_url":"https://api.github.com/repos/fidals/refarm-site/contributors","subscribers_url":"https://api.github.com/repos/fidals/refarm-site/subscribers","subscription_url":"https://api.github.com/repos/fidals/refarm-site/subscription","commits_url":"https://api.github.com/repos/fidals/refarm-site/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/refarm-site/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/refarm-site/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/refarm-site/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/refarm-site/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/refarm-site/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/refarm-site/merges","archive_url":"https://api.github.com/repos/fidals/refarm-site/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/refarm-site/downloads","issues_url":"https://api.github.com/repos/fidals/refarm-site/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/refarm-site/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/refarm-site/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/refarm-site/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/refarm-site/labels{/name}","releases_url":"https://api.github.com/repos/fidals/refarm-site/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/refarm-site/deployments","created_at":"2016-04-06T12:14:48Z","updated_at":"2016-07-07T09:13:32Z","pushed_at":"2016-07-26T15:50:28Z","git_url":"git://github.com/fidals/refarm-site.git","ssh_url":"git@github.com:fidals/refarm-site.git","clone_url":"https://github.com/fidals/refarm-site.git","svn_url":"https://github.com/fidals/refarm-site","homepage":"","size":40,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fidals/refarm-site/pulls/15"},"html":{"href":"https://github.com/fidals/refarm-site/pull/15"},"issue":{"href":"https://api.github.com/repos/fidals/refarm-site/issues/15"},"comments":{"href":"https://api.github.com/repos/fidals/refarm-site/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/fidals/refarm-site/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/fidals/refarm-site/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fidals/refarm-site/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/fidals/refarm-site/statuses/bc81a03112fcbc965df5b5bc2519d3c5fb18d084"}}}}
{"actor":{"display_login":"duker33"}}