Skip to content

Commit

Permalink
Tests for templatetags
Browse files Browse the repository at this point in the history
  • Loading branch information
yetty committed Jul 31, 2013
1 parent 2a191b3 commit 231e378
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion embed_video/templatetags/embed_video_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __iter__(self):
yield node

def __repr__(self):
return '<VideoNode>'
return '<VideoNode "%s">' % (self.url)


@register.filter(is_safe=True)
Expand Down
3 changes: 1 addition & 2 deletions embed_video/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os

from unittest import main

os.environ['DJANGO_SETTINGS_MODULE'] = 'embed_video.tests.django_settings'

from tests_fields import EmbedVideoFieldTestCase, EmbedVideoFormFieldTestCase
from tests_backend import EmbedVideoTestCase
from tests_tags import EmbedVideoNodeTestCase
6 changes: 1 addition & 5 deletions embed_video/tests/tests_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os

from unittest import main, TestCase
from unittest import TestCase

from django.http import HttpRequest
from django.template.base import Template
Expand All @@ -9,8 +7,6 @@
from ..base import detect_backend, YoutubeBackend, VimeoBackend, \
SoundCloundBackend

os.environ['DJANGO_SETTINGS_MODULE'] = 'embed_video.tests.django_settings'


class EmbedVideoTestCase(TestCase):
youtube_urls = (
Expand Down
6 changes: 1 addition & 5 deletions embed_video/tests/tests_fields.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import os

from mock import patch
from unittest import main, TestCase
from unittest import TestCase

from django.forms import ValidationError
from ..fields import EmbedVideoField, EmbedVideoFormField
from ..base import UnknownBackendException, UnknownIdException

os.environ['DJANGO_SETTINGS_MODULE'] = 'embed_video.tests.django_settings'


class EmbedVideoFieldTestCase(TestCase):
def setUp(self):
Expand Down
31 changes: 31 additions & 0 deletions embed_video/tests/tests_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from unittest import TestCase
from mock import Mock

from django.template import TemplateSyntaxError

from ..templatetags.embed_video_tags import VideoNode


class EmbedVideoNodeTestCase(TestCase):
def setUp(self):
self.parser = Mock()
self.token = Mock(methods=['split_contents'])

def test_syntax_error(self):
self.token.split_contents.return_value = []

try:
instance = VideoNode(self.parser, self.token)
except TemplateSyntaxError:
assert True

def test_repr(self):
self.token.split_contents.return_value = (
'video', 'http://youtu.be/v/1234', 'as', 'myvideo'
)
self.parser.compile_filter.return_value = u'some_url'

node = VideoNode(self.parser, self.token)
self.assertEqual(str(node), '<VideoNode "some_url">')


0 comments on commit 231e378

Please sign in to comment.