def init(self):
        '''This method is invoked automatically in order to setup common dependencies for all test cases.'''

        self._db_conn = Mock()
        self._user_facade = Mock()

        model_facade_cls = Mock(return_value=self._user_facade)

        self._repo = UserRepository(self._db_conn,
                                    model_facade_cls=model_facade_cls)

        model_facade_cls.assert_called_once_with(User, self._db_conn)
class UserRepositoryTests(FantasticoUnitTestsCase):
    '''This class provides tests suite for user repository.'''

    _db_conn = None
    _repo = None
    _user_facade = None

    def init(self):
        '''This method is invoked automatically in order to setup common dependencies for all test cases.'''

        self._db_conn = Mock()
        self._user_facade = Mock()

        model_facade_cls = Mock(return_value=self._user_facade)

        self._repo = UserRepository(self._db_conn,
                                    model_facade_cls=model_facade_cls)

        model_facade_cls.assert_called_once_with(User, self._db_conn)

    def test_load_by_username(self):
        '''This test case ensures a user can be loaded by username.'''

        user = User(username="******",
                    password="******",
                    person_id=1)

        self._user_facade.get_records_paged = Mock(return_value=[user])

        result = self._repo.load_by_username(user.username)

        self.assertEqual(user, result)

        self._user_facade.get_records_paged.assert_called_once_with(
            start_record=0,
            end_record=1,
            filter_expr=ModelFilter(User.username, user.username,
                                    ModelFilter.EQ))

    def test_load_by_username_notfound(self):
        '''This test case ensures a concrete db exception is raised if the given username is not found.'''

        self._user_facade.get_records_paged = Mock(return_value=[])

        with self.assertRaises(FantasticoDbNotFoundError):
            self._repo.load_by_username("john.doe")
    def init(self):
        '''This method is invoked automatically in order to setup common dependencies for all test cases.'''

        self._db_conn = Mock()
        self._user_facade = Mock()

        model_facade_cls = Mock(return_value=self._user_facade)

        self._repo = UserRepository(self._db_conn, model_facade_cls=model_facade_cls)

        model_facade_cls.assert_called_once_with(User, self._db_conn)
class UserRepositoryTests(FantasticoUnitTestsCase):
    '''This class provides tests suite for user repository.'''

    _db_conn = None
    _repo = None
    _user_facade = None

    def init(self):
        '''This method is invoked automatically in order to setup common dependencies for all test cases.'''

        self._db_conn = Mock()
        self._user_facade = Mock()

        model_facade_cls = Mock(return_value=self._user_facade)

        self._repo = UserRepository(self._db_conn, model_facade_cls=model_facade_cls)

        model_facade_cls.assert_called_once_with(User, self._db_conn)

    def test_load_by_username(self):
        '''This test case ensures a user can be loaded by username.'''

        user = User(username="******", password="******", person_id=1)

        self._user_facade.get_records_paged = Mock(return_value=[user])

        result = self._repo.load_by_username(user.username)

        self.assertEqual(user, result)

        self._user_facade.get_records_paged.assert_called_once_with(
                                                start_record=0, end_record=1,
                                                filter_expr=ModelFilter(User.username, user.username, ModelFilter.EQ))

    def test_load_by_username_notfound(self):
        '''This test case ensures a concrete db exception is raised if the given username is not found.'''

        self._user_facade.get_records_paged = Mock(return_value=[])

        with self.assertRaises(FantasticoDbNotFoundError):
            self._repo.load_by_username("john.doe")