Flake8 corrections
parent
5e95175654
commit
bb73c2c06d
|
@ -6,6 +6,7 @@
|
||||||
import re
|
import re
|
||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
|
|
||||||
# We can't re-use the built-in AutolinkPattern because we need to add protocols
|
# We can't re-use the built-in AutolinkPattern because we need to add protocols
|
||||||
# to links without them.
|
# to links without them.
|
||||||
class AutolinkPattern(markdown.inlinepatterns.Pattern):
|
class AutolinkPattern(markdown.inlinepatterns.Pattern):
|
||||||
|
@ -20,6 +21,7 @@ class AutolinkPattern(markdown.inlinepatterns.Pattern):
|
||||||
el.text = markdown.util.AtomicString(m.group(2))
|
el.text = markdown.util.AtomicString(m.group(2))
|
||||||
return el
|
return el
|
||||||
|
|
||||||
|
|
||||||
class AutolinkExtension(markdown.Extension):
|
class AutolinkExtension(markdown.Extension):
|
||||||
"""An extension that turns all URLs into links.
|
"""An extension that turns all URLs into links.
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
# for details. All rights reserved. Use of this source code is governed by a
|
# for details. All rights reserved. Use of this source code is governed by a
|
||||||
# BSD-style license that can be found in the LICENSE file.
|
# BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import re
|
|
||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
|
|
||||||
# We can't re-use the built-in AutomailPattern because we need to add mailto:.
|
# We can't re-use the built-in AutomailPattern because we need to add mailto:.
|
||||||
# We also don't care about HTML-encoding the email.
|
# We also don't care about HTML-encoding the email.
|
||||||
class AutomailPattern(markdown.inlinepatterns.Pattern):
|
class AutomailPattern(markdown.inlinepatterns.Pattern):
|
||||||
|
@ -15,6 +15,7 @@ class AutomailPattern(markdown.inlinepatterns.Pattern):
|
||||||
el.text = markdown.util.AtomicString(m.group(2))
|
el.text = markdown.util.AtomicString(m.group(2))
|
||||||
return el
|
return el
|
||||||
|
|
||||||
|
|
||||||
class AutomailExtension(markdown.Extension):
|
class AutomailExtension(markdown.Extension):
|
||||||
"""An extension that turns all email addresses into links."""
|
"""An extension that turns all email addresses into links."""
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#-*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Tested on Markdown 2.3.1
|
# Tested on Markdown 2.3.1
|
||||||
#
|
#
|
||||||
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import os
|
|
||||||
|
|
||||||
from markdown.extensions import Extension
|
from markdown.extensions import Extension
|
||||||
from markdown.preprocessors import Preprocessor
|
from markdown.preprocessors import Preprocessor
|
||||||
|
@ -167,7 +166,7 @@ class EmojifyPreprocessor(Preprocessor):
|
||||||
def emojify(match):
|
def emojify(match):
|
||||||
emoji = match.group(1)
|
emoji = match.group(1)
|
||||||
|
|
||||||
if not emoji in emojis_set:
|
if emoji not in emojis_set:
|
||||||
return match.group(0)
|
return match.group(0)
|
||||||
|
|
||||||
url = emojis_path + emoji + u'.png'
|
url = emojis_path + emoji + u'.png'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#-*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Tested on Markdown 2.3.1
|
# Tested on Markdown 2.3.1
|
||||||
#
|
#
|
||||||
|
@ -23,10 +23,6 @@
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
import os
|
|
||||||
|
|
||||||
from markdown.extensions import Extension
|
from markdown.extensions import Extension
|
||||||
from markdown.inlinepatterns import Pattern
|
from markdown.inlinepatterns import Pattern
|
||||||
from markdown.util import etree
|
from markdown.util import etree
|
||||||
|
@ -39,9 +35,7 @@ class MentionsExtension(Extension):
|
||||||
MENTION_RE = r'(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-]+)'
|
MENTION_RE = r'(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-]+)'
|
||||||
mentionsPattern = MentionsPattern(MENTION_RE)
|
mentionsPattern = MentionsPattern(MENTION_RE)
|
||||||
mentionsPattern.md = md
|
mentionsPattern.md = md
|
||||||
md.inlinePatterns.add('mentions',
|
md.inlinePatterns.add('mentions', mentionsPattern, '_begin')
|
||||||
mentionsPattern,
|
|
||||||
'_begin')
|
|
||||||
|
|
||||||
|
|
||||||
class MentionsPattern(Pattern):
|
class MentionsPattern(Pattern):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#-*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Tested on Markdown 2.3.1
|
# Tested on Markdown 2.3.1
|
||||||
#
|
#
|
||||||
|
@ -23,10 +23,6 @@
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
import os
|
|
||||||
|
|
||||||
from markdown.extensions import Extension
|
from markdown.extensions import Extension
|
||||||
from markdown.inlinepatterns import Pattern
|
from markdown.inlinepatterns import Pattern
|
||||||
from markdown.util import etree
|
from markdown.util import etree
|
||||||
|
@ -43,9 +39,8 @@ class TaigaReferencesExtension(Extension):
|
||||||
TAIGA_REFERENCE_RE = r'(?<=^|(?<=[^a-zA-Z0-9-\[]))#(\d+)'
|
TAIGA_REFERENCE_RE = r'(?<=^|(?<=[^a-zA-Z0-9-\[]))#(\d+)'
|
||||||
referencesPattern = TaigaReferencesPattern(TAIGA_REFERENCE_RE, self.project)
|
referencesPattern = TaigaReferencesPattern(TAIGA_REFERENCE_RE, self.project)
|
||||||
referencesPattern.md = md
|
referencesPattern.md = md
|
||||||
md.inlinePatterns.add('taiga-references',
|
md.inlinePatterns.add('taiga-references', referencesPattern, '_begin')
|
||||||
referencesPattern,
|
|
||||||
'_begin')
|
|
||||||
|
|
||||||
class TaigaReferencesPattern(Pattern):
|
class TaigaReferencesPattern(Pattern):
|
||||||
def __init__(self, pattern, project):
|
def __init__(self, pattern, project):
|
||||||
|
@ -73,7 +68,6 @@ class TaigaReferencesPattern(Pattern):
|
||||||
else:
|
else:
|
||||||
return "#{}".format(obj_ref)
|
return "#{}".format(obj_ref)
|
||||||
|
|
||||||
|
|
||||||
url = "/#/project/{}/{}/{}".format(
|
url = "/#/project/{}/{}/{}".format(
|
||||||
self.project.slug,
|
self.project.slug,
|
||||||
obj_section,
|
obj_section,
|
||||||
|
|
|
@ -2,15 +2,17 @@
|
||||||
# for details. All rights reserved. Use of this source code is governed by a
|
# for details. All rights reserved. Use of this source code is governed by a
|
||||||
# BSD-style license that can be found in the LICENSE file.
|
# BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import re
|
|
||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
|
|
||||||
class SemiSaneOListProcessor(markdown.blockprocessors.OListProcessor):
|
class SemiSaneOListProcessor(markdown.blockprocessors.OListProcessor):
|
||||||
SIBLING_TAGS = ['ol']
|
SIBLING_TAGS = ['ol']
|
||||||
|
|
||||||
|
|
||||||
class SemiSaneUListProcessor(markdown.blockprocessors.UListProcessor):
|
class SemiSaneUListProcessor(markdown.blockprocessors.UListProcessor):
|
||||||
SIBLING_TAGS = ['ul']
|
SIBLING_TAGS = ['ul']
|
||||||
|
|
||||||
|
|
||||||
class SemiSaneListExtension(markdown.Extension):
|
class SemiSaneListExtension(markdown.Extension):
|
||||||
"""An extension that causes lists to be treated the same way GitHub does.
|
"""An extension that causes lists to be treated the same way GitHub does.
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ SPACED_IMAGE_LINK_RE = markdown.inlinepatterns.IMAGE_LINK_RE.replace(
|
||||||
SPACED_IMAGE_REFERENCE_RE = markdown.inlinepatterns.IMAGE_REFERENCE_RE.replace(
|
SPACED_IMAGE_REFERENCE_RE = markdown.inlinepatterns.IMAGE_REFERENCE_RE.replace(
|
||||||
r'\!' + BRK, r'\!' + BRK + SPACE)
|
r'\!' + BRK, r'\!' + BRK + SPACE)
|
||||||
|
|
||||||
|
|
||||||
class SpacedLinkExtension(markdown.Extension):
|
class SpacedLinkExtension(markdown.Extension):
|
||||||
"""An extension that supports links and images with additional whitespace.
|
"""An extension that supports links and images with additional whitespace.
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import markdown
|
||||||
|
|
||||||
STRIKE_RE = r'(~{2})(.+?)(~{2})' # ~~strike~~
|
STRIKE_RE = r'(~{2})(.+?)(~{2})' # ~~strike~~
|
||||||
|
|
||||||
|
|
||||||
class StrikethroughExtension(markdown.Extension):
|
class StrikethroughExtension(markdown.Extension):
|
||||||
"""An extension that supports PHP-Markdown style strikethrough.
|
"""An extension that supports PHP-Markdown style strikethrough.
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,21 @@ from markdown.inlinepatterns import Pattern
|
||||||
from markdown.util import etree
|
from markdown.util import etree
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def build_url(label, base, end):
|
def build_url(label, base, end):
|
||||||
""" Build a url from the label, a base, and an end. """
|
""" Build a url from the label, a base, and an end. """
|
||||||
clean_label = re.sub(r'([ ]+_)|(_[ ]+)|([ ]+)', '_', label)
|
clean_label = re.sub(r'([ ]+_)|(_[ ]+)|([ ]+)', '_', label)
|
||||||
return '%s%s%s'% (base, clean_label, end)
|
return '%s%s%s' % (base, clean_label, end)
|
||||||
|
|
||||||
|
|
||||||
class WikiLinkExtension(Extension):
|
class WikiLinkExtension(Extension):
|
||||||
def __init__(self, configs):
|
def __init__(self, configs):
|
||||||
# set extension defaults
|
# set extension defaults
|
||||||
self.config = {
|
self.config = {
|
||||||
'base_url' : ['/', 'String to append to beginning or URL.'],
|
'base_url': ['/', 'String to append to beginning or URL.'],
|
||||||
'end_url' : ['/', 'String to append to end of URL.'],
|
'end_url': ['/', 'String to append to end of URL.'],
|
||||||
'html_class' : ['wikilink', 'CSS hook. Leave blank for none.'],
|
'html_class': ['wikilink', 'CSS hook. Leave blank for none.'],
|
||||||
'build_url' : [build_url, 'Callable formats URL from label.'],
|
'build_url': [build_url, 'Callable formats URL from label.'],
|
||||||
}
|
}
|
||||||
configs = dict(configs) or {}
|
configs = dict(configs) or {}
|
||||||
# Override defaults with user settings
|
# Override defaults with user settings
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import taiga.base
|
|
||||||
from taiga.mdrender.extensions import mentions
|
|
||||||
from taiga.mdrender.extensions import emojify
|
from taiga.mdrender.extensions import emojify
|
||||||
from taiga.mdrender.service import render, cache_by_sha, get_diff_of_htmls, render_and_extract
|
from taiga.mdrender.service import render, cache_by_sha, get_diff_of_htmls, render_and_extract
|
||||||
|
|
||||||
from taiga.projects.references import services
|
|
||||||
|
|
||||||
from taiga.users.models import User
|
from taiga.users.models import User
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -17,14 +11,17 @@ dummy_project = MagicMock()
|
||||||
dummy_project.id = 1
|
dummy_project.id = 1
|
||||||
dummy_project.slug = "test"
|
dummy_project.slug = "test"
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_valid_emoji():
|
def test_proccessor_valid_emoji():
|
||||||
result = emojify.EmojifyPreprocessor().run(["**:smile:**"])
|
result = emojify.EmojifyPreprocessor().run(["**:smile:**"])
|
||||||
assert result == ["****"]
|
assert result == ["****"]
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_invalid_emoji():
|
def test_proccessor_invalid_emoji():
|
||||||
result = emojify.EmojifyPreprocessor().run(["**:notvalidemoji:**"])
|
result = emojify.EmojifyPreprocessor().run(["**:notvalidemoji:**"])
|
||||||
assert result == ["**:notvalidemoji:**"]
|
assert result == ["**:notvalidemoji:**"]
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_valid_user_mention():
|
def test_proccessor_valid_user_mention():
|
||||||
with patch("taiga.mdrender.extensions.mentions.User") as mock:
|
with patch("taiga.mdrender.extensions.mentions.User") as mock:
|
||||||
instance = mock.objects.get.return_value
|
instance = mock.objects.get.return_value
|
||||||
|
@ -33,6 +30,7 @@ def test_proccessor_valid_user_mention():
|
||||||
expected_result = "<p><strong><a alt=\"test name\" class=\"mention\" href=\"/#/profile/user1\" title=\"test name\">@user1</a></strong></p>"
|
expected_result = "<p><strong><a alt=\"test name\" class=\"mention\" href=\"/#/profile/user1\" title=\"test name\">@user1</a></strong></p>"
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_invalid_user_mention():
|
def test_proccessor_invalid_user_mention():
|
||||||
with patch("taiga.mdrender.extensions.mentions.User") as mock:
|
with patch("taiga.mdrender.extensions.mentions.User") as mock:
|
||||||
mock.DoesNotExist = User.DoesNotExist
|
mock.DoesNotExist = User.DoesNotExist
|
||||||
|
@ -40,6 +38,7 @@ def test_proccessor_invalid_user_mention():
|
||||||
result = render(dummy_project, "**@notvaliduser**")
|
result = render(dummy_project, "**@notvaliduser**")
|
||||||
assert result == '<p><strong>@notvaliduser</strong></p>'
|
assert result == '<p><strong>@notvaliduser</strong></p>'
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_valid_us_reference():
|
def test_proccessor_valid_us_reference():
|
||||||
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
||||||
instance = mock.return_value
|
instance = mock.return_value
|
||||||
|
@ -49,97 +48,117 @@ def test_proccessor_valid_us_reference():
|
||||||
expected_result = '<p><strong><a alt="test" class="reference user-story" href="/#/project/test/user-story/1" title="test">#1</a></strong></p>'
|
expected_result = '<p><strong><a alt="test" class="reference user-story" href="/#/project/test/user-story/1" title="test">#1</a></strong></p>'
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_valid_issue_reference():
|
def test_proccessor_valid_issue_reference():
|
||||||
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
||||||
instance = mock.return_value
|
instance = mock.return_value
|
||||||
instance.content_type.model = "issue"
|
instance.content_type.model = "issue"
|
||||||
instance.content_object.subject = "test"
|
instance.content_object.subject = "test"
|
||||||
result = render(dummy_project, "**#1**")
|
result = render(dummy_project, "**#2**")
|
||||||
expected_result = '<p><strong><a alt="test" class="reference issue" href="/#/project/test/issues/1" title="test">#1</a></strong></p>'
|
expected_result = '<p><strong><a alt="test" class="reference issue" href="/#/project/test/issues/2" title="test">#2</a></strong></p>'
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_valid_task_reference():
|
def test_proccessor_valid_task_reference():
|
||||||
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
||||||
instance = mock.return_value
|
instance = mock.return_value
|
||||||
instance.content_type.model = "task"
|
instance.content_type.model = "task"
|
||||||
instance.content_object.subject = "test"
|
instance.content_object.subject = "test"
|
||||||
result = render(dummy_project, "**#1**")
|
result = render(dummy_project, "**#3**")
|
||||||
expected_result = '<p><strong><a alt="test" class="reference task" href="/#/project/test/tasks/1" title="test">#1</a></strong></p>'
|
expected_result = '<p><strong><a alt="test" class="reference task" href="/#/project/test/tasks/3" title="test">#3</a></strong></p>'
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_invalid_type_reference():
|
def test_proccessor_invalid_type_reference():
|
||||||
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
||||||
instance = mock.return_value
|
instance = mock.return_value
|
||||||
instance.content_type.model = "other"
|
instance.content_type.model = "other"
|
||||||
instance.content_object.subject = "test"
|
instance.content_object.subject = "test"
|
||||||
result = render(dummy_project, "**#1**")
|
result = render(dummy_project, "**#4**")
|
||||||
assert result == "<p><strong>#1</strong></p>"
|
assert result == "<p><strong>#4</strong></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_proccessor_invalid_reference():
|
def test_proccessor_invalid_reference():
|
||||||
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
||||||
mock.return_value = None
|
mock.return_value = None
|
||||||
result = render(dummy_project, "**#1**")
|
result = render(dummy_project, "**#5**")
|
||||||
assert result == "<p><strong>#1</strong></p>"
|
assert result == "<p><strong>#5</strong></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_wiki_strong():
|
def test_render_wiki_strong():
|
||||||
assert render(dummy_project, "**test**") == "<p><strong>test</strong></p>"
|
assert render(dummy_project, "**test**") == "<p><strong>test</strong></p>"
|
||||||
assert render(dummy_project, "__test__") == "<p><strong>test</strong></p>"
|
assert render(dummy_project, "__test__") == "<p><strong>test</strong></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_wiki_italic():
|
def test_render_wiki_italic():
|
||||||
assert render(dummy_project, "*test*") == "<p><em>test</em></p>"
|
assert render(dummy_project, "*test*") == "<p><em>test</em></p>"
|
||||||
assert render(dummy_project, "_test_") == "<p><em>test</em></p>"
|
assert render(dummy_project, "_test_") == "<p><em>test</em></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_wiki_strike():
|
def test_render_wiki_strike():
|
||||||
assert render(dummy_project, "~~test~~") == "<p><del>test</del></p>"
|
assert render(dummy_project, "~~test~~") == "<p><del>test</del></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_absolute_link():
|
def test_render_absolute_link():
|
||||||
assert render(dummy_project, "[test](/test)") == "<p><a href=\"/test\">test</a></p>"
|
assert render(dummy_project, "[test](/test)") == "<p><a href=\"/test\">test</a></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_relative_link():
|
def test_render_relative_link():
|
||||||
assert render(dummy_project, "[test](test)") == "<p><a href=\"test\">test</a></p>"
|
assert render(dummy_project, "[test](test)") == "<p><a href=\"test\">test</a></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_wikilink():
|
def test_render_wikilink():
|
||||||
expected_result = "<p><a class=\"wikilink\" href=\"#/project/test/wiki/test\">test</a></p>"
|
expected_result = "<p><a class=\"wikilink\" href=\"#/project/test/wiki/test\">test</a></p>"
|
||||||
assert render(dummy_project, "[[test]]") == expected_result
|
assert render(dummy_project, "[[test]]") == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_render_wikilink_with_custom_title():
|
def test_render_wikilink_with_custom_title():
|
||||||
expected_result = "<p><a class=\"wikilink\" href=\"#/project/test/wiki/test\">custom</a></p>"
|
expected_result = "<p><a class=\"wikilink\" href=\"#/project/test/wiki/test\">custom</a></p>"
|
||||||
assert render(dummy_project, "[[test|custom]]") == expected_result
|
assert render(dummy_project, "[[test|custom]]") == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_render_reference_links():
|
def test_render_reference_links():
|
||||||
expected_result = "<p>An <a href=\"http://example.com/\" title=\"Title\">example</a> of reference link</p>"
|
expected_result = "<p>An <a href=\"http://example.com/\" title=\"Title\">example</a> of reference link</p>"
|
||||||
source = "An [example][id] of reference link\n [id]: http://example.com/ \"Title\""
|
source = "An [example][id] of reference link\n [id]: http://example.com/ \"Title\""
|
||||||
assert render(dummy_project, source) == expected_result
|
assert render(dummy_project, source) == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_render_url_autolinks():
|
def test_render_url_autolinks():
|
||||||
expected_result = "<p>Test the <a href=\"http://example.com/\">http://example.com/</a> autolink</p>"
|
expected_result = "<p>Test the <a href=\"http://example.com/\">http://example.com/</a> autolink</p>"
|
||||||
source = "Test the http://example.com/ autolink"
|
source = "Test the http://example.com/ autolink"
|
||||||
assert render(dummy_project, source) == expected_result
|
assert render(dummy_project, source) == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_render_url_autolinks_without_http():
|
def test_render_url_autolinks_without_http():
|
||||||
expected_result = "<p>Test the <a href=\"http://www.example.com\">www.example.com</a> autolink</p>"
|
expected_result = "<p>Test the <a href=\"http://www.example.com\">www.example.com</a> autolink</p>"
|
||||||
source = "Test the www.example.com autolink"
|
source = "Test the www.example.com autolink"
|
||||||
assert render(dummy_project, source) == expected_result
|
assert render(dummy_project, source) == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_render_url_automail():
|
def test_render_url_automail():
|
||||||
expected_result = "<p>Test the <a href=\"mailto:example@example.com\">example@example.com</a> automail</p>"
|
expected_result = "<p>Test the <a href=\"mailto:example@example.com\">example@example.com</a> automail</p>"
|
||||||
source = "Test the example@example.com automail"
|
source = "Test the example@example.com automail"
|
||||||
assert render(dummy_project, source) == expected_result
|
assert render(dummy_project, source) == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_render_absolute_image():
|
def test_render_absolute_image():
|
||||||
assert render(dummy_project, "") == "<p><img alt=\"test\" src=\"/test.png\" /></p>"
|
assert render(dummy_project, "") == "<p><img alt=\"test\" src=\"/test.png\" /></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_relative_image():
|
def test_render_relative_image():
|
||||||
assert render(dummy_project, "") == "<p><img alt=\"test\" src=\"test.png\" /></p>"
|
assert render(dummy_project, "") == "<p><img alt=\"test\" src=\"test.png\" /></p>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_triple_quote_code():
|
def test_render_triple_quote_code():
|
||||||
expected_result = "<div class=\"codehilite\"><pre><span class=\"n\">print</span><span class=\"p\">(</span><span class=\"s\">"test"</span><span class=\"p\">)</span>\n</pre></div>"
|
expected_result = "<div class=\"codehilite\"><pre><span class=\"n\">print</span><span class=\"p\">(</span><span class=\"s\">"test"</span><span class=\"p\">)</span>\n</pre></div>"
|
||||||
assert render(dummy_project, "```\nprint(\"test\")\n```") == expected_result
|
assert render(dummy_project, "```\nprint(\"test\")\n```") == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_render_triple_quote_and_lang_code():
|
def test_render_triple_quote_and_lang_code():
|
||||||
expected_result = "<div class=\"codehilite\"><pre><span class=\"k\">print</span><span class=\"p\">(</span><span class=\"s\">"test"</span><span class=\"p\">)</span>\n</pre></div>"
|
expected_result = "<div class=\"codehilite\"><pre><span class=\"k\">print</span><span class=\"p\">(</span><span class=\"s\">"test"</span><span class=\"p\">)</span>\n</pre></div>"
|
||||||
assert render(dummy_project, "```python\nprint(\"test\")\n```") == expected_result
|
assert render(dummy_project, "```python\nprint(\"test\")\n```") == expected_result
|
||||||
|
|
||||||
|
|
||||||
def test_cache_by_sha():
|
def test_cache_by_sha():
|
||||||
@cache_by_sha
|
@cache_by_sha
|
||||||
def test_cache(project, text):
|
def test_cache(project, text):
|
||||||
|
@ -151,18 +170,22 @@ def test_cache_by_sha():
|
||||||
result3 = test_cache(dummy_project, "test")
|
result3 = test_cache(dummy_project, "test")
|
||||||
assert result1 == result3
|
assert result1 == result3
|
||||||
|
|
||||||
|
|
||||||
def test_get_diff_of_htmls_insertions():
|
def test_get_diff_of_htmls_insertions():
|
||||||
result = get_diff_of_htmls("", "<p>test</p>")
|
result = get_diff_of_htmls("", "<p>test</p>")
|
||||||
assert result == "<ins style=\"background:#e6ffe6;\"><p>test</p></ins>"
|
assert result == "<ins style=\"background:#e6ffe6;\"><p>test</p></ins>"
|
||||||
|
|
||||||
|
|
||||||
def test_get_diff_of_htmls_deletions():
|
def test_get_diff_of_htmls_deletions():
|
||||||
result = get_diff_of_htmls("<p>test</p>", "")
|
result = get_diff_of_htmls("<p>test</p>", "")
|
||||||
assert result == "<del style=\"background:#ffe6e6;\"><p>test</p></del>"
|
assert result == "<del style=\"background:#ffe6e6;\"><p>test</p></del>"
|
||||||
|
|
||||||
|
|
||||||
def test_get_diff_of_htmls_modifications():
|
def test_get_diff_of_htmls_modifications():
|
||||||
result = get_diff_of_htmls("<p>test1</p>", "<p>1test</p>")
|
result = get_diff_of_htmls("<p>test1</p>", "<p>1test</p>")
|
||||||
assert result == "<span><p></span><ins style=\"background:#e6ffe6;\">1</ins><span>test</span><del style=\"background:#ffe6e6;\">1</del><span></p></span>"
|
assert result == "<span><p></span><ins style=\"background:#e6ffe6;\">1</ins><span>test</span><del style=\"background:#ffe6e6;\">1</del><span></p></span>"
|
||||||
|
|
||||||
|
|
||||||
def test_render_and_extract_references():
|
def test_render_and_extract_references():
|
||||||
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
with patch("taiga.mdrender.extensions.references.get_instance_by_ref") as mock:
|
||||||
instance = mock.return_value
|
instance = mock.return_value
|
||||||
|
@ -171,6 +194,7 @@ def test_render_and_extract_references():
|
||||||
(_, extracted) = render_and_extract(dummy_project, "**#1**")
|
(_, extracted) = render_and_extract(dummy_project, "**#1**")
|
||||||
assert extracted['references'] == [instance.content_object]
|
assert extracted['references'] == [instance.content_object]
|
||||||
|
|
||||||
|
|
||||||
def test_render_and_extract_mentions():
|
def test_render_and_extract_mentions():
|
||||||
with patch("taiga.mdrender.extensions.mentions.User") as mock:
|
with patch("taiga.mdrender.extensions.mentions.User") as mock:
|
||||||
instance = mock.objects.get.return_value
|
instance = mock.objects.get.return_value
|
||||||
|
|
Loading…
Reference in New Issue