Commits

Anonymous committed b045b83

部屋の登録の際、定員数が1以上かのテスト

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
     u'''model for available room.'''
     
     label      = models.CharField(u'名前', max_length=30, unique=True)
-    place      = models.CharField(u'場所', max_length=140)
-    capacity   = models.PositiveSmallIntegerField(u'定員', blank=True, null=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_cant_crete_same_name_room(self):
         u'''管理者ユーザーが同じ名前の部屋を作成できない'''