~carljm/django-tagging/tagfield-signal-updates

« back to all changes in this revision

Viewing changes to tagging/tests/tests.py

  • Committer: jonathan.buchanan
  • Date: 2008-10-30 02:17:55 UTC
  • Revision ID: vcs-imports@canonical.com-20081030021755-zp1ua9wkvmt46c1d
Got tests back in working order; documentation updates for Django 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
tests = r"""
 
2
r"""
3
3
>>> import os
4
 
>>> from django import newforms as forms
 
4
>>> from django import forms
 
5
>>> from django.db.models import Q
5
6
>>> from tagging.forms import TagField
6
7
>>> from tagging import settings
7
8
>>> from tagging.models import Tag, TaggedItem
8
9
>>> from tagging.tests.models import Article, Link, Perch, Parrot, FormTest
9
10
>>> from tagging.utils import calculate_cloud, get_tag_list, get_tag, parse_tag_input
10
11
>>> from tagging.utils import LINEAR
11
 
>>> from tagging.validators import is_tag_list, is_tag
12
12
 
13
13
#############
14
14
# Utilities #
152
152
    ...
153
153
ValueError: Invalid distribution algorithm specified: cheese.
154
154
 
155
 
# Validators ##################################################################
156
 
 
157
 
>>> is_tag_list('foo qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbn bar', {})
158
 
Traceback (most recent call last):
159
 
    ...
160
 
ValidationError: [u'Each tag may be no more than 50 characters long.']
161
 
 
162
 
>>> is_tag('"test"', {})
163
 
>>> is_tag(',test', {})
164
 
>>> is_tag('f o o', {})
165
 
Traceback (most recent call last):
166
 
    ...
167
 
ValidationError: [u'Multiple tags were given.']
168
 
>>> is_tag_list('foo qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbn bar', {})
169
 
Traceback (most recent call last):
170
 
    ...
171
 
ValidationError: [u'Each tag may be no more than 50 characters long.']
172
 
 
173
155
###########
174
156
# Tagging #
175
157
###########
393
375
>>> TaggedItem.objects.get_related(a1, Link)
394
376
[]
395
377
 
 
378
# Limiting results to a queryset
 
379
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(state='no more'), counts=True)]
 
380
[(u'foo', 1), (u'ter', 1)]
 
381
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(state__startswith='p'), counts=True)]
 
382
[(u'bar', 2), (u'baz', 1), (u'foo', 1), (u'ter', 1)]
 
383
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=4), counts=True)]
 
384
[(u'bar', 2), (u'baz', 1), (u'foo', 1), (u'ter', 1)]
 
385
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__smelly=True), counts=True)]
 
386
[(u'bar', 1), (u'foo', 2), (u'ter', 1)]
 
387
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__smelly=True), min_count=2)]
 
388
[(u'foo', 2)]
 
389
>>> [(tag.name, hasattr(tag, 'counts')) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=4))]
 
390
[(u'bar', False), (u'baz', False), (u'foo', False), (u'ter', False)]
 
391
>>> [(tag.name, hasattr(tag, 'counts')) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=99))]
 
392
[]
 
393
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')), counts=True)]
 
394
[(u'bar', 2), (u'foo', 1), (u'ter', 1)]
 
395
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')), min_count=2)]
 
396
[(u'bar', 2)]
 
397
>>> [(tag.name, hasattr(tag, 'counts')) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')))]
 
398
[(u'bar', False), (u'foo', False), (u'ter', False)]
 
399
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(state='passed on'), counts=True)]
 
400
[(u'bar', 2), (u'foo', 2), (u'ter', 2)]
 
401
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(state__startswith='p'), min_count=2)]
 
402
[(u'ter', 2)]
 
403
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(Q(perch__size__gt=6) | Q(perch__smelly=False)), counts=True)]
 
404
[(u'foo', 1), (u'ter', 1)]
 
405
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(perch__smelly=True).filter(state__startswith='l'), counts=True)]
 
406
[(u'bar', 1), (u'ter', 1)]
 
407
 
396
408
################
397
409
# Model Fields #
398
410
################
444
456
    ...
445
457
ValidationError: [u'Each tag may be no more than 50 characters long.']
446
458
"""
447
 
 
448
 
tests_pre_qsrf = tests + r"""
449
 
# Limiting results to a queryset
450
 
>>> Tag.objects.usage_for_queryset(Parrot.objects.filter())
451
 
Traceback (most recent call last):
452
 
    ...
453
 
AttributeError: 'TagManager.usage_for_queryset' is not compatible with pre-queryset-refactor versions of Django.
454
 
"""
455
 
 
456
 
tests_post_qsrf = tests + r"""
457
 
>>> from django.db.models import Q
458
 
 
459
 
# Limiting results to a queryset
460
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(state='no more'), counts=True)]
461
 
[(u'foo', 1), (u'ter', 1)]
462
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(state__startswith='p'), counts=True)]
463
 
[(u'bar', 2), (u'baz', 1), (u'foo', 1), (u'ter', 1)]
464
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=4), counts=True)]
465
 
[(u'bar', 2), (u'baz', 1), (u'foo', 1), (u'ter', 1)]
466
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__smelly=True), counts=True)]
467
 
[(u'bar', 1), (u'foo', 2), (u'ter', 1)]
468
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__smelly=True), min_count=2)]
469
 
[(u'foo', 2)]
470
 
>>> [(tag.name, hasattr(tag, 'counts')) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=4))]
471
 
[(u'bar', False), (u'baz', False), (u'foo', False), (u'ter', False)]
472
 
>>> [(tag.name, hasattr(tag, 'counts')) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(perch__size__gt=99))]
473
 
[]
474
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')), counts=True)]
475
 
[(u'bar', 2), (u'foo', 1), (u'ter', 1)]
476
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')), min_count=2)]
477
 
[(u'bar', 2)]
478
 
>>> [(tag.name, hasattr(tag, 'counts')) for tag in Tag.objects.usage_for_queryset(Parrot.objects.filter(Q(perch__size__gt=6) | Q(state__startswith='l')))]
479
 
[(u'bar', False), (u'foo', False), (u'ter', False)]
480
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(state='passed on'), counts=True)]
481
 
[(u'bar', 2), (u'foo', 2), (u'ter', 2)]
482
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(state__startswith='p'), min_count=2)]
483
 
[(u'ter', 2)]
484
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(Q(perch__size__gt=6) | Q(perch__smelly=False)), counts=True)]
485
 
[(u'foo', 1), (u'ter', 1)]
486
 
>>> [(tag.name, tag.count) for tag in Tag.objects.usage_for_queryset(Parrot.objects.exclude(perch__smelly=True).filter(state__startswith='l'), counts=True)]
487
 
[(u'bar', 1), (u'ter', 1)]
488
 
"""
489
 
 
490
 
try:
491
 
    from django.db.models.query import parse_lookup
492
 
except ImportError:
493
 
    __test__ = {'post-qsrf': tests_post_qsrf}
494
 
else:
495
 
    __test__ = {'pre-qsrf': tests_pre_qsrf}