-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tobias Lorenz
committed
Apr 14, 2016
1 parent
046c6d9
commit 9241a0a
Showing
24 changed files
with
562 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Tests for the converter utils of ``django_libs``.""" | ||
import os | ||
|
||
from django.test import TestCase | ||
|
||
from ...utils.converter import html_to_plain_text | ||
|
||
|
||
class HTMLToPlainTextTestCase(TestCase): | ||
"""Tests for the ``html_to_plain_text`` function.""" | ||
longMessage = True | ||
|
||
def test_html_to_plain_text(self): | ||
html = ( | ||
""" | ||
<html> | ||
<head></head> | ||
<body> | ||
<ul> | ||
<li>List element</li> | ||
<li>List element</li> | ||
<li>List element</li> | ||
</ul> | ||
</body> | ||
</html> | ||
""" | ||
) | ||
self.assertEqual( | ||
html_to_plain_text(html), | ||
'\n * List element\n * List element\n * List element', | ||
msg='Should return a formatted plain text.') | ||
path = os.path.dirname(os.path.abspath(__file__)) + ( | ||
'/../test_app/templates/html_email.html') | ||
with open(path, 'rb') as file: | ||
self.assertIn('[1]: *|ARCHIVE|*\n', html_to_plain_text(file), msg=( | ||
'Should return a formatted plain text.')) | ||
|
||
def test_replace_links(self): | ||
html = ( | ||
""" | ||
<span>T1<span> <a href="www.example.com">link</a> <span>T2</span> | ||
<br /> | ||
<span>T3</span> | ||
""" | ||
) | ||
expected = ( | ||
"T1 link[1] T2\nT3\n\n[1]: www.example.com\n" | ||
) | ||
result = html_to_plain_text(html) | ||
self.assertEqual(result, expected, msg=( | ||
'Should replace links nicely')) | ||
|
||
def test_replace_br(self): | ||
html = ( | ||
""" | ||
<span>Text1<br>Text2</span> | ||
<br /><br /> | ||
<span>Text3</span> | ||
""" | ||
) | ||
expected = ( | ||
"Text1\nText2\n\n\nText3" | ||
) | ||
result = html_to_plain_text(html) | ||
self.assertEqual(result, expected, msg=( | ||
'Should replace links nicely')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Tests for the decorator utils of ``django_libs``.""" | ||
from django.test import TestCase | ||
|
||
from ...utils.decorators import conditional_decorator | ||
|
||
|
||
def dummy_decorator(func): | ||
def wrapper(): | ||
return 0 | ||
return wrapper | ||
|
||
|
||
@conditional_decorator(dummy_decorator, False) | ||
def test_method(): | ||
"""Used to test the ``conditional_decorator``.""" | ||
return 1 | ||
|
||
|
||
@conditional_decorator(dummy_decorator, True) | ||
def test_method_true(): | ||
"""Used to test the ``conditional_decorator``.""" | ||
return 1 | ||
|
||
|
||
class ConditionalDecoratorTestCase(TestCase): | ||
"""Tests for the ``conditional_decorator``.""" | ||
longMessage = True | ||
|
||
def test_decorator_with_condition_false(self): | ||
result = test_method() | ||
self.assertEqual(result, 1, msg=( | ||
'The method should have been executed normally, without calling' | ||
' the decorator')) | ||
|
||
def test_decorator_with_condition_true(self): | ||
result = test_method_true() | ||
self.assertEqual(result, 0, msg=( | ||
'The method should have been executed with the decorator')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Tests for the log utils of ``django_libs``.""" | ||
from django.test import TestCase | ||
|
||
from mock import Mock | ||
|
||
from ...utils.log import AddCurrentUser, FilterIgnorable404URLs | ||
|
||
|
||
class AddCurrentUserTestCase(TestCase): | ||
"""Tests for the ``AddCurrentUser`` filter.""" | ||
longMessage = True | ||
|
||
def test_filter(self): | ||
user = Mock() | ||
user.email = 'foo@example.com' | ||
record = Mock() | ||
record.request.user = user | ||
record.request.META = {} | ||
self.assertTrue(AddCurrentUser().filter(record)) | ||
|
||
|
||
class FilterIgnorable404URLsTestCase(TestCase): | ||
"""Tests for the ``FilterIgnorable404URLs`` filter.""" | ||
longMessage = True | ||
|
||
def test_filter(self): | ||
record = Mock() | ||
record.status_code = 200 | ||
record.request.META = { | ||
'HTTP_USER_AGENT': 'Mozilla/5.0 (compatible; bingbot/2.0;' | ||
' +http://www.bing.com/bingbot.htm)', | ||
} | ||
self.assertTrue(FilterIgnorable404URLs().filter(record)) | ||
record.status_code = 404 | ||
self.assertFalse(FilterIgnorable404URLs().filter(record)) | ||
record.request.META.update({ | ||
'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows Phone 8.1; ARM;' | ||
' Trident/7.0; Touch; rv:11.0; IEMobile/11.0;' | ||
' NOKIA; Lumia 530) like Gecko'}) | ||
record.request.get_full_path = Mock(return_value='/foo/') | ||
self.assertTrue(FilterIgnorable404URLs().filter(record)) | ||
record.request.get_full_path = Mock(return_value='/static/logo.png') | ||
self.assertFalse(FilterIgnorable404URLs().filter(record)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Tests for the text utils of ``django_libs``.""" | ||
from django.test import TestCase | ||
|
||
from ...utils.text import create_random_string | ||
|
||
|
||
class CreateRandomStringTestCase(TestCase): | ||
"""Tests for the ``create_random_string`` function.""" | ||
longMessage = True | ||
|
||
def test_func(self): | ||
self.assertEqual(len(create_random_string()), 7, msg=( | ||
'Should return a random string with 7 characters.')) | ||
self.assertEqual( | ||
len(create_random_string(length=3, chars='ABC', repetitions=True)), | ||
3, msg=('Should return a random string with 3 characters.')) |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.