<commit_before># -*- coding: utf-8 -*-
##
## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio 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.
##
## CDS Invenio 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 CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Unit tests for the user handling library."""

__revision__ = "$Id$"

import unittest

from invenio import external_authentication_cern as cern
from invenio.testutils import make_test_suite, run_test_suite

class ExternalAuthenticationCernTest(unittest.TestCase):
    """Test functions related to the CERN authentication."""

    def setUp(self):
        # pylint: disable-msg=C0103
        """setting up helper variables for tests"""
        self.username, self.userpwd, self.useremail = \
                open('demopwd.cfg', 'r').readline().strip().split(':', 2)
        self.cern = cern.ExternalAuthCern()

    def test_auth_user_ok(self):
        """external authentication CERN - authorizing user through CERN system: should pass"""
        self.assertEqual(self.cern.auth_user(self.username, self.userpwd), \
                self.useremail)

    def test_auth_user_fail(self):
        """external authentication CERN - authorizing user through CERN system: should fail"""
        self.assertEqual(self.cern.auth_user('patata', 'patata'), None)

    def test_fetch_user_groups_membership(self):
        """external authentication CERN - fetching user group membership at CERN"""
        self.assertNotEqual(self.cern.fetch_user_groups_membership(self.useremail, self.userpwd), 0)
        self.assertEqual(self.cern.fetch_user_groups_membership('patata', 'patata'), {})

    def test_fetch_user_preferences(self):
        """external authentication CERN - fetching user setting from CERN"""
        self.assertEqual(self.cern.fetch_user_preferences(self.username, self.userpwd)['email'], self.useremail)
        #self.assertRaises(KeyError, self.cern.fetch_user_preferences('patata', 'patata')['email'])

# FIXME: the above tests not plugged into global unit test suite
TEST_SUITE = make_test_suite() # ExternalAuthenticationCernTest,)

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)

<commit_msg>Fixed tests by using CFG_CERN_SITE.<commit_after># -*- coding: utf-8 -*-
##
## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio 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.
##
## CDS Invenio 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 CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Unit tests for the user handling library."""

__revision__ = "$Id$"

import unittest

from invenio.config import CFG_CERN_SITE
from invenio.testutils import make_test_suite, run_test_suite

class ExternalAuthenticationCernTest(unittest.TestCase):
    """Test functions related to the CERN authentication."""

    def setUp(self):
        # pylint: disable-msg=C0103
        """setting up helper variables for tests"""
        from invenio import external_authentication_cern as cern
        self.username, self.userpwd, self.useremail = \
                open('demopwd.cfg', 'r').readline().strip().split(':', 2)
        self.cern = cern.ExternalAuthCern()

    def test_auth_user_ok(self):
        """external authentication CERN - authorizing user through CERN system: should pass"""
        self.assertEqual(self.cern.auth_user(self.username, self.userpwd), \
                self.useremail)

    def test_auth_user_fail(self):
        """external authentication CERN - authorizing user through CERN system: should fail"""
        self.assertEqual(self.cern.auth_user('patata', 'patata'), None)

    def test_fetch_user_groups_membership(self):
        """external authentication CERN - fetching user group membership at CERN"""
        self.assertNotEqual(self.cern.fetch_user_groups_membership(self.useremail, self.userpwd), 0)
        self.assertEqual(self.cern.fetch_user_groups_membership('patata', 'patata'), {})

    def test_fetch_user_preferences(self):
        """external authentication CERN - fetching user setting from CERN"""
        self.assertEqual(self.cern.fetch_user_preferences(self.username, self.userpwd)['email'], self.useremail)
        #self.assertRaises(KeyError, self.cern.fetch_user_preferences('patata', 'patata')['email'])

if CFG_CERN_SITE:
    TEST_SUITE = make_test_suite(ExternalAuthenticationCernTest,)
else:
    TEST_SUITE = make_test_suite()

if __name__ == "__main__":
    run_test_suite(TEST_SUITE)


{'fraction_non_alphanumeric': 0.10641321726772074, 'fraction_numerical': 0.017765144785930005, 'mean_word_length': 4.076645626690713, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '12791', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1615, 'n_words': 527}