Commits

Anonymous committed 55219ce Merge

まーじした

Comments (0)

Files changed (2)

src/RoomReservation/rooms/models.py

 # -*- coding: utf-8 -*-
 from django.db import models
+from django.core.exceptions import ValidationError
 
 class RoomManager(models.Manager):
     pass
 class Room(models.Model):
     u'''model for available room.'''
     
-    label      = models.CharField(u'名前', max_length=30)
-    place      = models.CharField(u'場所', max_length=140)
-    capacity   = models.PositiveSmallIntegerField(u'定員', blank=True, null=True)
+    label      = models.CharField(u'名前', max_length=30, unique=True)
+    place      = models.CharField(u'場所', max_length=140, blank=True, null=True)
+    capacity   = models.IntegerField(u'定員')
     
     created_at = models.DateTimeField(u'作成日時', auto_now_add=True)
     updated_at = models.DateTimeField(u'更新日時', auto_now=True)
     def __unicode__(self):
         return self.label
     
+    def clean(self):
+        u"""各種Validation及び著者の自動設定"""
+        # 定員数は1以上
+        if self.capacity <= 0:
+                raise ValidationError(u"定員数は1以上です")
+        super(Room, self).clean()
+    
     @models.permalink
     def get_absolute_url(self):
         return ('rooms-room-detail', (), {

src/RoomReservation/rooms/tests.py

         list = r.context_data['object_list']
         eq_(list.count(), 1, u"部屋が作成できた")
         self.room = list[0]
-        
+    
+    def test_require_field_test(self):
+        u'''登録時の必須項目のテスト'''
+        c = Client()
+        response = c.post(reverse('auth_login'), {'username': 'miku', 'password': 'mikkumiku'}) 
+        eq_(response.status_code, 302, u'ログインできた')
+        c.post(reverse('rooms-room-create'), {'capacity' : 8, 'place' : 'bbb'})
+        r = c.get(reverse('rooms-room-list'))
+        list = r.context_data['object_list']
+        eq_(list.count(),0 , u"部屋が作成できない")
+        c.post(reverse('rooms-room-create'), {'label':u'AAA','place' : 'bbb'})
+        r = c.get(reverse('rooms-room-list'))
+        list = r.context_data['object_list']
+        eq_(list.count(),0 , u"部屋が作成できない")
+
+    def test_min_capacity_test(self):
+        u'''登録時の定員の最小値のテスト'''
+        c = Client()
+        response = c.post(reverse('auth_login'), {'username': 'miku', 'password': 'mikkumiku'}) 
+        eq_(response.status_code, 302, u'ログインできた')
+        c.post(reverse('rooms-room-create'), {'label':u'AAA','capacity' : 0, 'place' : 'bbb'})
+        r = c.get(reverse('rooms-room-list'))
+        list = r.context_data['object_list']
+        eq_(list.count(),0 , u"部屋が作成できない")
+        c.post(reverse('rooms-room-create'), {'label':u'AAA','capacity' : -1,'place' : 'bbb'})
+        r = c.get(reverse('rooms-room-list'))
+        list = r.context_data['object_list']
+        eq_(list.count(),0 , u"部屋が作成できない")
+    
+    def test_max_label_test(self):
+        u'''登録時の会議室名の長さのテスト'''
+        c = Client()
+        response = c.post(reverse('auth_login'), {'username': 'miku', 'password': 'mikkumiku'}) 
+        eq_(response.status_code, 302, u'ログインできた')
+        c.post(reverse('rooms-room-create'), {'label':u'0123456789012345678901234567890','capacity' : 0, 'place' : 'bbb'})
+        r = c.get(reverse('rooms-room-list'))
+        list = r.context_data['object_list']
+        eq_(list.count(),0 , u"部屋が作成できない")        
+
+    def test_max_place_test(self):
+        u'''登録時の場所の文字制限140文字内のテスト'''
+        c = Client()
+        response = c.post(reverse('auth_login'), {'username': 'miku', 'password': 'mikkumiku'}) 
+        eq_(response.status_code, 302, u'ログインできた')
+        c.post(reverse('rooms-room-create'), {'label':u'AAA','capacity' : 0, 'place' : 'b'*141})
+        r = c.get(reverse('rooms-room-list'))
+        list = r.context_data['object_list']
+        eq_(list.count(),0 , u"部屋が作成できない")  
+                
     def test_cant_crete_same_name_room(self):
         u'''管理者ユーザーが同じ名前の部屋を作成できない'''
         self.room = Room.objects.create(label=u'部屋1', place='どこか', capacity='100')