## $Id: test_customer.py 14188 2016-09-26 05:13:42Z henrik $
##
## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## 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
##
"""
Tests for uniben customers.
"""
import tempfile
import shutil
from zope.interface.verify import verifyClass, verifyObject
from zope.component import createObject
from zope.component.hooks import setSite
from zope.interface import verify
from waeup.ikoba.app import Company
from waeup.ikoba.customers.interfaces import (
    ICustomersContainer, ICustomerNavigation)
from waeup.ikoba.customers.container import CustomersContainer

from ikobacustom.uniben.testing import (FunctionalLayer, FunctionalTestCase)
from ikobacustom.uniben.customers.customer import UnibenCustomer
from ikobacustom.uniben.customers.interfaces import IUnibenCustomer

class UnibenCustomerTestCase(FunctionalTestCase):

    layer = FunctionalLayer

    def setUp(self):
        super(UnibenCustomerTestCase, self).setUp()

        # Prepopulate ZODB
        app = Company()
        self.dc_root = tempfile.mkdtemp()
        app['datacenter'].setStoragePath(self.dc_root)

        # Prepopulate the ZODB...
        self.getRootFolder()['app'] = app
        self.app = self.getRootFolder()['app']
        setSite(self.app)

    def test_interfaces(self):
        verify.verifyClass(IUnibenCustomer, UnibenCustomer)
        verify.verifyClass(ICustomerNavigation, UnibenCustomer)
        verify.verifyObject(IUnibenCustomer, UnibenCustomer())
        verify.verifyObject(ICustomerNavigation, UnibenCustomer())
        return

    def test_addUnibenCustomer(self):
        customer = createObject(u'waeup.Customer')
        verify.verifyObject(IUnibenCustomer, customer)
        self.app['customers'].addCustomer(customer)
        self.assertEqual(customer.customer_id, 'B1000000')
        self.assertEqual(self.app['customers']['B1000000'], customer)
        return

    def tearDown(self):
        shutil.rmtree(self.dc_root)
        super(UnibenCustomerTestCase, self).tearDown()
        return
