# (C) Copyright 2006 AixtraWare <http://aixtraware.de>
# Author: Joachim Schmitz <js@aixtraware.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
# $Id: test_tables.py 1561 2007-03-16 03:45:15Z uli $
import unittest

from waeuptest import WAeUP_SRPTest

class TestTables(WAeUP_SRPTest):
    
    # Test that data does not go away on reinstall
    def test_accomodation_install(self):
        # Make sure the table got installed properly
        patool = self.portal.portal_accommodation
        self.failUnlessEqual(patool.meta_type, 'WAeUP Accommodation Tool')
        schemalist = patool.schema()
        schemalist.sort()
        self.failUnlessEqual(schemalist, ['bed', 'bed_type', 'hall', 'student'])
        indexeslist = patool.indexes()
        indexeslist.sort()
        self.failUnlessEqual(indexeslist, ['bed', 'bed_type', 'hall', 'student'])
        
    def test_accomodation_add_change_delete(self):
        patool = self.portal.portal_accommodation
        
        # Add
        uid = patool.addRecord(bed='bed', bed_type='fresh', hall='hall', student='student')
        result = patool.searchResults({'bed':'bed'})
        self.failUnlessEqual(len(result), 1)
        self.failUnlessEqual(result[0].hall, 'hall')
        self.failUnlessEqual(result[0].student, 'student')
        self.failUnlessEqual(result[0].bed, 'bed')
        self.failUnlessEqual(result[0].bed_type, 'fresh')
        
        # Change
        patool.modifyRecord(bed=uid, student='newstudent')
        result = patool.searchResults({'bed':'bed'})
        self.failUnlessEqual(len(result), 1)
        self.failUnlessEqual(result[0].student, 'newstudent')
        
        # Delete
        patool.deleteRecord(uid)
        result = patool.searchResults({'bed':'bed'})
        self.failUnlessEqual(len(result), 0)
    

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(TestTables),
        ))
