# Path: mdweb/Page.py
# class PageMetaInf(MetaInfParser):  # pylint: disable=R0903
#     """MDWeb Page Meta Information."""
# 
#     def __init__(self, meta_string):
#         """Content page meta-information.
# 
#         If a page defines a non-standard meta value it is blindly included.
# 
#         :param meta_string: Raw meta-inf content as a string
#         """
#         super(PageMetaInf, self).__init__(meta_string)
#         self.nav_name = self.title if self.nav_name is None else self.nav_name
# 
# class Page(NavigationBaseItem):
#     """MDWeb Page View."""
# 
#     def __init__(self, page_path, url_path, file_string):
#         """Initialize Page object."""
# 
#         self.page_path = page_path
#         self.url_path = url_path
# 
#         # Separate the meta information and the page content
#         meta_inf_regex = re.compile(META_INF_REGEX, flags=re.DOTALL)
#         match = meta_inf_regex.search(file_string)
#         meta_inf_string = match.group('metainf') if match.group('metainf') \
#             else ''
#         content_string = match.group('content')
# 
#         self.meta_inf = PageMetaInf(meta_inf_string)
# 
#         # Strip the meta information and comments
#         self.markdown_str = content_string
# 
#         # The page will be rendered on first view
#         self.page_html = self.parse_markdown(self.markdown_str)
# 
#         self.abstract = self.page_html[0:100]
#         
#     @property
#     def is_published(self):
#         return self.meta_inf.published
# 
#     @staticmethod
#     def parse_markdown(page_markdown):
#         """Parse given markdown string into rendered html.
# 
#         :param page_markdown: Markdown to be parsed
#         :return: Rendered page HTML
#         """
#         page_html = markdown.markdown(page_markdown)
# 
#         return page_html
# 
#     def __repr__(self):
#         return '{0}'.format(self.page_path)
# 
# def load_page(content_path, page_path):
#     """Load the page file and return the path, URL and contents"""
# 
#     # Extract the part of the page_path that will be used as the URL path
#     pattern = URL_PATH_REGEX % content_path
#     matches = re.match(pattern, page_path)
#     if matches:
#         url_path = matches.group('path').rstrip('/').lstrip('/')
#     else:
#         raise PageParseException("Unable to parse page path [%s]" %
#                                  content_path)
# 
#     if not os.path.exists(page_path):
#         raise ContentException('Could not find file for content page "%s"' %
#                                page_path)
# 
#     # Read the page file
#     with codecs.open(page_path, 'r', encoding='utf8') as f:
#         file_string = f.read()
# 
#     return page_path, url_path, file_string
# 
# Path: mdweb/Exceptions.py
# class PageMetaInfFieldException(Exception):
#     """Invalid field in page metadata."""
# 
#     pass
# 
# class PageParseException(Exception):
#     """Error parsing page markdown."""
# 
#     pass
# 
# class ContentException(Exception):
#     """Markdown content exception."""
# 
#     pass


import datetime
    import mock
from pyfakefs import fake_filesystem_unittest
from unittest import skip
    from unittest import mock
from mdweb.Page import PageMetaInf, Page, load_page
from mdweb.Exceptions import (
    PageMetaInfFieldException,
    PageParseException,
    ContentException,
)

class TestPageMeta(fake_filesystem_unittest.TestCase):

    """PageMetaInf object tests."""

    def setUp(self):
        """Create fake filesystem."""
        self.setUpPyfakefs()

    def test_parse_empty_string(self):
        """Empty string should parse successfully."""
        file_string = u""

        meta_inf = PageMetaInf(file_string)

        self.assertIsNone(meta_inf.author)
        self.assertIsNone(meta_inf.date)
        self.assertIsNone(meta_inf.description)
        self.assertIsNone(meta_inf.nav_name)
        self.assertEqual(meta_inf.order, 0)
        self.assertIsNone(meta_inf.template)
        self.assertIsNone(meta_inf.title)

    def test_parse_some_fields(self):
        """A few defined fields should parse successfully."""
        file_string = u"""Title: MDWeb
Description: The minimalistic markdown NaCMS
Date: February 1st, 2016
"""


