from forgeblog import model as M
from forgeblog.tests.unit import BlogTestWithModel

def wrapped(s):
    return '<div class="markdown_content"><p>%s</p></div>' % s

class TestHtmlPreview(BlogTestWithModel):
    def _make_post(self, text):
        post = M.BlogPost()
        post.text = text
        post.make_slug()
        return post

    def test_single_long_paragraph(self):
        text = ("Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
                "sed do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
                "ullamco laboris nisi ut aliquip ex ea commodo consequat. "
                "Duis aute irure dolor in reprehenderit in voluptate velit "
                "esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
                "occaecat cupidatat non proident, sunt in culpa qui officia "
                "deserunt mollit anim id est laborum.")
        assert self._make_post(text).html_text_preview == wrapped(text)

    def test_single_short_paragraph(self):
        text = ("Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
                "sed do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
                "ullamco laboris nisi ut aliquip ex ea commodo consequat.")
        assert self._make_post(text).html_text_preview == wrapped(text)

    def test_multi_paragraph_short(self):
        text = ("Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
                "sed do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua."
                "\n\n"
                "Ut enim ad minim veniam, quis nostrud exercitation "
                "ullamco laboris nisi ut aliquip ex ea commodo consequat.")

        expected = ('<div class="markdown_content"><p>Lorem ipsum dolor sit '
                    'amet, consectetur adipisicing elit, sed do eiusmod '
                    'tempor incididunt ut labore et dolore magna aliqua.</p>\n'
                    '<p>Ut enim ad minim veniam, quis nostrud exercitation '
                    'ullamco laboris nisi ut aliquip ex ea commodo '
                    'consequat.</p></div>')
        assert self._make_post(text).html_text_preview == expected

    def test_multi_paragraph_long(self):
        text = ("Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
                "sed do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua."
                "\n\n"
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
                "sed do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
                "ullamco laboris nisi ut aliquip ex ea commodo consequat. "
                "Duis aute irure dolor in reprehenderit in voluptate velit "
                "esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
                "occaecat cupidatat non proident, sunt in culpa qui officia "
                "deserunt mollit anim id est laborum."
                "\n\n"
                "Ut enim ad minim veniam, quis nostrud exercitation "
                "ullamco laboris nisi ut aliquip ex ea commodo consequat.")

        expected = ('<div class="markdown_content"><p>Lorem ipsum dolor sit '
                    'amet, consectetur adipisicing elit, sed do eiusmod '
                    'tempor incididunt ut labore et dolore magna aliqua.</p>\n'
                    '<p>Lorem ipsum dolor sit amet, consectetur adipisicing '
                    'elit, sed do eiusmod tempor incididunt ut labore et '
                    'dolore magna aliqua. Ut enim ad minim veniam, quis '
                    'nostrud exercitation ullamco laboris nisi ut aliquip ex '
                    'ea commodo consequat. Duis aute irure dolor in '
                    'reprehenderit in voluptate velit esse cillum dolore eu '
                    'fugiat nulla pariatur. Excepteur sint occaecat cupidatat '
                    'non proident, sunt in culpa qui officia deserunt mollit '
                    'anim id est laborum.... '
                    '<a href="/p/test/blog/2011/09/untitled/">read more</a>'
                    '</p></div>')
        assert self._make_post(text).html_text_preview == expected

@@ -1,20 +1,87 @@
+from datetime import datetime%0Afrom nose.tools import assert_equal%0A%0A
 from forgeblog impor
@@ -93,16 +93,16 @@
 el as M%0A
-
 from for
@@ -1045,33 +1045,39 @@
 )%0A        assert
- 
+_equal(
 self._make_post(
@@ -1091,35 +1091,33 @@
 tml_text_preview
- ==
+,
  wrapped(text)%0A%0A
@@ -1106,32 +1106,33 @@
 w, wrapped(text)
+)
 %0A%0A    def test_s
@@ -1475,33 +1475,39 @@
 )%0A        assert
- 
+_equal(
 self._make_post(
@@ -1529,19 +1529,17 @@
 _preview
- ==
+,
  wrapped
@@ -1544,16 +1544,17 @@
 ed(text)
+)
 %0A%0A    de
@@ -2368,33 +2368,39 @@
 )%0A        assert
- 
+_equal(
 self._make_post(
@@ -2414,35 +2414,33 @@
 tml_text_preview
- ==
+,
  expected%0A%0A    d
@@ -2432,16 +2432,17 @@
 expected
+)
 %0A%0A    de
@@ -3440,32 +3440,64 @@
 o consequat.%22)%0A%0A
+        now = datetime.utcnow()%0A
         expected
@@ -4419,15 +4419,13 @@
 log/
-2011/09
+%25s/%25s
 /unt
@@ -4472,32 +4472,56 @@
    '%3C/p%3E%3C/div%3E')
+ %25 (now.year, now.month)
 %0A        assert 
@@ -4519,17 +4519,23 @@
   assert
- 
+_equal(
 self._ma
@@ -4569,11 +4569,9 @@
 view
- ==
+,
  exp
@@ -4575,9 +4575,10 @@
 expected
+)
 %0A

fix time-dependent test