本文整理汇总了Python中test_utils.eq_函数的典型用法代码示例。如果您正苦于以下问题:Python eq_函数的具体用法?Python eq_怎么用?Python eq_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eq_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_frequent_by_date
def test_frequent_by_date(self):
"""Test frequent terms by date."""
ts = Term.objects.frequent(date_end=self.split_date)
eq_(ts[0].term, self.t1.term)
ts = Term.objects.frequent(date_start=self.split_date)
eq_(ts[0].term, self.t2.term)
示例2: test_set_domains_no_args
def test_set_domains_no_args(self):
Site.objects.create(pk=1, domain='hi', name='hi')
Site.objects.create(pk=2, domain='there', name='there')
cron.set_domains(None, None)
# Assert NOOP
eq_(Site.objects.get(id=1).domain, 'hi')
eq_(Site.objects.get(id=2).domain, 'there')
示例3: test_locale_fallback
def test_locale_fallback(self):
"""
Any specific flavor of a language (xx-YY) should return its generic
site (xx) if it exists.
"""
patterns = (
('fR,de;q=0.7', 'fr'),
('zh,fr;q=0.7', 'zh-CN'),
('eN,fr;q=0.7', 'en-US'),
('en,de;q=0.8', 'en-US'),
('en-us,en;q=0.7,de;q=0.8', 'en-US'),
('fr-FR,de-DE;q=0.5', 'fr'),
('zh, en-us;q=0.8, en;q=0.6', 'zh-CN'),
('xx-YY,es-ES;q=0.7,de-DE;q=0.5', 'es'),
('German', 'en-US'), # invalid
# bug 582075
('nb,no;q=0.8,nn;q=0.6,en-us;q=0.4,en;q=0.2', 'nb-NO'),
# bug 629115
('en-US,en;q=0.9,ro;q=0.8,ja;q=0.7,fr;q=0.6', 'en-US'),
)
for pattern in patterns:
r = self.client.get('/', HTTP_ACCEPT_LANGUAGE=pattern[0])
eq_(r.status_code, 301)
did_it_work = r['Location'].rstrip('/').endswith(pattern[1])
self.assertTrue(did_it_work, "%s didn't match %s" % pattern)
示例4: test_trans_interpolation
def test_trans_interpolation():
"""Trans block with interpolation should be escaped."""
s = """
{% trans what="<a>" %}
this is a <b>{{ what }}</b>
{% endtrans %}
""".strip()
eq_(render(s), 'this is a <b><a></b>')
示例5: test_platform_name
def test_platform_name():
"""Show platform name or ID if unknown."""
o = Opinion()
o.platform = 'win7'
eq_(o.platform_name, WINDOWS_7.pretty)
o.platform = 'win25' # Unknown ID
eq_(o.platform_name, 'win25')
示例6: test_product_name
def test_product_name():
"""Show product name or ID if unknown."""
o = Opinion()
o.product = FIREFOX.id
eq_(o.product_name, FIREFOX.pretty)
o.product = 17 # Unknown ID
eq_(o.product_name, 17)
示例7: test_mobilesite_detection
def test_mobilesite_detection(self, mock):
"""Make sure we switch to the mobile site if the domain matches."""
def side_effect(*args, **kwargs):
class FakeSite(object):
id = settings.MOBILE_SITE_ID
return FakeSite()
mock.side_effect = side_effect
# Get the front page. Since we mocked the Site model, the URL we
# pass here does not matter.
self.client.get('/', HTTP_HOST='m.example.com')
eq_(settings.SITE_ID, settings.MOBILE_SITE_ID)
示例8: test_cached_property
def test_cached_property(self):
class A(object):
_foo = 1
@decorators.cached_property
def foo(self):
return self._foo
a = A()
eq_(a.foo, 1)
a._foo = 2
eq_(a.foo, 1)
示例9: test_channel_in_get
def test_channel_in_get(self):
for ch in CHANNELS:
request = Mock()
request.path_info = '/'
request.GET = dict(channel=ch)
p = urlresolvers.Prefixer(request)
eq_(p.get_channel(), ch)
# Invalid channel
request = Mock()
request.path_info = '/'
request.GET = dict(channel='bogus')
p = urlresolvers.Prefixer(request)
eq_(p.get_channel(), settings.DEFAULT_CHANNEL)
示例10: test_forward_mobile
def test_forward_mobile(self, mock):
fake_mobile_domain = 'mymobiledomain.example.com'
def side_effect(*args, **kwargs):
class FakeSite(object):
id = settings.MOBILE_SITE_ID
domain = fake_mobile_domain
return FakeSite()
mock.side_effect = side_effect
r = self.mclient.get(reverse('dashboard') + '?foo=bar')
eq_(r.status_code, 302)
eq_(r['Location'], 'http://' + fake_mobile_domain +
reverse('dashboard') + '?foo=bar')
示例11: test_mobile_device_detection
def test_mobile_device_detection(self, mock):
"""
Requests to front page and submission pages should forward mobile
users to mobile site.
"""
fake_mobile_domain = 'mymobiledomain.example.com'
def side_effect(*args, **kwargs):
class FakeSite(object):
id = settings.MOBILE_SITE_ID
domain = fake_mobile_domain
return FakeSite()
mock.side_effect = side_effect
# URLs that should allow Mobile detection
urls = (
reverse('dashboard', channel='beta'),
reverse('feedback.happy'),
reverse('feedback.sad'),
reverse('feedback.idea'),
reverse('feedback'),
)
# User Agent Patterns: (UA, forward: true/false?)
ua_patterns = (
# Fx
('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; '
'rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13', False),
# MSIE
('Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)',
False),
# Fennec
('Mozilla/5.0 (X11; U; Linux armv6l; fr; rv:1.9.1b1pre) Gecko/'
'20081005220218 Gecko/2008052201 Fennec/0.9pre', True),
# iPod touch
('Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 '
'(KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3',
True),
)
for test_url in urls:
for ua, forward_this in ua_patterns:
r = self.client.get(test_url, HTTP_USER_AGENT=ua)
if forward_this:
eq_(r.status_code, 301)
assert r['Location'].find(fake_mobile_domain) >= 0
else:
assert (r.status_code == 200 or # Page is served, or:
r.status_code / 100 == 3 and # some redirect...
# ... but not to the mobile domain.
r['Location'].find(fake_mobile_domain) == -1)
示例12: test_split_queryset
def test_split_queryset():
"""Split a queryset into pieces."""
# Mock queryset object: List with qs-style count function.
class MockQs(list):
def count(self):
return len(self)
bucket_size = api.cron.BUCKET_SIZE
try:
api.cron.BUCKET_SIZE = 10
my_qs = MockQs(range(100))
splits = list(_split_queryset(my_qs))
eq_(len(splits), 10)
finally:
api.cron.BUCKET_SIZE = bucket_size
示例13: test_forward_mobile
def test_forward_mobile(self, mock):
fake_mobile_domain = 'mymobiledomain.example.com'
populate(1)
id = Opinion.objects.values_list('id', flat=True)[0]
def side_effect(*args, **kwargs):
class FakeSite(object):
id = settings.MOBILE_SITE_ID
domain = fake_mobile_domain
return FakeSite()
mock.side_effect = side_effect
r = self.mclient.get(reverse('opinion.detail', args=[id]) +
'?foo=bar')
eq_(r.status_code, 302)
eq_(r['Location'], 'http://' + fake_mobile_domain +
reverse('opinion.detail', args=[id]) + '?foo=bar')
示例14: test_fake_locale
def test_fake_locale(self):
r = self.factory.get('/zf/beta')
p = urlresolvers.Prefixer(r)
eq_(p.locale, '')
示例15: test_locale_in_get
def test_locale_in_get(self):
request = Mock()
request.path_info = '/'
request.GET = dict(lang='en-US')
p = urlresolvers.Prefixer(request)
eq_(p.get_language(), 'en-US')