Ticket #7210: update_tests.py

File update_tests.py, 958 bytes (added by Alex Gaynor, 17 years ago)

Some quick tests, not a ton, but tests basic funcionality, should be a good starting point if anyone wants to help out.

Line 
1from django.db import models
2
3class Employee(models.Model):
4 name = models.CharField(max_length=100)
5 salary = models.IntegerField()
6 birth_date = models.DateField()
7
8__test__ = {'API_TEST': '''
9>>> from datetime import date
10>>> from django.db.models import F
11>>> a = Employee(name='Alex', salary=130, birth_date=date(1980, 1, 8))
12>>> a.save()
13>>> b = Employee(name='Brian', salary=150, birth_date=date(1970, 3, 4))
14>>> b.save()
15>>> c = Employee(name='Michael', salary=100, birth_date=date(1960, 5, 6))
16>>> c.save()
17>>> Employee.objects.all().update(salary=F('salary')+20)
18>>> print Employee.objects.get(pk=a.pk).salary
19150
20>>> print Employee.objects.get(pk=b.pk).salary
21170
22>>> Employee.objects.all(salary=F('salary')*1.1)
23>>> print Employee.objects.get(pk=a.pk).salary
24165
25>>> print Employee.objects.get(pk=b.pk).salary
26187
27>>> Employee.objects.filter(salary__gt=170).update(name=F('salary'))
28>>> print Employee.objects.get(pk=b.pk).name
29187
30'''
31}
Back to Top