Ignore:
Timestamp:
21 Aug 2013, 11:44:28 (11 years ago)
Author:
Henrik Bettermann
Message:

Update applicant data too. get_applicant_moodle_data yet to be implemented in Kofa.

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

Legend:

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

    r10517 r10518  
    241241                    userdata = proxy.get_student_moodle_data(username)
    242242                    return self._create_user(username, userdata, moodle)
    243         return (False, 'Invalid username or password.')
     243                if principal['type'] == 'applicant':
     244                    userdata = proxy.get_applicant_moodle_data(username)
     245                    return self._create_user(username, userdata, moodle)
     246        return (False, 'Invalid username or password or user not eligible.')
  • main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py

    r10515 r10518  
    167167            self._check_credentials, 'check_student_credentials')
    168168        self.register_function(
    169             self._get_student_moodle_data, 'get_student_moodle_data')
     169            self._get_moodle_data, 'get_student_moodle_data')
     170        self.register_function(
     171            self._get_moodle_data, 'get_applicant_moodle_data')
    170172
    171173    def _check_credentials(self, username, password):
     
    186188            'fault1', 'fault2', 'fault3', 'fault4') and password == 'biz':
    187189            return {'type': 'student'}
     190        if username == 'fault5' and password == 'biz':
     191            return {'type': 'applicant'}
    188192        return None
    189193
    190     def _get_student_moodle_data(self, username):
     194    def _get_moodle_data(self, username):
    191195        # fake waeup.kofa get_student_moodle_data method.
    192196        if username == 'bird':
     
    200204                        lastname='Charles',
    201205                        )
    202         if username in ('fault1', 'fault2', 'fault3', 'fault4'):
     206        if username in ('fault1', 'fault2', 'fault3', 'fault4', 'fault5'):
    203207            return dict(email='ff@ff.ff',
    204208                        firstname='John',
     
    225229        if arg[0]['username'] == 'fault1':
    226230            raise xmlrpclib.Fault('faultCode', 'faultString')
    227         if arg[0]['username'] == 'fault4':
     231        if arg[0]['username'] in ('fault4', 'fault5'):
    228232            raise xmlrpclib.Fault('faultCode', 'Username already exists')
    229233        return None
     
    295299            'firstname': 'Ray',
    296300            }
     301        result = proxy.get_applicant_moodle_data('pig')
     302        assert result == {
     303            'lastname': 'Charles',
     304            'email': 'bb@bb.bb',
     305            'firstname': 'Ray',
     306            }
    297307        return
    298308
     
    323333        return
    324334
    325     def test_check_credentials_1(self):
     335    def test_check_credentials_KofaAuthenticator(self):
    326336        # we get real responses when querying Kofa instances
    327337        auth = KofaAuthenticator(auth_backends=str(BACKENDS2))
     
    333343        assert result3 == (False, 'Invalid username or password.')
    334344
    335     def test_check_credentials_2(self):
     345    def test_check_credentials_KofaMoodleAuthenticator(self):
    336346        # we get real responses when querying Kofa instances
    337347        auth = KofaMoodleAuthenticator(auth_backends=str(BACKENDS3))
    338         result1 = auth.check_credentials('SCHOOL1-bird', 'bebop')
    339         assert result1 == (True, '')
    340         result2 = auth.check_credentials('SCHOOL1-foo', 'bar')
    341         assert result2 == (False, 'Invalid username or password.')
    342         result3 = auth.check_credentials('SCHOOL2-bar', 'baz')
    343         assert result3 == (False, 'Invalid username or password.')
     348        result1s = auth.check_credentials('SCHOOL1-bird', 'bebop')
     349        assert result1s == (True, '')
     350        result1a  = auth.check_credentials('SCHOOL1-pig', 'pog')
     351        assert result1a == (True, '')
     352        result2s = auth.check_credentials('SCHOOL1-foo', 'bar')
     353        assert result2s == (
     354            False, 'Invalid username or password or user not eligible.')
     355        result3s = auth.check_credentials('SCHOOL2-bar', 'baz')
     356        assert result3s == (
     357            False, 'Invalid username or password or user not eligible.')
     358
    344359        # exceptions are raised in the follwoing cases
    345         result4 = auth.check_credentials('SCHOOL1-fault1', 'biz')
    346         assert result4 == (False, 'faultString')
    347         result5 = auth.check_credentials('SCHOOL1-fault2', 'biz')
    348         assert result5 == (False, 'faultString')
    349         result6 = auth.check_credentials('SCHOOL1-fault3', 'biz')
    350         assert result6 == (False, 'faultString')
     360        result4s = auth.check_credentials('SCHOOL1-fault1', 'biz')
     361        assert result4s == (False, 'faultString')
     362        result5s = auth.check_credentials('SCHOOL1-fault2', 'biz')
     363        assert result5s == (False, 'faultString')
     364        result6s = auth.check_credentials('SCHOOL1-fault3', 'biz')
     365        assert result6s == (False, 'faultString')
     366
    351367        # no exception if user exists
    352         result7 = auth.check_credentials('SCHOOL1-fault4', 'biz')
    353         assert result7 == (True, '')
     368        result7s = auth.check_credentials('SCHOOL1-fault4', 'biz')
     369        assert result7s == (True, '')
     370        result7a = auth.check_credentials('SCHOOL1-fault5', 'biz')
     371        assert result7a == (True, '')
Note: See TracChangeset for help on using the changeset viewer.