# Path: pyvac/tests/case.py
# class ModelTestCase(TestCase):
# 
#     def setUp(self):
#         transaction.begin()
#         self.session = DBSession()
# 
#     def tearDown(self):
#         transaction.commit()


from datetime import datetime
from freezegun import freeze_time
from dateutil.relativedelta import relativedelta
from mock import patch, PropertyMock, MagicMock
from .case import ModelTestCase
        from pyvac.models import Group
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User, Request
        from pyvac.models import User, Request
        from pyvac.models import User, Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import User, VacationType
        from pyvac.models import User, VacationType
        from pyvac.models import User, VacationType
        from pyvac.models import User, VacationType
        from pyvac.models import VacationType
        from pyvac.models import VacationType
        from pyvac.models import VacationType
        from pyvac.models import User
        from pyvac.models import CPLUVacation, CompensatoireVacation, User
        from pyvac.models import CPVacation, User
        from pyvac.models import Sudoer
        from pyvac.models import Sudoer
        from pyvac.models import User
        from pyvac.models import Sudoer
        from pyvac.models import User
            with patch('pyvac.models.User.pool',
                       new_callable=PropertyMock) as mock_foo:
                mocked_pool1 = mock_pool(12.48, date_start, date_end)
                mocked_pool2 = mock_pool(0, date_start, date_end)
                mock_foo.return_value = {'CP acquis': mocked_pool1,
                                         'CP restant': mocked_pool2}

                user = User.by_login(self.session, 'jdoe')
                self.assertIsInstance(user, User)
                cp_pool = user.pool.get('CP acquis')
                self.assertTrue(cp_pool)
                cp_pool = user.pool.get('CP restant')
                self.assertTrue(cp_pool)

                days = 3
                date_from = datetime.now().replace(year=datetime.now().year + 2) # noqa
                date_to = date_from + relativedelta(days=3)
                err = CPVacation.validate_request(user, None, days,
                                                  date_from, date_to)
                msg = 'CP can only be used until %s.' % user.pool['CP acquis'].date_end.strftime('%d/%m/%Y') # noqa
                self.assertEqual(err, msg)


class SudoerTestCase(ModelTestCase):

    def test_list(self):
        sudoers = Sudoer.list(self.session)
        self.assertEqual(len(sudoers), 1)
        sudoer = sudoers[0]
        self.assertIsInstance(sudoer, Sudoer)

# Path: pyvac/tests/case.py
# class ModelTestCase(TestCase):
# 
#     def setUp(self):
#         transaction.begin()
#         self.session = DBSession()
# 
#     def tearDown(self):
#         transaction.commit()


# Path: pyvac/tests/test_models.py
from datetime import datetime
from freezegun import freeze_time
from dateutil.relativedelta import relativedelta
from mock import patch, PropertyMock, MagicMock
from .case import ModelTestCase
        from pyvac.models import Group
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User
        from pyvac.models import User, Request
        from pyvac.models import User, Request
        from pyvac.models import User, Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import Request
        from pyvac.models import User, VacationType
        from pyvac.models import User, VacationType
        from pyvac.models import User, VacationType
        from pyvac.models import User, VacationType
        from pyvac.models import VacationType
        from pyvac.models import VacationType
        from pyvac.models import VacationType
        from pyvac.models import User
        from pyvac.models import CPLUVacation, CompensatoireVacation, User
        from pyvac.models import CPVacation, User
        from pyvac.models import Sudoer
        from pyvac.models import Sudoer
        from pyvac.models import User
        from pyvac.models import Sudoer
        from pyvac.models import User

            with patch('pyvac.models.User.pool',
                       new_callable=PropertyMock) as mock_foo:
                mocked_pool1 = mock_pool(12.48, date_start, date_end)
                mocked_pool2 = mock_pool(0, date_start, date_end)
                mock_foo.return_value = {'CP acquis': mocked_pool1,
                                         'CP restant': mocked_pool2}

                user = User.by_login(self.session, 'jdoe')
                self.assertIsInstance(user, User)
                cp_pool = user.pool.get('CP acquis')
                self.assertTrue(cp_pool)
                cp_pool = user.pool.get('CP restant')
                self.assertTrue(cp_pool)

                days = 3
                date_from = datetime.now().replace(year=datetime.now().year + 2) # noqa
                date_to = date_from + relativedelta(days=3)
                err = CPVacation.validate_request(user, None, days,
                                                  date_from, date_to)
                msg = 'CP can only be used until %s.' % user.pool['CP acquis'].date_end.strftime('%d/%m/%Y') # noqa
                self.assertEqual(err, msg)


class SudoerTestCase(ModelTestCase):

    def test_list(self):
        sudoers = Sudoer.list(self.session)
        self.assertEqual(len(sudoers), 1)
        sudoer = sudoers[0]
        self.assertIsInstance(sudoer, Sudoer)

        self.assertEqual(sudoer.target_id, 1)