Permalink
Browse files

Merge branch 't13_customer'

  • Loading branch information...
2 parents 68b2315 + a72df5c commit 4f2d0019e8ca1c9641ba794046a3644466e6aecb @andreysobol committed Mar 11, 2012
View
@@ -1,2 +1,3 @@
Django==1.3
+pil
wsgiref==0.1.2
View
@@ -0,0 +1,2 @@
+test:
+ python manage.py test mainapp
@@ -1,4 +1,5 @@
from django.conf import settings
+
def settings_context_processor(request):
- return {'settings':settings}
+ return {'settings': settings}
@@ -5,15 +5,18 @@
from models import Bio
from utils import Render
+
class ImgWidget(ClearableFileInput):
def render(self, name, value, attrs=None):
substitutions = {}
template = u'%(input)s'
- substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs)
+ substitutions['input'] = super(ClearableFileInput, self)\
+ .render(name, value, attrs)
if value and hasattr(value, "url"):
template = u'%(initial)s<br />%(input)s'
- substitutions['initial'] = (u'<img src="%s"/>' % (escape(value.url)))
+ substitutions['initial'] = (u'<img src="%s"/>' %\
+ (escape(value.url)))
return mark_safe(template % substitutions)
@@ -25,7 +28,10 @@ class Meta:
}
def render(self):
- form_field = dict([(field.name, {'label':field.label,'value':field.as_widget(),'errors':field.errors}) for field in self])
+ form_field = dict([(field.name,
+ {'label':field.label,
+ 'value':field.as_widget(),
+ 'errors':field.errors}) for field in self])
get = lambda item: form_field[item]
@@ -2,9 +2,11 @@
from django.db import models
import sys
+
class Command(NoArgsCommand):
def handle(self, *args, **options):
- p = unicode([(cls.__name__,cls.objects.count()) for cls in models.get_models()])
+ p = unicode([(cls.__name__, cls.objects.count())
+ for cls in models.get_models()])
print p
print >> sys.stderr, 'error: ' + p,
@@ -2,8 +2,9 @@
from models import Request
+
class RequestMiddleware(object):
-
+
def process_request(self, request):
r = Request()
r.date = datetime.now()
@@ -1,9 +1,8 @@
from django.db import models
from django.db.models.signals import post_save, post_delete
-from utils import Render
-class Bio(models.Model, Render):
+class Bio(models.Model):
name = models.CharField(max_length=250, verbose_name='Name')
surname = models.CharField(max_length=250, verbose_name='Last name')
birth = models.DateField(verbose_name='Date of birth')
@@ -14,43 +13,42 @@ class Bio(models.Model, Render):
bio = models.TextField(verbose_name='Bio')
img = models.ImageField(verbose_name='Photo', upload_to='img/')
- def render(self):
- field_types = dict([(field.name, field.verbose_name) for field in self._meta.fields])
-
- get = lambda item: {'value':unicode(getattr(self,item)) if item!='img' else '<img src="%s" />' % getattr(self,item).url,'label':field_types[item]}
-
- return self.get_struct(get, False)
class Request(models.Model):
date = models.DateTimeField()
url = models.CharField(max_length=250)
ip = models.CharField(max_length=250)
+
class RequestPriority(models.Model):
url = models.CharField(max_length=250)
priority = models.IntegerField()
def __unicode__(self):
return 'url="' + self.url + '" prioryty=' + str(self.priority)
+
class Log(models.Model):
date = models.DateTimeField(auto_now_add=True)
model = models.CharField(max_length=250)
signal = models.CharField(max_length=250)
+
def save(sender, **kwargs):
if sender != Log:
if kwargs['created']:
- signal='create'
+ signal = 'create'
else:
- signal='update'
+ signal = 'update'
- log = Log(model = sender.__name__, signal = signal)
+ log = Log(model=sender.__name__, signal=signal)
log.save()
+
def delete(sender, **kwargs):
- log = Log(model = sender.__name__, signal = 'delete')
+ log = Log(model=sender.__name__, signal='delete')
log.save()
+
post_save.connect(save)
post_delete.connect(delete)
@@ -1,16 +1,20 @@
from django.template import Library, Node, Variable
from django.core.urlresolvers import reverse
+
register = Library()
+
class EditAdmin(Node):
def __init__(self, edit):
self.edit = Variable(edit)
def render(self, context):
e = self.edit.resolve(context)
- return u'<a href="%s">Edit</a>' % reverse('admin:%s_%s_change' % (e._meta.app_label, e._meta.module_name), args=(e.id,))
+ return u'<a href="%s">Edit</a>' %\
+ reverse('admin:%s_%s_change' %\
+ (e._meta.app_label, e._meta.module_name), args=(e.id,))
def ed(parser, token):
@@ -17,22 +17,24 @@
class IndexViewTest(TestCase):
def test(self):
- fixtures = ['initial_data.json']
-
page = self.client.get('')
self.assertEqual(page.status_code, 200)
-
- for key,value in model_to_dict(Bio.objects.get(pk = 1)).items():
- if key!='id':
+
+ for key, value in model_to_dict(Bio.objects.get(pk=1)).items():
+ if key != 'id':
self.assertTrue(page.content.find(unicode(value)) != -1)
class RequestTest(TestCase):
def test(self):
page = self.client.get('')
- self.assertTrue(bool(Request.objects.filter(date__gte = (datetime.now() - timedelta(minutes=1)))))
+
+ self.assertEqual(page.status_code, 200)
+
+ self.assertTrue(bool(Request.objects.filter(
+ date__gte=(datetime.now() - timedelta(minutes=1)))))
class RequestViewTest(TestCase):
@@ -42,43 +44,56 @@ def test(self):
self.assertEqual(page.status_code, 200)
self.assertTrue(bool(page.context['custom_request']))
+
class SettingsContextTest(TestCase):
-
+
def test(self):
page = self.client.get('')
self.assertEqual(page.status_code, 200)
self.assertTrue(page.context['settings'])
+ self.assertEqual(page.context['settings'].STATIC_URL, '/static/')
class Edit(TestCase):
-
- def test(self):
- fixtures = ['initial_data.json']
- page = self.client.post('/accounts/login/', {'username': 'admin', 'password': 'admin'})
+ def test(self):
+ page = self.client.post('/accounts/login/',
+ {'username': 'admin', 'password': 'admin'})
self.assertEqual(page.status_code, 302)
-
- page = self.client.post('/edit/', {"bio": "Noooooooooooooo", "surname": "Sobol", "name": "Andrey", "other": "pigeon post - white pigeon only", "birth": "1990-09-18", "skype": "andreysobol", "jabber": "pisecs@gmail.com", "email": "asobol@mail.ua"})
+
+ s = {"bio": "Noooooooooooooo",
+ "surname": "Sobol",
+ "name": "Andrey",
+ "other": "pigeon post - white pigeon only",
+ "birth": "1990-09-18",
+ "skype": "andreysobol",
+ "jabber": "pisecs@gmail.com",
+ "email": "asobol@mail.ua"}
+ page = self.client.post('/edit/', s)
self.assertEqual(page.status_code, 200)
self.assertTrue(page.content == 'Okay')
- self.assertTrue(Bio.objects.get(pk = 1).bio == "Noooooooooooooo")
-
- page = self.client.post('/edit/', {"bio": "Noooooooooooooo", "surname": "Sobol", "name": "Andrey", "other": "pigeon post - white pigeon only"})
+ for t in s:
+ self.assertEqual(unicode(getattr(Bio.objects.get(pk=1), t)), s[t])
+
+ page = self.client.post('/edit/',
+ {"bio": "Noooooooooooooo",
+ "surname": "Sobol",
+ "name": "Andrey",
+ "other": "pigeon post - white pigeon only"})
self.assertEqual(page.status_code, 200)
self.assertTrue(page.content.find("error") != -1)
class AjaxEdit(TestCase):
def test(self):
- fixtures = ['initial_data.json']
-
- page = self.client.post('/accounts/login/', {'username': 'admin', 'password': 'admin'})
+ page = self.client.post('/accounts/login/',
+ {'username': 'admin', 'password': 'admin'})
self.assertEqual(page.status_code, 302)
page = self.client.post('/edit/')
self.assertTrue(page.content.find('<body>') == -1)
-
+
page = self.client.get('/edit/')
self.assertTrue(page.content.find('<body>') != -1)
self.assertTrue(page.content.find('<script') != -1)
@@ -90,70 +105,98 @@ def test(self):
class EditReverse(TestCase):
def test(self):
- fixtures = ['initial_data.json']
-
page = self.client.get('/')
- self.assertTrue(page.content.find('>Name:') < page.content.find('Last name:'))
- self.assertTrue(page.content.find('Bio:') > page.content.find('Other'))
+ self.assertTrue(page.content.find('>Name:')
+ < page.content.find('Last name:'))
+ self.assertTrue(page.content.find('Bio:')
+ > page.content.find('Other'))
- page = self.client.post('/accounts/login/', {'username': 'admin', 'password': 'admin'})
+ page = self.client.post('/accounts/login/',
+ {'username': 'admin', 'password': 'admin'})
page = self.client.get('/edit/')
- self.assertTrue(page.content.find('>Name:') > page.content.find('Last name:'))
- self.assertTrue(page.content.find('Bio:') < page.content.find('Other'))
+ self.assertTrue(page.content.find('>Name:')
+ > page.content.find('Last name:'))
+ self.assertTrue(page.content.find('Bio:')
+ < page.content.find('Other'))
class Tag(TestCase):
def test(self):
- fixtures = ['initial_data.json']
+ page = self.client.post('/accounts/login/',
+ {'username': 'admin', 'password': 'admin'})
+
+ page = self.client.get('/')
+ self.assertTrue(page.content.find(
+ '<a href="/admin/auth/user/1/"') != -1)
- page = self.client.post('/accounts/login/', {'username': 'admin', 'password': 'admin'})
+class NameUrlTest(TestCase):
+
+ def test(self):
page = self.client.get('/')
- self.assertTrue(page.content.find('<a href="/admin/auth/user/1/"') != -1 )
+ self.assertEqual(page.status_code, 200)
+ self.assertTrue(page.content.find('a href="/http/"') != -1)
+ self.assertTrue(page.content.find('a href="/edit/"') != -1)
class Command(TestCase):
def test(self):
- p = Popen("python manage.py printmodels", stdout=PIPE, stderr=PIPE, shell=True).stdout.read()
- self.assertTrue(p.find('Bio')!=-1)
+ p = Popen("python manage.py printmodels",
+ stdout=PIPE, stderr=PIPE, shell=True).stdout.read()
+ self.assertTrue(p.find('Bio') != -1)
Popen("bash save.bash", stdout=PIPE, stderr=PIPE, shell=True)
l = os.listdir(".")
for d in l:
- if d.find('.dat')!=-1:
- f = open(d,'r')
+ if d.find('.dat') != -1:
+ f = open(d, 'r')
self.assertTrue((f.read()).find('error') != -1)
f.close()
Popen("rm " + d, stdout=PIPE, stderr=PIPE, shell=True)
class Signal(TestCase):
-
+
def test(self):
- b = Bio(bio="Noooooooooooooo", surname="Sobol", name="Andrey", other="pigeon post - white pigeon only", birth="1990-09-18", skype="andreysobol", jabber="pisecs@gmail.com", email="asobol@mail.ua", img="img/1.jpg")
+ b = Bio(bio="Noooooooooooooo", surname="Sobol",
+ name="Andrey", other="pigeon post - white pigeon only",
+ birth="1990-09-18", skype="andreysobol",
+ jabber="pisecs@gmail.com", email="asobol@mail.ua",
+ img="img/1.jpg")
b.save()
- self.assertEqual(Log.objects.order_by('-id')[0].model,'Bio')
- self.assertEqual(Log.objects.order_by('-id')[0].signal,'create')
-
- b.bio="sfsf"
+ self.assertEqual(Log.objects.order_by('-id')[0].model, 'Bio')
+ self.assertEqual(Log.objects.order_by('-id')[0].signal, 'create')
+
+ b.bio = "sfsf"
b.save()
- self.assertEqual(Log.objects.order_by('-id')[0].model,'Bio')
- self.assertEqual(Log.objects.order_by('-id')[0].signal,'update')
+ self.assertEqual(Log.objects.order_by('-id')[0].model, 'Bio')
+ self.assertEqual(Log.objects.order_by('-id')[0].signal, 'update')
b.delete()
- self.assertEqual(Log.objects.order_by('-id')[0].model,'Bio')
- self.assertEqual(Log.objects.order_by('-id')[0].signal,'delete')
+ self.assertEqual(Log.objects.order_by('-id')[0].model, 'Bio')
+ self.assertEqual(Log.objects.order_by('-id')[0].signal, 'delete')
+
class RequestPriority(TestCase):
def test(self):
- fixtures = ['initial_data.json']
page = self.client.get('/http/')
self.assertEqual(page.status_code, 200)
- b = False;
+ b = False
for r in page.context['custom_request']:
- if r['url']=='/http/' and r['priority']==2:
+ if r['url'] == '/http/' and r['priority'] == 2:
b = True
self.assertTrue(b)
+
+
+class ManyRequestTest(TestCase):
+
+ def test(self):
+ for t in range(11):
+ page = self.client.get('/')
+ self.assertEqual(page.status_code, 200)
+
+ page = self.client.get('/http/')
+ self.assertTrue(len(page.context['custom_request']) == 10)
Oops, something went wrong.

0 comments on commit 4f2d001

Please sign in to comment.