tests/xmlrpc.py
branchdevel
changeset 126 1ac2439a68b5
parent 125 19b3f383c9ce
child 127 79966b937274
equal deleted inserted replaced
125:19b3f383c9ce 126:1ac2439a68b5
    67         self.failUnlessEqual(ret,'hello')
    67         self.failUnlessEqual(ret,'hello')
    68 
    68 
    69     def testListMethods(self):
    69     def testListMethods(self):
    70         '''list of all offical Methods, that can be executed'''
    70         '''list of all offical Methods, that can be executed'''
    71         ret=self.__rpc2().listMethods()
    71         ret=self.__rpc2().listMethods()
    72         self.failUnlessEqual(ret, ['listMethods', 'status', 'stop', 'sms', 'fax', 'mail', 'routes', 'defaultRoute', 'statistic'])
    72         self.failUnlessEqual(ret, ['listMethods', 'status', 'stop', 'sms', 'fax', 'mail', 'routes', 'defaultRoute', 'statistic', 'telnumber','email'])
    73 
    73 
    74     def testStatus(self):
    74     def testStatus(self):
    75         ''' test the status function'''
    75         ''' test the status function'''
    76         with WithSession(md.engine, autocommit=True) as session:
    76         with WithSession(md.engine, autocommit=True) as session:
    77             u = User(name='test',apikey='abcdef123456789')
    77             u = User(name='test',apikey='abcdef123456789')
   169             o=Offer(name="sipgate_plus", provider="sipgate", route="plus", typ="sms")
   169             o=Offer(name="sipgate_plus", provider="sipgate", route="plus", typ="sms")
   170             u.rights.append(Userright(o))
   170             u.rights.append(Userright(o))
   171             session.add(u)
   171             session.add(u)
   172         self.failUnlessEqual(self.__rpc2().defaultRoute('abcdef123456789','sms'),['sipgate_basic'])
   172         self.failUnlessEqual(self.__rpc2().defaultRoute('abcdef123456789','sms'),['sipgate_basic'])
   173 
   173 
   174 
   174     def testTelnumbers(self):
   175 
   175         '''test the telefon validator'''
       
   176         self.failUnlessEqual(self.__rpc2().telnumber(["0123/456(78)","+4912346785433","00123435456-658"]),True)
       
   177         numbers=['xa','+1','1-23',';:+0','0123']
       
   178         for number in numbers:
       
   179             with self.assertRaises(Fault) as fault:
       
   180                 self.__rpc2().telnumber([number])
       
   181             exc = fault.exception
       
   182             self.failUnlessEqual(exc.faultCode, 701)
       
   183             self.failUnlessEqual(exc.faultString, "No valid telnumber: '%s'"%number)
       
   184 
       
   185         with self.assertRaises(Fault) as fault:
       
   186             self.__rpc2().telnumber(['01234']+numbers)
       
   187         exc = fault.exception
       
   188         self.failUnlessEqual(exc.faultCode, 701)
       
   189         self.failUnlessEqual(exc.faultString, "No valid telnumber: '%s'"%numbers[0])
       
   190 
       
   191 
       
   192     def testVaildEmail(self):
       
   193         '''test vaild email adresses (got from wikipedia)'''
       
   194         validmails=["niceandsimple@example.com",
       
   195                 "simplewith+symbol@example.com",
       
   196                 'a.little.unusual@example.com',
       
   197                 'a.little.more.unusual@dept.example.com',
       
   198                 '@[10.10.10.10]',
       
   199                 '@[1.1.1.1]',
       
   200                 '@[200.100.100.100]',
       
   201                 'user@[2001:db8:1ff::a0b:dbd0]',
       
   202                 '"much.more\ unusual"@example.com',
       
   203                 '"very.unusual.@.unusual.com"@example.com',
       
   204                 '"very.(),:;<>[]\\".VERY.\\"very@\\\ \\"very\\".unusual"@strange.example.com',
       
   205                 "!#$%&'*+-/=?^_`{}|~@example.org",
       
   206                 '"()<>[]:;@,\\\"!#$%&\'*+-/=?^_`{}| ~  ? ^_`{}|~."@example.org',
       
   207                 '""@example.org']
       
   208         
       
   209         for num in validmails:
       
   210             self.failUnlessEqual(self.__rpc2().email([num]),True)
       
   211     
       
   212     def testInvaildEmail(self):
       
   213         '''test invaild email adresses (got from wikipedia)'''
       
   214         invalid=["Abc.example.com",  # (an @ character must separate the local and domain parts)
       
   215                 "Abc.@example.com",          # (character dot(.) is last in local part)
       
   216                 "Abc..123@example.com",      # (character dot(.) is double)
       
   217                 "A@b@c@example.com",         # (only one @ is allowed outside quotation marks)
       
   218                 'a"b(c)d,e:f;g<h>i[j\k]l@example.com',  # (none of the special characters in this local part is allowed outside quotation marks)
       
   219                 'just"not"right@example.com',           # (quoted strings must be dot separated, or the only element making up the local-part)
       
   220                 'thisis."notallowed@example.com',      # (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a slash)
       
   221                 'this\\ still\\"not\\allowed@example.com',   # (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes)
       
   222                 ]
       
   223 
       
   224         for number in invalid:
       
   225             with self.assertRaises(Fault) as fault:
       
   226                 self.__rpc2().email([number])
       
   227             exc = fault.exception
       
   228             self.failUnlessEqual(exc.faultCode, 702)
       
   229             self.failUnlessEqual(exc.faultString, "No valid email: '%s'"%number)
       
   230 
       
   231  
   176 def startReactor(engine):
   232 def startReactor(engine):
   177     """starts the Rector with a special debug Clild, so that the reactor can be stopped remotly. """
   233     """starts the Rector with a special debug Clild, so that the reactor can be stopped remotly. """
   178     from twisted.internet import reactor
   234     from twisted.internet import reactor
   179     from twisted.web import xmlrpc, resource
   235     from twisted.web import xmlrpc, resource
   180     
   236