def test_class_array(self): peeps = [] names = ['bob', 'jim', 'peabody', 'mumblesleves'] dob = datetime.datetime(1979, 1, 1) for name in names: a = Person() a.name = name a.birthdate = dob a.age = 27 peeps.append(a) type = Array(Person) type.resolve_namespace(type, __name__) element = etree.Element('test') XmlObject().to_parent_element(type, peeps, ns_test, element) element = element[0] self.assertEquals(4, len(element.getchildren())) peeps2 = XmlObject().from_element(type, element) for i in range(0, 4): self.assertEquals(peeps2[i].name, names[i]) self.assertEquals(peeps2[i].birthdate, dob)
def test_class_nested_array(self): peeps = [] names = ['bob', 'jim', 'peabody', 'mumblesleves'] for name in names: a = Person() a.name = name a.birthdate = datetime.datetime(1979, 1, 1) a.age = 27 a.addresses = [] for i in range(0, 25): addr = Address() addr.street = '555 downtown' addr.city = 'funkytown' a.addresses.append(addr) peeps.append(a) type = Array(Person) type.resolve_namespace(type, __name__) element = etree.Element('test') XmlObject().to_parent_element(type, peeps, ns_test, element) element = element[0] self.assertEquals(4, len(element.getchildren())) peeps2 = XmlObject().from_element(type, element) for peep in peeps2: self.assertEquals(27, peep.age) self.assertEquals(25, len(peep.addresses)) self.assertEquals('funkytown', peep.addresses[18].city)
class PostmasterServer(SoapListener.BasicSoapServer): """The SOAP commands available for the clients. TODO: is the following correct anymore? Note that an instance of this class is created for each incoming call. """ # Headers: no need for headers for e.g. session IDs in this web service. # The class where the Cerebrum-specific functionality is done. This is # instantiated per call, to avoid thread conflicts. cere_class = None # The hock for the site object site = None @rpc(Array(String), Array(String), Array(String), _returns=Array(String)) def get_addresses_by_affiliation(ctx, status=None, skos=None, source=None): """Get primary e-mail addresses for persons that match given criterias.""" if not source and not status: raise Errors.CerebrumRPCException('Input needed') return ctx.udc['postmaster'].get_addresses_by_affiliation(status=status, skos=skos, source=source)
class Person(ComplexModel): __namespace__ = "TestService" name = String birthdate = DateTime age = Integer addresses = Array(Address) titles = Array(String)
class NestedClass(ComplexModel): __namespace__ = "punk.tunk" simple = Array(SimpleClass) s = String i = Integer f = Float other = OtherClass ai = Array(Integer)
class InteropMisc(ServiceBase): @srpc(_returns=[ Integer, String, Integer, Array(Enum("MEMBER", type_name="RoleEnum")) ], _out_variable_names=[ 'resultCode', 'resultDescription', 'transactionId', 'roles' ]) def complex_return(): return [1, "Test", 123, ["MEMBER"]] @srpc(_returns=Integer) def huge_number(): return 2**int(1e5) @srpc(_returns=String) def long_string(): return ('0123456789abcdef' * 16384) @srpc() def test_empty(): pass @srpc(String, Integer, DateTime) def multi_param(s, i, dt): pass @srpc(NonNillableClass, _returns=String) def non_nillable(n): return "OK" @srpc(String, _returns=String, _public_name="do_something") def do_something_else(s): return s @srpc(Integer, _returns=Array(OtherClass)) def return_other_class_array(num): for i in range(num): yield OtherClass(dt=datetime(2010, 12, 6), d=3.0, b=True) @srpc(_returns=Attachment) def return_binary_data(): return Attachment(data=''.join([chr(i) for i in range(256)])) @srpc(_returns=Integer) def return_invalid_data(): return 'a' @srpc(String, _public_name="urn:#getCustomMessages", _in_message="getCustomMessagesMsgIn", _out_message="getCustomMessagesMsgOut", _out_variable_name="CustomMessages", _returns=String) def custom_messages(s): return s
def test_array_empty(self): type = Array(String) type.resolve_namespace(type, "zbank") values = [] element = etree.Element('test') XmlObject().to_parent_element(type, values, ns_test, element) element = element[0] self.assertEquals(len(values), len(element.getchildren())) values2 = XmlObject().from_element(type, element) self.assertEquals(len(values2), 0)
class EntityAPIService(SoapListener.BasicSoapServer): """Function definitions for the service.""" __namespace__ = NAMESPACE __tns__ = NAMESPACE # Require the session ID in the client's header __in_header__ = SoapListener.SessionHeader # Respond with a header with the current session ID __out_header__ = SoapListener.SessionHeader # The class where the Cerebrum-specific functionality is done. This is # instantiated per call, to avoid thread conflicts. cere_class = None # The hook for the site object site = None @rpc(String, String, _throws=faults.EndUserFault, _returns=Array(String)) def spread_list(ctx, id_type, entity_id): return ctx.udc[NAMESPACE].spread_list(id_type, entity_id) @rpc(String, String, String, _throws=faults.EndUserFault, _returns=Boolean) def in_system(ctx, id_type, entity_id, system): return ctx.udc[NAMESPACE].in_system(id_type, entity_id, system) @rpc(String, String, String, _throws=faults.EndUserFault, _returns=Boolean) def active_in_system(ctx, id_type, entity_id, system): return ctx.udc[NAMESPACE].active_in_system(id_type, entity_id, system) @rpc(String, String, String, _throws=faults.EndUserFault) def add_to_system(ctx, id_type, entity_id, system): return ctx.udc[NAMESPACE].add_to_system(id_type, entity_id, system)
class UserManager(ServiceBase): @srpc(User, _returns=Integer) def add_user(user): global user_database global userid_seq user.userid = userid_seq userid_seq = userid_seq + 1 user_database[user.userid] = user return user.userid @srpc(Integer, _returns=User) def get_user(userid): global user_database return user_database[userid] @srpc(User) def modify_user(user): global user_database user_database[user.userid] = user @srpc(Integer) def delete_user(userid): global user_database del user_database[userid] @srpc(_returns=Array(User)) def list_users(): global user_database return user_database.values()
class User(ComplexModel): __namespace__ = "user" userid = Integer username = String firstname = String lastname = String permissions = Array(Permission)
class HelloWorldService(ServiceBase): @srpc(String, Integer, _returns=Array(String)) def say_hello(name, times): results = [] for i in range(0, times): results.append('Hello, %s' % name) return results
class User(ComplexModel): __namespace__ = 'rpclib.examples.user_manager' user_id = Integer user_name = String first_name = String last_name = String email = String(pattern=r'[a-z0-9._%+-]+@[a-z0-9.-]+\.[A-Z]{2,4}') permissions = Array(Permission)
class InteropClass(ServiceBase): @srpc(SimpleClass, _returns=SimpleClass) def echo_simple_class(sc): return sc @srpc(Array(SimpleClass), _returns=Array(SimpleClass)) def echo_simple_class_array(sca): return sca @srpc(NestedClass, _returns=NestedClass) def echo_nested_class(nc): return nc @srpc(Array(NestedClass), _returns=Array(NestedClass)) def echo_nested_class_array(nca): return nca @srpc(ExtensionClass, _returns=ExtensionClass) def echo_extension_class(nc): return nc @srpc(ClassWithSelfReference, _returns=ClassWithSelfReference) def echo_class_with_self_reference(sr): return sr @srpc(Attachment, _returns=Attachment) def echo_attachment(a): assert isinstance(a, Attachment) return a @srpc(Array(Attachment), _returns=Array(Attachment)) def echo_attachment_array(aa): return aa
class Service(ServiceBase): @rpc(String(max_occurs='unbounded'), _returns=Array(KeyValuePair), _in_variable_names={ 'keys': 'key' } ) def get_values(ctx, keys): session = self.Session() return session.query(KeyValuePair).filter(sql.and_( KeyValuePair.key.in_(keys) )).order_by(KeyValuePair.key)
class HelloWorldService(ServiceBase): @srpc(String, Integer, _returns=Array(String)) def say_hello(name, times): '''Docstrings for service methods appear as documentation in the wsdl. @param name the name to say hello to @param the number of times to say hello @return the completed array ''' results = [] for i in range(0, times): results.append('Hello, %s' % name) return results
def test_class_array(self): peeps = [] names = ['bob', 'jim', 'peabody', 'mumblesleves'] for name in names: a = Person() a.name = name a.birthdate = datetime.datetime(1979, 1, 1) a.age = 27 peeps.append(a) type = Array(Person) type.resolve_namespace(type, __name__) element = etree.Element('test') XmlObject().to_parent_element(type, peeps, ns_test, element) element = element[0] self.assertEquals(4, len(element.getchildren())) peeps2 = XmlObject().from_element(type, element) for i in range(0, 4): self.assertEquals(peeps2[i].name, names[i]) self.assertEquals(peeps2[i].birthdate, datetime.datetime(1979, 1, 1))
def test_late_mapping(self): import sqlalchemy user_t = Table('user', self.metadata, Column('id', sqlalchemy.Integer, primary_key=True), Column('name', sqlalchemy.String), ) class User(TableSerializer, self.DeclarativeBase): __table__ = user_t self.assertEquals(User._type_info['id'].__type_name__, 'integer') self.assertEquals(User._type_info['name'].__type_name__, 'string') Array(User)
def test_array(self): type = Array(String) type.resolve_namespace(type,"zbank") values = ['a', 'b', 'c', 'd', 'e', 'f'] element = etree.Element('test') type.to_parent_element(values, ns_test, element) element = element[0] self.assertEquals(len(values), len(element.getchildren())) values2 = type.from_xml(element) self.assertEquals(values[3], values2[3])
class Person(ComplexModel): name = String birthdate = DateTime age = Integer addresses = Array(Address) titles = Array(String)
class Level1(ComplexModel): level2 = Level2 level3 = Array(Level3) level4 = Array(Level4)
class GroupAPIService(SoapListener.BasicSoapServer): """Function definitions for the service.""" __namespace__ = NAMESPACE __tns__ = NAMESPACE # Require the session ID in the client's header __in_header__ = SoapListener.SessionHeader # Respond with a header with the current session ID __out_header__ = SoapListener.SessionHeader # The class where the Cerebrum-specific functionality is done. This is # instantiated per call, to avoid thread conflicts. cere_class = None # The hook for the site object site = None @rpc(String, String, DateTime, String, _throws=faults.EndUserFault, _returns=Integer) def group_create(ctx, group_name, description, expire_date=None, visibility=None): return ctx.udc[NAMESPACE].group_create(group_name, description, expire_date, visibility) @rpc(String, String, String, String, _throws=faults.EndUserFault, _returns=Boolean) def group_add_member(ctx, group_id_type, group_id, member_id_type, member_id): return ctx.udc[NAMESPACE].group_add_member(group_id_type, group_id, member_id_type, member_id) @rpc(String, String, String, String, _throws=faults.EndUserFault, _returns=Boolean) def group_remove_member(ctx, group_id_type, group_id, member_id_type, member_id): return ctx.udc[NAMESPACE].group_remove_member(group_id_type, group_id, member_id_type, member_id) @rpc(String, String, _throws=faults.EndUserFault, _returns=GroupInfo) def group_info(ctx, group_id_type, group_id): return ctx.udc[NAMESPACE].group_info(group_id_type, group_id) @rpc(String, String, _throws=faults.EndUserFault, _returns=Array(GroupMember)) def group_list(ctx, group_id_type, group_id): return ctx.udc[NAMESPACE].group_list(group_id_type, group_id) @rpc(String, String, DateTime, _throws=faults.EndUserFault) def group_set_expire(ctx, group_id_type, group_id, expire_date=None): return ctx.udc[NAMESPACE].group_set_expire(group_id_type, group_id, expire_date)
class InteropArray(ServiceBase): @srpc(Array(Integer), _returns=Array(Integer)) def echo_integer_array(ia): return ia @srpc(Array(String), _returns=Array(String)) def echo_string_array(sa): return sa @srpc(Array(DateTime), _returns=Array(DateTime)) def echo_date_time_array(dta): return dta @srpc(Array(Float), _returns=Array(Float)) def echo_float_array(fa): return fa @srpc(Array(Double), _returns=Array(Double)) def echo_double_array(da): return da @srpc(Array(Boolean), _returns=Array(Boolean)) def echo_boolean_array(ba): return ba @srpc(Boolean(max_occurs="unbounded"), _returns=Boolean(max_occurs="unbounded")) def echo_simple_boolean_array(ba): return ba @srpc(Array(Boolean), _returns=Array(Array(Boolean))) def echo_array_in_array(baa): return baa