Beispiel #1
0
 def _test_status_modified(self, **kwargs):
     path = 'a/b/test.page'
     self._make_file(path, self.edited_content)
     FilePageLoader(path).save()
     page = Page.objects.get(url='/a/b/test/')
     for attr, value in kwargs.items():
         setattr(page, attr, value)
     page.save()
     loader = FilePageLoader(path)
     self.assertEqual(loader.status(), SyncStatus.MODIFIED)
Beispiel #2
0
 def test_page_fields_edited(self):
     path = 'a/b/test.page'
     self._make_file(path, self.edited_content)
     loader = FilePageLoader(path)
     self.assertEqual(
         loader.page_fields(), {
             'alias': 'test-page',
             'description': 'At vero eos et accusamus et iusto odio',
             'keywords': 'lorem ipsum dolor sit amet',
             'page_processor': 'powerpages.RedirectProcessor',
             'page_processor_config': {
                 'to url': '/test/'
             },
             'template': '<h1>{{ website_page.title }}</h1>\n',
             'title': 'De Finibus Bonorum et Malorum'
         })
Beispiel #3
0
    def test_diff_template_modified(self):
        path = 'a/b/test.page'
        self._make_file(path, self.edited_content)
        FilePageLoader(path).save()
        page = Page.objects.get(url='/a/b/test/')
        page.template = 'TEST'
        page.save()
        loader = FilePageLoader(path)
        self.assertEqual(
            loader.diff(),
            _file_contents('''--- Current content

+++ Coming changes

@@ -9,4 +9,4 @@

   "title": "De Finibus Bonorum et Malorum"
 }
 ## TEMPLATE SOURCE: ##
-TEST
+<h1>{{ website_page.title }}</h1>'''))
Beispiel #4
0
    def test_diff_title_modified(self):
        path = 'a/b/test.page'
        self._make_file(path, self.edited_content)
        FilePageLoader(path).save()
        page = Page.objects.get(url='/a/b/test/')
        page.title = 'CHANGE'
        page.save()
        loader = FilePageLoader(path)
        self.assertEqual(
            loader.diff(),
            _file_contents('''--- Current content

+++ Coming changes

@@ -6,7 +6,7 @@

   "page_processor_config": {
     "to url": "/test/"
   },
-  "title": "CHANGE"
+  "title": "De Finibus Bonorum et Malorum"
 }
 ## TEMPLATE SOURCE: ##
 <h1>{{ website_page.title }}</h1>'''))
Beispiel #5
0
 def test_status_no_changes(self):
     path = 'a/b/test.page'
     self._make_file(path, self.edited_content)
     FilePageLoader(path).save()
     loader = FilePageLoader(path)
     self.assertEqual(loader.status(), SyncStatus.NO_CHANGES)
Beispiel #6
0
 def test_status_added(self):
     path = 'a/b/test.page'
     self._make_file(path, self.edited_content)
     loader = FilePageLoader(path)
     self.assertEqual(loader.status(), SyncStatus.ADDED)
Beispiel #7
0
 def test_page_non_existing(self):
     path = 'a/b/test.page'
     self._make_file(path, self.normalized_content)
     loader = FilePageLoader(path)
     self.assertIsNone(loader.page())
Beispiel #8
0
 def test_page_existing(self):
     page = Page.objects.create(url='/a/b/test/')
     path = 'a/b/test.page'
     self._make_file(path, self.normalized_content)
     loader = FilePageLoader(path)
     self.assertEqual(loader.page(), page)
Beispiel #9
0
 def test_file_contents(self):
     path = 'a/b/test.page'
     self._make_file(path, self.edited_content)
     loader = FilePageLoader(path)
     self.assertEqual(loader.file_contents(), self.edited_content)
Beispiel #10
0
 def test_absolute_path(self):
     loader = FilePageLoader('a/b/test.page')
     self.assertEqual(loader.absolute_path(),
                      os.path.join(self.sync_directory, 'a/b/test.page'))
Beispiel #11
0
 def test_relative_path_txt(self):
     loader = FilePageLoader('robots.txt')
     self.assertEqual(loader.url(), '/robots.txt')
Beispiel #12
0
 def test_url_nested(self):
     loader = FilePageLoader('a/b/test.page')
     self.assertEqual(loader.url(), '/a/b/test/')
Beispiel #13
0
 def test_url_root(self):
     loader = FilePageLoader('_index_.page')
     self.assertEqual(loader.url(), '/')
Beispiel #14
0
 def test_data_normalization(self):
     self.assertEqual(
         normalize_page_fields(FilePageLoader.load(
             self.normalized_content)),
         normalize_page_fields(FilePageLoader.load(self.edited_content)))