1# -*- coding: utf-8 -*- 2""" 3Simple tests for module ldap0.extop 4""" 5 6# from Python's standard lib 7import unittest 8 9from ldap0.extop import ExtendedRequest, ExtendedResponse 10from ldap0.extop.passmod import PassmodResponse 11 12 13class TestExtOpRequest(unittest.TestCase): 14 """ 15 test classes for encoding extended operation requests 16 """ 17 18 def test_basic(self): 19 er = ExtendedRequest('1.2.3.4') 20 self.assertEqual(er.requestName, '1.2.3.4') 21 self.assertEqual(er.requestValue, None) 22 self.assertEqual(repr(er), "ExtendedRequest(requestName='1.2.3.4', requestValue=None)") 23 er = ExtendedRequest(requestName='1.2.3.4') 24 self.assertEqual(er.requestName, '1.2.3.4') 25 self.assertEqual(er.requestValue, None) 26 self.assertEqual(repr(er), "ExtendedRequest(requestName='1.2.3.4', requestValue=None)") 27 er = ExtendedRequest('1.2.3.4', 'foobar') 28 self.assertEqual(er.requestName, '1.2.3.4') 29 self.assertEqual(er.requestValue, 'foobar') 30 self.assertEqual(repr(er), "ExtendedRequest(requestName='1.2.3.4', requestValue='foobar')") 31 self.assertEqual(er.encode(), 'foobar') 32 33 34class TestExtOpResponse(unittest.TestCase): 35 """ 36 test classes for decoding extended operation responses 37 """ 38 39 def test_basic(self): 40 er = ExtendedResponse() 41 self.assertEqual(er.responseValue, None) 42 self.assertEqual(repr(er), "ExtendedResponse(encodedResponseValue=None)") 43 er = ExtendedResponse('foobar') 44 self.assertEqual(er.responseValue, 'foobar') 45 self.assertEqual(repr(er), "ExtendedResponse(encodedResponseValue='foobar')") 46 er.decode('foobar42') 47 self.assertEqual(er.responseValue, 'foobar42') 48 49 def test_passmod(self): 50 er = PassmodResponse() 51 er.decode(None) 52 self.assertEqual(er.responseValue, None) 53 54 55if __name__ == '__main__': 56 unittest.main() 57