Ignore:
Timestamp:
26 Aug 2013, 13:04:51 (11 years ago)
Author:
uli
Message:

pep8.

Location:
main/waeup.cas/trunk/waeup/cas
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/authenticators.py

    r10526 r10535  
    173173        return (False, 'Invalid username or password.')
    174174
     175
    175176class KofaMoodleAuthenticator(KofaAuthenticator):
    176177    """Authenticate against a running Kofa instance and transfer
     
    179180    Configuration of Moodle:
    180181    1. Set 'passwordpolicy' to No
    181     2. Create external web service 'Kofa' with the following functions:
    182       core_user_create_users, core_user_get_users,
    183       core_user_update_users, enrol_manual_enrol_users
    184     3. Create token for the admin user (no special web service user needed)
    185       and for service 'Kofa'
    186     4. Enable and configure CAS server authentication.
    187       CAS protocol version is 1.0. Moodle expects SSL/TLS protocol.
    188     """
    189 
     182
     183    2. Create external web service 'Kofa' with the following
     184       functions: core_user_create_users, core_user_get_users,
     185       core_user_update_users, enrol_manual_enrol_users
     186
     187    3. Create token for the admin user (no special web service user
     188       needed) and for service 'Kofa'
     189
     190    4. Enable and configure CAS server authentication. CAS protocol
     191       version is 1.0. Moodle expects SSL/TLS protocol.
     192    """
    190193    name = 'kofa_moodle1'
    191194
     
    226229        try:
    227230            result = moodle.core_user_update_users([
    228                 {'id':user_id,'auth':'cas'}])
     231                {'id': user_id, 'auth': 'cas'}])
    229232        except xmlrpclib.Fault:
    230233            faultstring = sys.exc_info()[1].faultString
     
    247250            moodle = xmlrpclib.ServerProxy(
    248251                backend['moodle_url'], allow_none=True)
    249             principal = proxy.check_applicant_credentials(kofa_username, password)
     252            principal = proxy.check_applicant_credentials(
     253                kofa_username, password)
    250254            if principal is None:
    251                 principal = proxy.check_student_credentials(kofa_username, password)
     255                principal = proxy.check_student_credentials(
     256                    kofa_username, password)
    252257            if principal is None:
    253258                return (False, 'Invalid username or password')
     
    260265            return (False, 'User not eligible')
    261266        return (False, 'Invalid username or password')
    262 
  • main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py

    r10526 r10535  
    1 3# Tests for waeup.cas.authentictors
     1# Tests for waeup.cas.authentictors
    22import os
    33import threading
     
    8888        url='http://localhost:6666/',
    8989        marker='^SCHOOL1-',
    90         moodle_url = 'http://localhost:7777/',
     90        moodle_url='http://localhost:7777/',
    9191        )
    9292    )
     93
    9394
    9495class KofaAuthenticatorTests(unittest.TestCase):
     
    132133        assert app.db_connection_string == 'sqlite:///:memory:'
    133134        assert isinstance(app.auth, KofaAuthenticator)
     135
    134136
    135137class KofaMoodleAuthenticatorTests(unittest.TestCase):
     
    148150            {'url': 'http://xmlrpcuser1:xmlrpcuser1@localhost:8080/app1/',
    149151             'marker': '^K',
    150              'moodle_url': 'http://localhost/moodle/webservice/xmlrpc/server.php?wstoken=de1e1cbacf91ec6290bb6f6339122e7d',
     152             'moodle_url': ('http://localhost/moodle/webservice/xmlrpc'
     153                            '/server.php?wstoken=de1e1cbacf91ec6290bb6'
     154                            'f6339122e7d'),
    151155            },
    152156          }
     
    214218                        )
    215219
     220
    216221class FakeMoodleServer(SimpleXMLRPCServer):
    217222    # A fake Moodle server that provides only XMLRPC methods
     
    242247            raise xmlrpclib.Fault('faultCode', 'core_user_get_users failed')
    243248        if arg[0]['value'] == 'SCHOOL1-fault3':
    244             return {'users':[{'id':'SCHOOL1-fault3'}]}
     249            return {'users': [{'id': 'SCHOOL1-fault3'}]}
    245250        if arg[0]['value'] in ('SCHOOL1-fault4', 'SCHOOL1-fault5'):
    246             return {'users':[{'id': 123}]}
     251            return {'users': [{'id': 123}]}
    247252        return {'users': []}
    248253
     
    252257            raise xmlrpclib.Fault('faultCode', 'core_user_update_users failed')
    253258        return None
     259
    254260
    255261class KofaAuthenticatorsIntegrationTests(unittest.TestCase):
     
    271277        # set up a fake moodle server
    272278        cls.moodle_server = FakeMoodleServer(('localhost', 7777))
    273         cls.moodle_th = threading.Thread(target=cls.moodle_server.serve_forever)
     279        cls.moodle_th = threading.Thread(
     280            target=cls.moodle_server.serve_forever)
    274281        cls.moodle_th.daemon = True
    275282        cls.moodle_th.start()
     
    319326        result = proxy.core_user_create_users(
    320327            [{'username': 'any name'}])
    321         assert result ==  [{'id': 37, 'username': 'any name'}]
     328        assert result == [{'id': 37, 'username': 'any name'}]
    322329        self.assertRaises(
    323330            xmlrpclib.Fault, proxy.core_user_create_users,
     
    354361        result1s = auth.check_credentials('SCHOOL1-bird', 'bebop')
    355362        assert result1s == (True, '')
    356         result1a  = auth.check_credentials('SCHOOL1-pig', 'pog')
     363        result1a = auth.check_credentials('SCHOOL1-pig', 'pog')
    357364        assert result1a == (True, '')
    358365        # user does not exist
Note: See TracChangeset for help on using the changeset viewer.