def test_process_gender(self): """ Test parsing of gender field.""" with self.app.app_context(): female_data = self.fake_ldap_data(swissEduPersonGender='0') female_filtered = ldap._process_data(female_data) self.assertTrue(female_filtered['gender'] == 'female') male_data = self.fake_ldap_data(swissEduPersonGender='1') male_filtered = ldap._process_data(male_data) self.assertTrue(male_filtered['gender'] == 'male')
def test_process_gender(self): """ Test parsing of gender field.""" with self.app.app_context(): female_data = self.fake_ldap_data(swissEduPersonGender='0') female_filtered = ldap._process_data(female_data) self.assertTrue(female_filtered['gender'] == 'female') male_data = self.fake_ldap_data(swissEduPersonGender='1') male_filtered = ldap._process_data(male_data) self.assertTrue(male_filtered['gender'] == 'male')
def test_process_data(self): """The received LDAP data can look weird. Test that it is filtered.""" with self.app.app_context(): filtered = ldap._process_data(self.fake_ldap_data()) expected = self.fake_filtered_data() self.assertEqual(filtered, expected)
def test_process_data(self): """The received LDAP data can look weird. Test that it is filtered.""" with self.app.app_context(): filtered = ldap._process_data(self.fake_ldap_data()) expected = self.fake_filtered_data() self.assertEqual(filtered, expected)
def test_process_department(self): """Test department filtering. Relies on 'departmentNUmber' field.""" with self.app.app_context(): tests = ( ('ETH Studentin D-ITET', 'itet'), ('ETH Student D-ITET', 'itet'), ('ETH Student D-MAVT', 'mavt'), ('ETH Studentin D-MAVT', 'mavt'), ('ETH Student D-ITET and more text that', 'itet'), ('ETH Studentin D-SOMETHINGELSE', None), ('any other text', None), ('', None), ) for ldap_value, api_value in tests: data = self.fake_ldap_data(departmentNumber=[ldap_value]) filtered = ldap._process_data(data) self.assertTrue(filtered['department'] == api_value)
def test_process_department(self): """Test department filtering. Relies on 'departmentNUmber' field.""" with self.app.app_context(): tests = ( ('ETH Studentin D-ITET', 'itet'), ('ETH Student D-ITET', 'itet'), ('ETH Student D-MAVT', 'mavt'), ('ETH Studentin D-MAVT', 'mavt'), ('ETH Student D-ITET and more text that', 'itet'), ('ETH Studentin D-SOMETHINGELSE', None), ('any other text', None), ('', None), ) for ldap_value, api_value in tests: data = self.fake_ldap_data(departmentNumber=[ldap_value]) filtered = ldap._process_data(data) self.assertTrue(filtered['department'] == api_value)
def test_process_data_incomplete_response(self): """Test that processing ldap response works even if some fields are missing.""" tests = ( # (missing ldap_field, (missing filtered_fields), \ # {patch for expected}) ('cn', ('nethz', 'email')), ('swissEduPersonMatriculationNumber', ('legi')), ('givenName', ('firstname')), ('sn', ('lastname')), ('swissEduPersonGender', ('gender')), ('departmentNumber', tuple(), { 'department': None, 'membership': 'none', 'send_newsletter': False }), ('ou', ('send_newsletter'), { 'membership': 'none' }), ) with self.app.app_context(): for test in tests: ldap_data = { key: value for key, value in self.fake_ldap_data().items() if key != test[0] } filtered = ldap._process_data(ldap_data) expected = { key: value for key, value in self.fake_filtered_data().items() if key not in test[1] } # Apply patch for expected data if len(test) > 2: expected.update(**test[2]) if (expected['membership'] == 'none' and 'send_newsletter' in expected): del expected['send_newsletter'] self.assertEqual(filtered, expected)
def test_process_membership(self): """Test membership filtering.""" with self.app.app_context(): # ou must contain 'VSETH Mitglied' # and department must not be None (see other test) our = 'ETH Student D-ITET' other = 'ETH Student D-OTHER' self.app.config['LDAP_DEPARTMENT_MAP'] = {our: 'itet'} tests = ( # (departmentNUmber, ou, expected result) ([our], ['VSETH Mitglied'], 'regular'), ([our], ['blabla', 'VSETH Mitglied', 'random'], 'regular'), # Something missing ([our], ['novseth'], 'none'), ([other], ['VSETH Mitglied'], 'none'), ([other], ['nonono'], 'none'), ([other], [], 'none'), ) for (dn, ou, result) in tests: data = self.fake_ldap_data(departmentNumber=dn, ou=ou) filtered = ldap._process_data(data) self.assertTrue(filtered['membership'] == result)
def test_process_membership(self): """Test membership filtering.""" with self.app.app_context(): # ou must contain 'VSETH Mitglied' # and department must not be None (see other test) our = 'ETH Student D-ITET' other = 'ETH Student D-OTHER' self.app.config['LDAP_DEPARTMENT_MAP'] = {our: 'itet'} tests = ( # (departmentNUmber, ou, expected result) ([our], ['VSETH Mitglied'], 'regular'), ([our], ['blabla', 'VSETH Mitglied', 'random'], 'regular'), # Something missing ([our], ['novseth'], 'none'), ([other], ['VSETH Mitglied'], 'none'), ([other], ['nonono'], 'none'), ([other], [], 'none'), ) for (dn, ou, result) in tests: data = self.fake_ldap_data(departmentNumber=dn, ou=ou) filtered = ldap._process_data(data) self.assertTrue(filtered['membership'] == result)