# Path: mdweb/Page.py
# class PageMetaInf(MetaInfParser):  # pylint: disable=R0903
#     """MDWeb Page Meta Information."""
# 
#     def __init__(self, meta_string):
#         """Content page meta-information.
# 
#         If a page defines a non-standard meta value it is blindly included.
# 
#         :param meta_string: Raw meta-inf content as a string
#         """
#         super(PageMetaInf, self).__init__(meta_string)
#         self.nav_name = self.title if self.nav_name is None else self.nav_name
# 
# class Page(NavigationBaseItem):
#     """MDWeb Page View."""
# 
#     def __init__(self, page_path, url_path, file_string):
#         """Initialize Page object."""
# 
#         self.page_path = page_path
#         self.url_path = url_path
# 
#         # Separate the meta information and the page content
#         meta_inf_regex = re.compile(META_INF_REGEX, flags=re.DOTALL)
#         match = meta_inf_regex.search(file_string)
#         meta_inf_string = match.group('metainf') if match.group('metainf') \
#             else ''
#         content_string = match.group('content')
# 
#         self.meta_inf = PageMetaInf(meta_inf_string)
# 
#         # Strip the meta information and comments
#         self.markdown_str = content_string
# 
#         # The page will be rendered on first view
#         self.page_html = self.parse_markdown(self.markdown_str)
# 
#         self.abstract = self.page_html[0:100]
#         
#     @property
#     def is_published(self):
#         return self.meta_inf.published
# 
#     @staticmethod
#     def parse_markdown(page_markdown):
#         """Parse given markdown string into rendered html.
# 
#         :param page_markdown: Markdown to be parsed
#         :return: Rendered page HTML
#         """
#         page_html = markdown.markdown(page_markdown)
# 
#         return page_html
# 
#     def __repr__(self):
#         return '{0}'.format(self.page_path)
# 
# def load_page(content_path, page_path):
#     """Load the page file and return the path, URL and contents"""
# 
#     # Extract the part of the page_path that will be used as the URL path
#     pattern = URL_PATH_REGEX % content_path
#     matches = re.match(pattern, page_path)
#     if matches:
#         url_path = matches.group('path').rstrip('/').lstrip('/')
#     else:
#         raise PageParseException("Unable to parse page path [%s]" %
#                                  content_path)
# 
#     if not os.path.exists(page_path):
#         raise ContentException('Could not find file for content page "%s"' %
#                                page_path)
# 
#     # Read the page file
#     with codecs.open(page_path, 'r', encoding='utf8') as f:
#         file_string = f.read()
# 
#     return page_path, url_path, file_string
# 
# Path: mdweb/Exceptions.py
# class PageMetaInfFieldException(Exception):
#     """Invalid field in page metadata."""
# 
#     pass
# 
# class PageParseException(Exception):
#     """Error parsing page markdown."""
# 
#     pass
# 
# class ContentException(Exception):
#     """Markdown content exception."""
# 
#     pass


# Path: tests/test_page.py
import datetime
    import mock
from pyfakefs import fake_filesystem_unittest
from unittest import skip
    from unittest import mock
from mdweb.Page import PageMetaInf, Page, load_page
from mdweb.Exceptions import (
    PageMetaInfFieldException,
    PageParseException,
    ContentException,
)


class TestPageMeta(fake_filesystem_unittest.TestCase):

    """PageMetaInf object tests."""

    def setUp(self):
        """Create fake filesystem."""
        self.setUpPyfakefs()

    def test_parse_empty_string(self):
        """Empty string should parse successfully."""
        file_string = u""

        meta_inf = PageMetaInf(file_string)

        self.assertIsNone(meta_inf.author)
        self.assertIsNone(meta_inf.date)
        self.assertIsNone(meta_inf.description)
        self.assertIsNone(meta_inf.nav_name)
        self.assertEqual(meta_inf.order, 0)
        self.assertIsNone(meta_inf.template)
        self.assertIsNone(meta_inf.title)

    def test_parse_some_fields(self):
        """A few defined fields should parse successfully."""
        file_string = u"""Title: MDWeb
Description: The minimalistic markdown NaCMS
Date: February 1st, 2016
"""


        meta_inf = PageMetaInf(file_string)