Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (74 sloc) 5.061 kb
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
1 from django.contrib.sites.models import Site
2
3 from oembed.tests.tests.base import BaseOEmbedTestCase
99e30660 » coleifer
2010-08-21 Moving the image scaling into a separate function and adding tests
4 from oembed.utils import size_to_nearest, relative_to_full, load_class, cleaned_sites, scale
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
5
6 class OEmbedUtilsTestCase(BaseOEmbedTestCase):
7 def test_size_to_nearest(self):
8 sizes = ((100, 100), (200, 200), (300, 300))
9
10 self.assertEqual((300, 200), size_to_nearest(400, 200, sizes, False))
11 self.assertEqual((100, 100), size_to_nearest(100, 100, sizes, False))
12 self.assertEqual((200, 300), size_to_nearest(250, 500, sizes, False))
13
0acd1173 » coleifer
2010-09-10 Cleaning up djangoembed's size_to_nearest and adding some test cases
14 # if force_fit is False then jump to the largest on None
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
15 self.assertEqual((100, 300), size_to_nearest(150, None, sizes, False))
16 self.assertEqual((300, 100), size_to_nearest(None, 150, sizes, False))
17
0acd1173 » coleifer
2010-09-10 Cleaning up djangoembed's size_to_nearest and adding some test cases
18 # if force_fit is True then scale to the nearest size for the one
19 # that is defined
20 self.assertEqual((100, 100), size_to_nearest(150, None, sizes, True))
21 self.assertEqual((100, 100), size_to_nearest(None, 150, sizes, True))
9a23c93c » coleifer
2011-04-22 Fix to size_to_nearest
22 self.assertEqual((200, 200), size_to_nearest(220, None, sizes, True))
23 self.assertEqual((200, 200), size_to_nearest(None, 220, sizes, True))
24
0acd1173 » coleifer
2010-09-10 Cleaning up djangoembed's size_to_nearest and adding some test cases
25
26 # if both dimensions are None use the largest possible
27 self.assertEqual((300, 300), size_to_nearest(None, None, sizes, False))
28 self.assertEqual((300, 300), size_to_nearest(None, None, sizes, True))
29
30 # if a dimension is too small scale it up to the minimum
31 self.assertEqual((100, 300), size_to_nearest(50, 300, sizes, False))
32 self.assertEqual((100, 100), size_to_nearest(50, 300, sizes, True))
33 self.assertEqual((100, 300), size_to_nearest(50, None, sizes, False))
34 self.assertEqual((100, 100), size_to_nearest(50, None, sizes, True))
35
36 # test when things are too large
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
37 self.assertEqual((200, 200), size_to_nearest(400, 200, sizes, True))
38 self.assertEqual((100, 100), size_to_nearest(100, 100, sizes, True))
39 self.assertEqual((200, 200), size_to_nearest(250, 500, sizes, True))
40
0acd1173 » coleifer
2010-09-10 Cleaning up djangoembed's size_to_nearest and adding some test cases
41 # test Nones around the edges
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
42 self.assertEqual((100, 100), size_to_nearest(100, None, sizes, True))
43 self.assertEqual((100, 100), size_to_nearest(None, 100, sizes, True))
44
0acd1173 » coleifer
2010-09-10 Cleaning up djangoembed's size_to_nearest and adding some test cases
45 def test_size_to_nearest_defaults(self):
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
46 self.assertEqual((800, 600), size_to_nearest(800, 600))
47 self.assertEqual((800, 600), size_to_nearest(850, 650))
0acd1173 » coleifer
2010-09-10 Cleaning up djangoembed's size_to_nearest and adding some test cases
48
49 self.assertEqual((800, 300), size_to_nearest(None, 350))
50 self.assertEqual((400, 800), size_to_nearest(450, None))
51
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
52 self.assertEqual((800, 300), size_to_nearest(None, 350))
53 self.assertEqual((400, 800), size_to_nearest(450, None))
54
55 self.assertEqual((200, 200), size_to_nearest(400, 250, force_fit=True))
56
57 def test_relative_to_full(self):
58 self.assertEqual('http://test.com/a/b/', relative_to_full('/a/b/', 'http://test.com'))
59 self.assertEqual('http://test.com/a/b/', relative_to_full('/a/b/', 'http://test.com/c/d/?cruft'))
60 self.assertEqual('http://test.com/a/b/', relative_to_full('http://test.com/a/b/', 'http://test.com'))
61 self.assertEqual('http://blah.com/a/b/', relative_to_full('http://blah.com/a/b/', 'http://test.com'))
62 self.assertEqual('/a/b/', relative_to_full('/a/b/', ''))
63
64 def test_load_class(self):
9288c238 » coleifer
2010-08-02 Moving text and html parsers into their own modules
65 parser_class = load_class('oembed.parsers.html.HTMLParser')
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
66 self.assertEqual(parser_class.__name__, 'HTMLParser')
9288c238 » coleifer
2010-08-02 Moving text and html parsers into their own modules
67 self.assertEqual(parser_class.__module__, 'oembed.parsers.html')
8fa47b7e » coleifer
2010-07-27 Initial commit of djangoembed, rich media consuming and providing in
68
69 def test_cleaned_sites(self):
70 sites = Site.objects.all()
71 cleaned = cleaned_sites()
72 example = cleaned[1] # example site
73 self.assertEquals(example[1], 'example.com')
74 self.assertEquals(example[2], 'http://example.com')
75 self.assertEquals(example[0], 'https?:\/\/(?:www[^\.]*\.)?example.com')
76
77 www2_site = Site.objects.create(name='Test Site', domain='www2.testsite.com')
78 mobile_site = Site.objects.create(name='Mobile Site', domain='m.testsite.com')
79
80 cleaned = cleaned_sites()
81 self.assertEquals(cleaned[www2_site.pk][1], 'Test Site')
82 self.assertEquals(cleaned[www2_site.pk][2], 'http://www2.testsite.com')
83 self.assertEquals(cleaned[www2_site.pk][0], 'https?:\/\/(?:www[^\.]*\.)?testsite.com')
84
85 self.assertEquals(cleaned[mobile_site.pk][1], 'Mobile Site')
86 self.assertEquals(cleaned[mobile_site.pk][2], 'http://m.testsite.com')
87 self.assertEquals(cleaned[mobile_site.pk][0], 'https?:\/\/(?:www[^\.]*\.)?m.testsite.com')
99e30660 » coleifer
2010-08-21 Moving the image scaling into a separate function and adding tests
88
89 def test_scale(self):
90 self.assertEqual(scale(640, 480, 320), (320, 240))
91 self.assertEqual(scale(640, 480, 500, 240), (320, 240))
92 self.assertEqual(scale(640, 480, 320, 500), (320, 240))
93 self.assertEqual(scale(640, 480, 320, 240), (320, 240))
94
95 self.assertEqual(scale(640, 480, 700), (640, 480))
96 self.assertEqual(scale(640, 480, 700, 500), (640, 480))
Something went wrong with that request. Please try again.