From 29f363e8a0bfabac5f57a085919a23610e156c78 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 13:40:35 -0700 Subject: create tests/test_acceptparse.py --- tests/test_acceptparse.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test_acceptparse.py (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py new file mode 100644 index 0000000..7571766 --- /dev/null +++ b/tests/test_acceptparse.py @@ -0,0 +1,47 @@ +from unittest import TestCase + + +class TestAccept(TestCase): + def test_init_accept_content_type(self): + from webob.acceptparse import Accept + name, value = ('Content-Type', 'text/html') + accept = Accept(name, value) + assert accept.header_name == name + assert accept.header_value == value + assert accept._parsed == [('text/html', 1)] + + def test_init_accept_accept_charset(self): + from webob.acceptparse import Accept + name, value = ('Accept-Charset', 'iso-8859-5, unicode-1-1;q=0.8') + accept = Accept(name, value) + assert accept.header_name == name + assert accept.header_value == value + assert accept._parsed == [('iso-8859-5', 1), + ('unicode-1-1', 0.80000000000000004), + ('iso-8859-1', 1)] + + def test_init_accept_accept_charset_with_iso_8859_1(self): + from webob.acceptparse import Accept + name, value = ('Accept-Charset', 'iso-8859-1') + accept = Accept(name, value) + assert accept.header_name == name + assert accept.header_value == value + assert accept._parsed == [('iso-8859-1', 1)] + + def test_init_accept_accept_charset_wildcard(self): + from webob.acceptparse import Accept + name, value = ('Accept-Charset', '*') + accept = Accept(name, value) + assert accept.header_name == name + assert accept.header_value == value + assert accept._parsed == [('*', 1)] + + def test_init_accept_accept_language(self): + from webob.acceptparse import Accept + name, value = ('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7') + accept = Accept(name, value) + assert accept.header_name == name + assert accept.header_value == value + assert accept._parsed == [('da', 1), + ('en-gb', 0.80000000000000004), + ('en', 0.69999999999999996)] -- cgit v1.2.1 From 6145be3719b57021d1dd1ac12f4180e3a8230a61 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 13:54:02 -0700 Subject: test invalid param in accept value --- tests/test_acceptparse.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 7571766..f573f35 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -45,3 +45,11 @@ class TestAccept(TestCase): assert accept._parsed == [('da', 1), ('en-gb', 0.80000000000000004), ('en', 0.69999999999999996)] + + def test_init_accept_invalid_value(self): + from webob.acceptparse import Accept + name, value = ('Accept-Language', 'da, q, en-gb;q=0.8') + accept = Accept(name, value) + # The "q" value should not be there. + assert accept._parsed == [('da', 1), + ('en-gb', 0.80000000000000004)] -- cgit v1.2.1 From f8b6fda903ead97d04489e4f3c85cac86d88c7ba Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 14:00:15 -0700 Subject: test invalid q value --- tests/test_acceptparse.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index f573f35..30d3c0d 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -53,3 +53,11 @@ class TestAccept(TestCase): # The "q" value should not be there. assert accept._parsed == [('da', 1), ('en-gb', 0.80000000000000004)] + + def test_init_accept_invalid_q_value(self): + from webob.acceptparse import Accept + name, value = ('Accept-Language', 'da, en-gb;q=foo') + accept = Accept(name, value) + # I can't get to cover line 40-41 (webob.acceptparse) as the regex + # will prevent from hitting these lines (aconrad) + assert accept._parsed == [('da', 1), ('en-gb', 1)] -- cgit v1.2.1 From c82f28afc8d383e51ecbb6c622bd7a68cda5e045 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 17:07:32 -0700 Subject: test Accept.__str__ and Accept.__repr__ --- tests/test_acceptparse.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 30d3c0d..30e0110 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -61,3 +61,30 @@ class TestAccept(TestCase): # I can't get to cover line 40-41 (webob.acceptparse) as the regex # will prevent from hitting these lines (aconrad) assert accept._parsed == [('da', 1), ('en-gb', 1)] + + def test_accept_repr(self): + from webob.acceptparse import Accept + name, value = ('Content-Type', 'text/html') + accept = Accept(name, value) + assert '%r' % accept == '<%s at 0x%x %s: %s>' % ('Accept', + abs(id(accept)), + name, + str(accept)) + + def test_accept_str(self): + from webob.acceptparse import Accept + name, value = ('Content-Type', 'text/html') + accept = Accept(name, value) + assert str(accept) == value + + def test_accept_str_with_q_not_1(self): + from webob.acceptparse import Accept + name, value = ('Content-Type', 'text/html;q=0.5') + accept = Accept(name, value) + assert str(accept) == value + + def test_accept_str_with_q_not_1_multiple(self): + from webob.acceptparse import Accept + name, value = ('Content-Type', 'text/html;q=0.5, foo/bar') + accept = Accept(name, value) + assert str(accept) == value -- cgit v1.2.1 From 0fc52b60a6002d265623c117ce0dff6f8fb437d3 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 17:50:14 -0700 Subject: test __add__ (missing __radd__, I don't know how to call this) --- tests/test_acceptparse.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 30e0110..117756f 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -88,3 +88,42 @@ class TestAccept(TestCase): name, value = ('Content-Type', 'text/html;q=0.5, foo/bar') accept = Accept(name, value) assert str(accept) == value + + def test_accept_add_other_accept(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + \ + Accept('Content-Type', 'foo/bar') + assert str(accept) == 'text/html, foo/bar' + accept += Accept('Content-Type', 'bar/baz;q=0.5') + assert str(accept) == 'text/html, foo/bar, bar/baz;q=0.5' + + def test_accept_add_other_list_of_tuples(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + accept += [('foo/bar', 1)] + assert str(accept) == 'text/html, foo/bar' + accept += [('bar/baz', 0.5)] + assert str(accept) == 'text/html, foo/bar, bar/baz;q=0.5' + accept += ['she/bangs', 'the/house'] + assert str(accept) == ('text/html, foo/bar, bar/baz;q=0.5, ' + 'she/bangs, the/house') + + def test_accept_add_other_dict(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + accept += {'foo/bar': 1} + assert str(accept) == 'text/html, foo/bar' + accept += {'bar/baz': 0.5} + assert str(accept) == 'text/html, foo/bar, bar/baz;q=0.5' + + def test_accept_add_other_empty_str(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + accept += '' + assert str(accept) == 'text/html' + + def test_accept_with_no_value_add_other_str(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', '') + accept += 'text/html' + assert str(accept) == 'text/html' -- cgit v1.2.1 From 0345e27bd8bc9f864581d9b4c07359c6506d6ff1 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 18:00:21 -0700 Subject: test __contains__ --- tests/test_acceptparse.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 117756f..0889d29 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -127,3 +127,13 @@ class TestAccept(TestCase): accept = Accept('Content-Type', '') accept += 'text/html' assert str(accept) == 'text/html' + + def test_contains(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + assert 'text/html' in accept + + def test_contains_not(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + assert not 'foo/bar' in accept -- cgit v1.2.1 From a8a669f3815fdcbcc8884e625832727b6a566faa Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 18:06:19 -0700 Subject: test quality --- tests/test_acceptparse.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 0889d29..7483c1b 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -137,3 +137,15 @@ class TestAccept(TestCase): from webob.acceptparse import Accept accept = Accept('Content-Type', 'text/html') assert not 'foo/bar' in accept + + def test_quality(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + assert accept.quality('text/html') == 1 + accept = Accept('Content-Type', 'text/html;q=0.5') + assert accept.quality('text/html') == 0.5 + + def test_quality_not_found(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + assert accept.quality('foo/bar') is None -- cgit v1.2.1 From d8327573d8ebce828ab7a48b35f8521f671d1335 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 18:35:57 -0700 Subject: test Accept.first_match --- tests/test_acceptparse.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 7483c1b..057dc71 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -149,3 +149,15 @@ class TestAccept(TestCase): from webob.acceptparse import Accept accept = Accept('Content-Type', 'text/html') assert accept.quality('foo/bar') is None + + def test_first_match(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html, foo/bar') + assert accept.first_match(['text/html', 'foo/bar']) == 'text/html' + assert accept.first_match(['foo/bar', 'text/html']) == 'foo/bar' + assert accept.first_match(['xxx/xxx', 'text/html']) == 'text/html' + assert accept.first_match(['xxx/xxx']) == 'xxx/xxx' + assert accept.first_match([None, 'text/html']) is None + assert accept.first_match(['text/html', None]) == 'text/html' + assert accept.first_match(['foo/bar', None]) == 'foo/bar' + self.assertRaises(ValueError, accept.first_match, []) -- cgit v1.2.1 From 82a1fe461aa815c27dc40a5fe0be7d343e25504e Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 18:54:07 -0700 Subject: test Accept.best_match --- tests/test_acceptparse.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 057dc71..68eecc8 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -161,3 +161,22 @@ class TestAccept(TestCase): assert accept.first_match(['text/html', None]) == 'text/html' assert accept.first_match(['foo/bar', None]) == 'foo/bar' self.assertRaises(ValueError, accept.first_match, []) + + def test_best_match(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html, foo/bar') + assert accept.best_match(['text/html', 'foo/bar']) == 'text/html' + assert accept.best_match(['foo/bar', 'text/html']) == 'foo/bar' + assert accept.best_match([('foo/bar', 0.5), + 'text/html']) == 'text/html' + assert accept.best_match([('foo/bar', 0.5), + ('text/html', 0.4)]) == 'foo/bar' + self.assertRaises(ValueError, accept.best_match, ['text/*']) + + def test_best_match_with_one_lower_q(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html, foo/bar;q=0.5') + assert accept.best_match(['text/html', 'foo/bar']) == 'text/html' + accept = Accept('Content-Type', 'text/html;q=0.5, foo/bar') + assert accept.best_match(['text/html', 'foo/bar']) == 'foo/bar' + -- cgit v1.2.1 From 224c7418c1e8e97da1d0b455ec97f9b0cfea8e63 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:07:55 -0700 Subject: test Accept.best_matches --- tests/test_acceptparse.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 68eecc8..f3d6c07 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -180,3 +180,25 @@ class TestAccept(TestCase): accept = Accept('Content-Type', 'text/html;q=0.5, foo/bar') assert accept.best_match(['text/html', 'foo/bar']) == 'foo/bar' + def test_best_matches(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html, foo/bar') + assert accept.best_matches() == ['text/html', 'foo/bar'] + accept = Accept('Content-Type', 'text/html, foo/bar;q=0.5') + assert accept.best_matches() == ['text/html', 'foo/bar'] + accept = Accept('Content-Type', 'text/html;q=0.5, foo/bar') + assert accept.best_matches() == ['foo/bar', 'text/html'] + + def test_best_matches_with_fallback(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html, foo/bar') + assert accept.best_matches('xxx/yyy') == ['text/html', + 'foo/bar', + 'xxx/yyy'] + accept = Accept('Content-Type', 'text/html;q=0.5, foo/bar') + assert accept.best_matches('xxx/yyy') == ['foo/bar', + 'text/html', + 'xxx/yyy'] + assert accept.best_matches('foo/bar') == ['foo/bar'] + assert accept.best_matches('text/html') == ['foo/bar', 'text/html'] + -- cgit v1.2.1 From 0a51a2620a67f4ad30c18db10bc575b647795900 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:23:43 -0700 Subject: test Accept._match --- tests/test_acceptparse.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index f3d6c07..bccfc84 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -202,3 +202,13 @@ class TestAccept(TestCase): assert accept.best_matches('foo/bar') == ['foo/bar'] assert accept.best_matches('text/html') == ['foo/bar', 'text/html'] + def test_accept_match(self): + from webob.acceptparse import Accept + accept = Accept('Content-Type', 'text/html') + #FIXME: Accept._match should be standalone function _match that is + # attached as Accept._match during Accept.__init__. + assert accept._match('*', 'text/html') + assert accept._match('text/html', 'text/html') + assert accept._match('TEXT/HTML', 'text/html') + assert not accept._match('foo/bar', 'text/html') + -- cgit v1.2.1 From 1757a36e0bb4883b3ffa60b96caee3d846f586a0 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:29:05 -0700 Subject: test Accept._match_lang --- tests/test_acceptparse.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index bccfc84..1fbdcf6 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -212,3 +212,14 @@ class TestAccept(TestCase): assert accept._match('TEXT/HTML', 'text/html') assert not accept._match('foo/bar', 'text/html') + def test_accept_match_lang(self): + from webob.acceptparse import Accept + accept = Accept('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7') + #FIXME: Accept._match_lang should be standalone function _match_lang + # that is attached as Accept._match during Accept.__init__. + assert accept._match('*', 'da') + assert accept._match('da', 'DA') + assert accept._match('en', 'en-gb') + assert accept._match('en-gb', 'en-gb') + assert not accept._match('en-gb', 'fr-fr') + -- cgit v1.2.1 From ff676f84c2262c21219bcd7211a8b9cea70e6eec Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:35:18 -0700 Subject: create TestNilAccept --- tests/test_acceptparse.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 1fbdcf6..4e99b66 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -223,3 +223,12 @@ class TestAccept(TestCase): assert accept._match('en-gb', 'en-gb') assert not accept._match('en-gb', 'fr-fr') + +class TestNilAccept(TestCase): + def NilAccept(self, *args, **kwargs): + from webob.acceptparse import NilAccept + return NilAccept(*args, **kwargs) + + def test_init(self): + nilaccept = self.NilAccept('Connection-Close') + assert nilaccept.header_name == 'Connection-Close' -- cgit v1.2.1 From d38121687fd7d9b9ca1254c5654cd7768a235951 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:40:46 -0700 Subject: use self.Accept() rather than importing Accept everytime --- tests/test_acceptparse.py | 99 ++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 61 deletions(-) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 4e99b66..8a1e330 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -2,18 +2,20 @@ from unittest import TestCase class TestAccept(TestCase): - def test_init_accept_content_type(self): + def Accept(self, *args, **kwargs): from webob.acceptparse import Accept + return Accept(*args, **kwargs) + + def test_init_accept_content_type(self): name, value = ('Content-Type', 'text/html') - accept = Accept(name, value) + accept = self.Accept(name, value) assert accept.header_name == name assert accept.header_value == value assert accept._parsed == [('text/html', 1)] def test_init_accept_accept_charset(self): - from webob.acceptparse import Accept name, value = ('Accept-Charset', 'iso-8859-5, unicode-1-1;q=0.8') - accept = Accept(name, value) + accept = self.Accept(name, value) assert accept.header_name == name assert accept.header_value == value assert accept._parsed == [('iso-8859-5', 1), @@ -21,25 +23,22 @@ class TestAccept(TestCase): ('iso-8859-1', 1)] def test_init_accept_accept_charset_with_iso_8859_1(self): - from webob.acceptparse import Accept name, value = ('Accept-Charset', 'iso-8859-1') - accept = Accept(name, value) + accept = self.Accept(name, value) assert accept.header_name == name assert accept.header_value == value assert accept._parsed == [('iso-8859-1', 1)] def test_init_accept_accept_charset_wildcard(self): - from webob.acceptparse import Accept name, value = ('Accept-Charset', '*') - accept = Accept(name, value) + accept = self.Accept(name, value) assert accept.header_name == name assert accept.header_value == value assert accept._parsed == [('*', 1)] def test_init_accept_accept_language(self): - from webob.acceptparse import Accept name, value = ('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7') - accept = Accept(name, value) + accept = self.Accept(name, value) assert accept.header_name == name assert accept.header_value == value assert accept._parsed == [('da', 1), @@ -47,59 +46,51 @@ class TestAccept(TestCase): ('en', 0.69999999999999996)] def test_init_accept_invalid_value(self): - from webob.acceptparse import Accept name, value = ('Accept-Language', 'da, q, en-gb;q=0.8') - accept = Accept(name, value) + accept = self.Accept(name, value) # The "q" value should not be there. assert accept._parsed == [('da', 1), ('en-gb', 0.80000000000000004)] def test_init_accept_invalid_q_value(self): - from webob.acceptparse import Accept name, value = ('Accept-Language', 'da, en-gb;q=foo') - accept = Accept(name, value) + accept = self.Accept(name, value) # I can't get to cover line 40-41 (webob.acceptparse) as the regex # will prevent from hitting these lines (aconrad) assert accept._parsed == [('da', 1), ('en-gb', 1)] def test_accept_repr(self): - from webob.acceptparse import Accept name, value = ('Content-Type', 'text/html') - accept = Accept(name, value) + accept = self.Accept(name, value) assert '%r' % accept == '<%s at 0x%x %s: %s>' % ('Accept', abs(id(accept)), name, str(accept)) def test_accept_str(self): - from webob.acceptparse import Accept name, value = ('Content-Type', 'text/html') - accept = Accept(name, value) + accept = self.Accept(name, value) assert str(accept) == value def test_accept_str_with_q_not_1(self): - from webob.acceptparse import Accept name, value = ('Content-Type', 'text/html;q=0.5') - accept = Accept(name, value) + accept = self.Accept(name, value) assert str(accept) == value def test_accept_str_with_q_not_1_multiple(self): - from webob.acceptparse import Accept name, value = ('Content-Type', 'text/html;q=0.5, foo/bar') - accept = Accept(name, value) + accept = self.Accept(name, value) assert str(accept) == value def test_accept_add_other_accept(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + \ - Accept('Content-Type', 'foo/bar') + accept = self.Accept('Content-Type', 'text/html') + \ + self.Accept('Content-Type', 'foo/bar') assert str(accept) == 'text/html, foo/bar' - accept += Accept('Content-Type', 'bar/baz;q=0.5') + accept += self.Accept('Content-Type', 'bar/baz;q=0.5') assert str(accept) == 'text/html, foo/bar, bar/baz;q=0.5' def test_accept_add_other_list_of_tuples(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') accept += [('foo/bar', 1)] assert str(accept) == 'text/html, foo/bar' accept += [('bar/baz', 0.5)] @@ -109,50 +100,42 @@ class TestAccept(TestCase): 'she/bangs, the/house') def test_accept_add_other_dict(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') accept += {'foo/bar': 1} assert str(accept) == 'text/html, foo/bar' accept += {'bar/baz': 0.5} assert str(accept) == 'text/html, foo/bar, bar/baz;q=0.5' def test_accept_add_other_empty_str(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') accept += '' assert str(accept) == 'text/html' def test_accept_with_no_value_add_other_str(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', '') + accept = self.Accept('Content-Type', '') accept += 'text/html' assert str(accept) == 'text/html' def test_contains(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') assert 'text/html' in accept def test_contains_not(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') assert not 'foo/bar' in accept def test_quality(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') assert accept.quality('text/html') == 1 - accept = Accept('Content-Type', 'text/html;q=0.5') + accept = self.Accept('Content-Type', 'text/html;q=0.5') assert accept.quality('text/html') == 0.5 def test_quality_not_found(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') assert accept.quality('foo/bar') is None def test_first_match(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html, foo/bar') + accept = self.Accept('Content-Type', 'text/html, foo/bar') assert accept.first_match(['text/html', 'foo/bar']) == 'text/html' assert accept.first_match(['foo/bar', 'text/html']) == 'foo/bar' assert accept.first_match(['xxx/xxx', 'text/html']) == 'text/html' @@ -163,8 +146,7 @@ class TestAccept(TestCase): self.assertRaises(ValueError, accept.first_match, []) def test_best_match(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html, foo/bar') + accept = self.Accept('Content-Type', 'text/html, foo/bar') assert accept.best_match(['text/html', 'foo/bar']) == 'text/html' assert accept.best_match(['foo/bar', 'text/html']) == 'foo/bar' assert accept.best_match([('foo/bar', 0.5), @@ -174,28 +156,25 @@ class TestAccept(TestCase): self.assertRaises(ValueError, accept.best_match, ['text/*']) def test_best_match_with_one_lower_q(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html, foo/bar;q=0.5') + accept = self.Accept('Content-Type', 'text/html, foo/bar;q=0.5') assert accept.best_match(['text/html', 'foo/bar']) == 'text/html' - accept = Accept('Content-Type', 'text/html;q=0.5, foo/bar') + accept = self.Accept('Content-Type', 'text/html;q=0.5, foo/bar') assert accept.best_match(['text/html', 'foo/bar']) == 'foo/bar' def test_best_matches(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html, foo/bar') + accept = self.Accept('Content-Type', 'text/html, foo/bar') assert accept.best_matches() == ['text/html', 'foo/bar'] - accept = Accept('Content-Type', 'text/html, foo/bar;q=0.5') + accept = self.Accept('Content-Type', 'text/html, foo/bar;q=0.5') assert accept.best_matches() == ['text/html', 'foo/bar'] - accept = Accept('Content-Type', 'text/html;q=0.5, foo/bar') + accept = self.Accept('Content-Type', 'text/html;q=0.5, foo/bar') assert accept.best_matches() == ['foo/bar', 'text/html'] def test_best_matches_with_fallback(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html, foo/bar') + accept = self.Accept('Content-Type', 'text/html, foo/bar') assert accept.best_matches('xxx/yyy') == ['text/html', 'foo/bar', 'xxx/yyy'] - accept = Accept('Content-Type', 'text/html;q=0.5, foo/bar') + accept = self.Accept('Content-Type', 'text/html;q=0.5, foo/bar') assert accept.best_matches('xxx/yyy') == ['foo/bar', 'text/html', 'xxx/yyy'] @@ -203,8 +182,7 @@ class TestAccept(TestCase): assert accept.best_matches('text/html') == ['foo/bar', 'text/html'] def test_accept_match(self): - from webob.acceptparse import Accept - accept = Accept('Content-Type', 'text/html') + accept = self.Accept('Content-Type', 'text/html') #FIXME: Accept._match should be standalone function _match that is # attached as Accept._match during Accept.__init__. assert accept._match('*', 'text/html') @@ -213,8 +191,7 @@ class TestAccept(TestCase): assert not accept._match('foo/bar', 'text/html') def test_accept_match_lang(self): - from webob.acceptparse import Accept - accept = Accept('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7') + accept = self.Accept('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7') #FIXME: Accept._match_lang should be standalone function _match_lang # that is attached as Accept._match during Accept.__init__. assert accept._match('*', 'da') -- cgit v1.2.1 From 6945e5a496d68b6739b91e0a24f625bb46108b34 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:48:57 -0700 Subject: test NilAccept.__repr__ --- tests/test_acceptparse.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 8a1e330..bab1179 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -62,10 +62,10 @@ class TestAccept(TestCase): def test_accept_repr(self): name, value = ('Content-Type', 'text/html') accept = self.Accept(name, value) - assert '%r' % accept == '<%s at 0x%x %s: %s>' % ('Accept', - abs(id(accept)), - name, - str(accept)) + assert repr(accept) == '<%s at 0x%x %s: %s>' % ('Accept', + abs(id(accept)), + name, + str(accept)) def test_accept_str(self): name, value = ('Content-Type', 'text/html') @@ -209,3 +209,8 @@ class TestNilAccept(TestCase): def test_init(self): nilaccept = self.NilAccept('Connection-Close') assert nilaccept.header_name == 'Connection-Close' + + def test_repr(self): + nilaccept = self.NilAccept('Connection-Close') + assert repr(nilaccept) == (">") -- cgit v1.2.1 From 3fdcad461530e7ba73ab37e39d3c7266848111d9 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:50:08 -0700 Subject: test NilAccept.__str__ --- tests/test_acceptparse.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index bab1179..3a28587 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -214,3 +214,8 @@ class TestNilAccept(TestCase): nilaccept = self.NilAccept('Connection-Close') assert repr(nilaccept) == (">") + + def test_str(self): + nilaccept = self.NilAccept('Connection-Close') + assert str(nilaccept) == '' + -- cgit v1.2.1 From de59f44d8eb7edce792074abbf07d0977366e5e7 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 19:52:04 -0700 Subject: test NilAccept.__nonzero__ --- tests/test_acceptparse.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 3a28587..e0401a1 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -219,3 +219,7 @@ class TestNilAccept(TestCase): nilaccept = self.NilAccept('Connection-Close') assert str(nilaccept) == '' + def test_nonzero(self): + nilaccept = self.NilAccept('Connection-Close') + assert not nilaccept + -- cgit v1.2.1 From 4546c81f5c604c48c272558f1b3e570a926ffc32 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:02:46 -0700 Subject: test NilAccept.__add__ --- tests/test_acceptparse.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index e0401a1..4d9bfe9 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -206,6 +206,10 @@ class TestNilAccept(TestCase): from webob.acceptparse import NilAccept return NilAccept(*args, **kwargs) + def Accept(self, *args, **kwargs): + from webob.acceptparse import Accept + return Accept(*args, **kwargs) + def test_init(self): nilaccept = self.NilAccept('Connection-Close') assert nilaccept.header_name == 'Connection-Close' @@ -223,3 +227,12 @@ class TestNilAccept(TestCase): nilaccept = self.NilAccept('Connection-Close') assert not nilaccept + def test_add(self): + nilaccept = self.NilAccept('Connection-Close') + accept = self.Accept('Content-Type', 'text/html') + assert nilaccept + accept is accept + new_accept = nilaccept + nilaccept + assert isinstance(new_accept, accept.__class__) + assert new_accept.header_name == 'Connection-Close' + assert new_accept.header_value == '' + -- cgit v1.2.1 From fc4f670c35789f652c38b46bac562a45232fd104 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:04:44 -0700 Subject: test NilAccept.__contains__ --- tests/test_acceptparse.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 4d9bfe9..74f1c8c 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -236,3 +236,10 @@ class TestNilAccept(TestCase): assert new_accept.header_name == 'Connection-Close' assert new_accept.header_value == '' + def test_contains(self): + nilaccept = self.NilAccept('Connection-Close') + # NilAccept.__contains__ always returns True + assert '' in nilaccept + assert 'dummy' in nilaccept + assert nilaccept in nilaccept + -- cgit v1.2.1 From 93585ba99544987435e4b4ecf20a1fc8b6e61b81 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:06:38 -0700 Subject: test NilAccept.quality --- tests/test_acceptparse.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 74f1c8c..882eaca 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -243,3 +243,8 @@ class TestNilAccept(TestCase): assert 'dummy' in nilaccept assert nilaccept in nilaccept + def test_quality(self): + nilaccept = self.NilAccept('Connection-Close') + # NilAccept.quality always returns 0 + assert nilaccept.quality('dummy') == 0 + -- cgit v1.2.1 From 61390ecfa7276195df241ee160c7ed378027466d Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:08:52 -0700 Subject: test NilAccept.first_match --- tests/test_acceptparse.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 882eaca..bab5cf1 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -248,3 +248,9 @@ class TestNilAccept(TestCase): # NilAccept.quality always returns 0 assert nilaccept.quality('dummy') == 0 + def test_first_match(self): + nilaccept = self.NilAccept('Connection-Close') + # NilAccept.first_match always returns element 0 of the list + assert nilaccept.first_match(['dummy', '']) == 'dummy' + assert nilaccept.first_match(['', 'dummy']) == '' + -- cgit v1.2.1 From d0f0a68f4c16241026665cdb2e1fe54351528344 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:15:31 -0700 Subject: test NilAccept.best_match --- tests/test_acceptparse.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index bab5cf1..f465bdf 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -254,3 +254,15 @@ class TestNilAccept(TestCase): assert nilaccept.first_match(['dummy', '']) == 'dummy' assert nilaccept.first_match(['', 'dummy']) == '' + def test_best_match(self): + nilaccept = self.NilAccept('Connection-Close') + assert nilaccept.best_match(['foo', 'bar']) == 'foo' + assert nilaccept.best_match([('foo', 1), ('bar', 0.5)]) == 'foo' + assert nilaccept.best_match([('foo', 0.5), ('bar', 1)]) == 'bar' + assert nilaccept.best_match([('foo', 0.5), 'bar']) == 'bar' + # default_match has no effect on NilAccept class + assert nilaccept.best_match([('foo', 0.5), 'bar'], + default_match=True) == 'bar' + assert nilaccept.best_match([('foo', 0.5), 'bar'], + default_match=False) == 'bar' + -- cgit v1.2.1 From 0be114985c8ce8f046c6841e1e3475edabeae7b8 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:17:48 -0700 Subject: test NilAccept.best_matches --- tests/test_acceptparse.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index f465bdf..52ff845 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -266,3 +266,8 @@ class TestNilAccept(TestCase): assert nilaccept.best_match([('foo', 0.5), 'bar'], default_match=False) == 'bar' + def test_best_matches(self): + nilaccept = self.NilAccept('Connection-Close') + assert nilaccept.best_matches() == [] + assert nilaccept.best_matches('foo') == ['foo'] + -- cgit v1.2.1 From 76a392835f5b0ab0c82050d9cf9919c7d2020a1d Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:21:00 -0700 Subject: create NoAccept and test NoAccept.__contains__ --- tests/test_acceptparse.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 52ff845..9971dc2 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -271,3 +271,15 @@ class TestNilAccept(TestCase): assert nilaccept.best_matches() == [] assert nilaccept.best_matches('foo') == ['foo'] +class TestNoAccept(TestCase): + def NoAccept(self, *args, **kwargs): + from webob.acceptparse import NoAccept + return NoAccept(*args, **kwargs) + + def test_contains(self): + noaccept = self.NoAccept('Connection-Close') + # NoAccept.__contains__ always returns False + assert not '' in noaccept + assert not True in noaccept + assert not False in noaccept + assert not noaccept in noaccept -- cgit v1.2.1 From b394ce9fdaa3c43e940efc96968fd7b303a73847 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:23:09 -0700 Subject: create MIMEAccept test --- tests/test_acceptparse.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 9971dc2..d5be019 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -271,6 +271,7 @@ class TestNilAccept(TestCase): assert nilaccept.best_matches() == [] assert nilaccept.best_matches('foo') == ['foo'] + class TestNoAccept(TestCase): def NoAccept(self, *args, **kwargs): from webob.acceptparse import NoAccept @@ -283,3 +284,9 @@ class TestNoAccept(TestCase): assert not True in noaccept assert not False in noaccept assert not noaccept in noaccept + + +class TestMIMEAccept(TestCase): + def MIMEAccept(self, *args, **kwargs): + from webob.acceptparse import MIMEAccept + return MIMEAccept(*args, **kwargs) -- cgit v1.2.1 From 767019f9bae738d340aabe1b41e5df2bc8afe619 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:31:28 -0700 Subject: test MIMEAccept.__init__ --- tests/test_acceptparse.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index d5be019..5d70036 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -290,3 +290,17 @@ class TestMIMEAccept(TestCase): def MIMEAccept(self, *args, **kwargs): from webob.acceptparse import MIMEAccept return MIMEAccept(*args, **kwargs) + + def test_init(self): + mimeaccept = self.MIMEAccept('Content-Type', 'image/jpg') + assert mimeaccept._parsed == [('image/jpg', 1)] + mimeaccept = self.MIMEAccept('Content-Type', 'image/png, image/jpg;q=0.5') + assert mimeaccept._parsed == [('image/png', 1), ('image/jpg', 0.5)] + mimeaccept = self.MIMEAccept('Content-Type', 'image, image/jpg;q=0.5') + assert mimeaccept._parsed == [('image/jpg', 0.5)] + mimeaccept = self.MIMEAccept('Content-Type', '*/*') + assert mimeaccept._parsed == [('*/*', 1)] + mimeaccept = self.MIMEAccept('Content-Type', '*/png') + assert mimeaccept._parsed == [] + mimeaccept = self.MIMEAccept('Content-Type', 'image/*') + assert mimeaccept._parsed == [('image/*', 1)] -- cgit v1.2.1 From 8525020d38bbafa5e56a03d3cfc9d5b6b0dccb83 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:33:36 -0700 Subject: test MIMEAccept.accept_html --- tests/test_acceptparse.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 5d70036..9bcdf68 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -304,3 +304,10 @@ class TestMIMEAccept(TestCase): assert mimeaccept._parsed == [] mimeaccept = self.MIMEAccept('Content-Type', 'image/*') assert mimeaccept._parsed == [('image/*', 1)] + + def test_accept_html(self): + mimeaccept = self.MIMEAccept('Content-Type', 'image/jpg') + assert not mimeaccept.accept_html() + mimeaccept = self.MIMEAccept('Content-Type', 'image/jpg, text/html') + assert mimeaccept.accept_html() + -- cgit v1.2.1 From fdec1dd7cd8dfe49e8d4c15a666e4d23a268b3ec Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Tue, 15 Mar 2011 20:40:23 -0700 Subject: test MIMEAccept._match --- tests/test_acceptparse.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 9bcdf68..9cc299d 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -311,3 +311,11 @@ class TestMIMEAccept(TestCase): mimeaccept = self.MIMEAccept('Content-Type', 'image/jpg, text/html') assert mimeaccept.accept_html() + def test_match(self): + mimeaccept = self.MIMEAccept('Content-Type', 'image/jpg') + assert mimeaccept._match('image/jpg', 'image/jpg') + assert mimeaccept._match('image/*', 'image/jpg') + assert mimeaccept._match('*/*', 'image/jpg') + assert not mimeaccept._match('text/html', 'image/jpg') + self.assertRaises(AssertionError, mimeaccept._match, 'image/jpg', '*/*') + -- cgit v1.2.1 From 3c00425bfbaaa9c26fee1e99a863c911bb843bcc Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Wed, 16 Mar 2011 16:14:44 -0700 Subject: test NilAccept.__radd__ (can't figure out how to fully test, comment included in test) --- tests/test_acceptparse.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 9cc299d..76243a2 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -236,6 +236,14 @@ class TestNilAccept(TestCase): assert new_accept.header_name == 'Connection-Close' assert new_accept.header_value == '' + def test_radd(self): + nilaccept = self.NilAccept('Connection-Close') + accept = self.Accept('Content-Type', 'text/html') + assert isinstance('foo' + nilaccept, accept.__class__) + assert ('foo' + nilaccept).header_value == 'foo' + # How to test ``if isinstance(item, self.MasterClass): return item`` + # under NilAccept.__radd__ ?? + def test_contains(self): nilaccept = self.NilAccept('Connection-Close') # NilAccept.__contains__ always returns True -- cgit v1.2.1 From 40b1a2a0ef2f8d60115eb43020abea452ea66090 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Wed, 16 Mar 2011 16:32:35 -0700 Subject: more tests for NilAccept.__add__ --- tests/test_acceptparse.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 76243a2..58b3325 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -235,6 +235,10 @@ class TestNilAccept(TestCase): assert isinstance(new_accept, accept.__class__) assert new_accept.header_name == 'Connection-Close' assert new_accept.header_value == '' + new_accept = nilaccept + 'foo' + assert isinstance(new_accept, accept.__class__) + assert new_accept.header_name == 'Connection-Close' + assert new_accept.header_value == 'foo' def test_radd(self): nilaccept = self.NilAccept('Connection-Close') -- cgit v1.2.1 From 03f28c8cee3cebbc72f742d503b501bc48409d04 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Wed, 16 Mar 2011 16:42:15 -0700 Subject: placeholder for test of accept_property --- tests/test_acceptparse.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 58b3325..72c800d 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -331,3 +331,7 @@ class TestMIMEAccept(TestCase): assert not mimeaccept._match('text/html', 'image/jpg') self.assertRaises(AssertionError, mimeaccept._match, 'image/jpg', '*/*') + +class TestAcceptProperty(TestCase): + def test_accept_property(self): + from webob.acceptparse import accept_property -- cgit v1.2.1 From 91746bc5fe5435758404e3662544cd0f0e38dad9 Mon Sep 17 00:00:00 2001 From: Chris Shenton Date: Wed, 16 Mar 2011 22:57:02 -0400 Subject: 100% coverage (but test for __radd__ smells funny) --- tests/test_acceptparse.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 72c800d..8d050f0 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -1,5 +1,9 @@ from unittest import TestCase +class Test_parse_accept_badq(TestCase): + from webob.acceptparse import parse_accept + assert parse_accept("value1; q=0.1.2") == [('value1', 1)] + class TestAccept(TestCase): def Accept(self, *args, **kwargs): @@ -248,6 +252,12 @@ class TestNilAccept(TestCase): # How to test ``if isinstance(item, self.MasterClass): return item`` # under NilAccept.__radd__ ?? + def test_radd_masterclass(self): + # Is this "reaching into" __radd__ legit? + nilaccept = self.NilAccept('Connection-Close') + accept = self.Accept('Content-Type', 'text/html') + assert nilaccept.__radd__(accept) is accept + def test_contains(self): nilaccept = self.NilAccept('Connection-Close') # NilAccept.__contains__ always returns True @@ -334,4 +344,14 @@ class TestMIMEAccept(TestCase): class TestAcceptProperty(TestCase): def test_accept_property(self): + from webob.acceptparse import NilAccept from webob.acceptparse import accept_property + from webob import Request + desc = accept_property('Accept-Charset', '14.2') + req = Request.blank('/', environ={'envkey': 'envval'}) + desc.fset(req, 'val') + assert desc.fget(req).header_value == 'val' + desc.fdel(req) + self.assertEqual(type(desc.fget(req)), NilAccept) + + -- cgit v1.2.1 From b669d93025d768c40e2bb3563f0908439b72d470 Mon Sep 17 00:00:00 2001 From: Reed O'Brien Date: Thu, 17 Mar 2011 00:07:15 -0400 Subject: 100% for acceptparse --- tests/test_acceptparse.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'tests/test_acceptparse.py') diff --git a/tests/test_acceptparse.py b/tests/test_acceptparse.py index 8d050f0..07ae07a 100644 --- a/tests/test_acceptparse.py +++ b/tests/test_acceptparse.py @@ -343,7 +343,39 @@ class TestMIMEAccept(TestCase): class TestAcceptProperty(TestCase): - def test_accept_property(self): + def test_accept_property_fget(self): + from webob.acceptparse import accept_property + from webob import Request + desc = accept_property('Accept-Charset', '14.2') + req = Request.blank('/', environ={'envkey': 'envval'}) + desc.fset(req, 'val') + self.assertEqual(desc.fget(req).header_value, 'val') + + def test_accept_property_fget_nil(self): + from webob.acceptparse import NilAccept + from webob.acceptparse import accept_property + from webob import Request + desc = accept_property('Accept-Charset', '14.2') + req = Request.blank('/') + self.assertEqual(type(desc.fget(req)), NilAccept) + + def test_accept_property_fset(self): + from webob.acceptparse import accept_property + from webob import Request + desc = accept_property('Accept-Charset', '14.2') + req = Request.blank('/', environ={'envkey': 'envval'}) + desc.fset(req, 'baz') + self.assertEqual(desc.fget(req).header_value, 'baz') + + def test_accept_property_fset_acceptclass(self): + from webob.acceptparse import accept_property + from webob import Request + desc = accept_property('Accept-Charset', '14.2') + req = Request.blank('/', environ={'envkey': 'envval'}) + desc.fset(req, ['utf-8', 'latin-11']) + self.assertEqual(desc.fget(req).header_value, 'utf-8, latin-11, iso-8859-1') + + def test_accept_property_fdel(self): from webob.acceptparse import NilAccept from webob.acceptparse import accept_property from webob import Request @@ -353,5 +385,3 @@ class TestAcceptProperty(TestCase): assert desc.fget(req).header_value == 'val' desc.fdel(req) self.assertEqual(type(desc.fget(req)), NilAccept) - - -- cgit v1.2.1