Beispiel #1
0
 def setUp(self):
     self.pb = ProtocolBuffer("service_test")
     simple_msg = genMsg("Simple", models.Simple)
     self.pb.addMessage(simple_msg)
     self.service_port = 4567
     
     def SimpleHandler(service_impl, controller, request, done):
         request.val += 1
         done.run(request)
     
     def SimpleHandler2(service_impl, controller, request, done):
         '''Docstring from Handler2'''
         request.val += 5
         done.run(request)
         
     self.pb.addRpc('SimpleService', 'TestRpc', simple_msg,
                                simple_msg, SimpleHandler,
                                'A line of documentation')
     self.pb.addRpc('SimpleService', 'TestRpc2', simple_msg,
                                simple_msg, SimpleHandler2)
     self.pb.addRpc('SimpleService2', 'TestRpc', simple_msg,
                                simple_msg, SimpleHandler)
     mod_name = pbandj.genMod(self.pb)
     global proto
     proto = __import__(mod_name)
     if not ServiceTestCase.services_started:
         sThread = ProtocolBuffer.ServiceThread(proto, self.service_port, True,
                                                 self.pb.services['SimpleService'],
                                                 self.pb.services['SimpleService2'])
         #self.pb.services['SimpleService'].start(proto, self.service_port, True)
         #self.pb.services['SimpleService2'].start(proto, self.service_port + 1, True)
         sThread.start()
         ServiceTestCase.services_started = True
Beispiel #2
0
 def setUp(self):
     self.module_name = "simple_test"
     self.pb = ProtocolBuffer(self.module_name)
     self.simple = genMsg('SimpleRename', models.Simple)
     self.pb.addMessage(self.simple)
     mod_name = pbandj.genMod(self.pb)
     global proto
     proto = __import__(mod_name)
     self.con = Converter()
Beispiel #3
0
 def test_genMod(self):
     '''Test that the generated mod name is correct and the module is 
        importable
     '''
     mod_name = pbandj.genMod(self.pb)
     self.assertEqual(mod_name, self.module_name + "_pb2",
                      "Module name does not match name passed in to ProtocolBuffer() constructor")
     try:
         proto = __import__(mod_name)
     except ImportError, ie:
         self.assert_(False,
                  "Failed to import generated python module")
Beispiel #4
0
 def setUp(self):
     self.module_name = "ooe_test"
     self.pb = ProtocolBuffer(self.module_name)
     self.ooe = genMsg('OneOfEverything',
                                     models.OneOfEverything)
     self.pb.addMessage(self.ooe)
     
     self.django_class_fields = [field for field in 
                            models.OneOfEverything._meta.local_fields]
     self.pb_field_names = [f.name for f in self.ooe.mapped_fields]
     mod_name = pbandj.genMod(self.pb)
     global proto
     proto = __import__(mod_name)
     
     ooe = proto.OneOfEverything()
     ooe.bool_test = True
     ooe.char_test = "ABC123"
     ooe.comma_test = "A,B,C"
     ooe.date_test.year = 1980
     ooe.date_test.month = 6
     ooe.date_test.day = 10
     ooe.date_time_test.year = 1989
     ooe.date_time_test.month = 9
     ooe.date_time_test.day = 19
     ooe.date_time_test.time.hour = 1
     ooe.date_time_test.time.minute = 2
     ooe.date_time_test.time.second = 3
     ooe.decimal_test = 12.34
     ooe.float_test = 56.789
     ooe.email_test = '*****@*****.**'
     ooe.file_test = "path/to/file"
     ooe.image_test = "/path/to/image"
     ooe.int_test = -1
     ooe.ip_test = '123.456.789.123'
     ooe.null_bool_test = False
     ooe.pos_int_test = 1
     ooe.pos_sm_int_test = 1
     ooe.slug_test = 'This is a slug'
     ooe.sm_int_test = -1
     ooe.text_test = 'This is some text'
     ooe.time_test.hour = 12
     ooe.time_test.minute = 13
     ooe.time_test.second = 14
     ooe.url_test = 'http://www.lcogt.net'
     ooe.xml_test = '<abc>123</abc>'
     self.ooe = ooe
     self.converter = Converter()
Beispiel #5
0
 def setUp(self):
     self.module_name = "fk_test"
     self.pb = ProtocolBuffer(self.module_name)
     self.fkt = genMsg('ForeignKeyTest',
                                     models.ForeignKeyTest)
     self.pb.addMessage(self.fkt)
     
     self.django_class_fields = [field for field in 
                            models.ForeignKeyTest._meta.local_fields]
     self.pb_fields_by_name = dict([(f.name, f) for f in self.fkt.mapped_fields])
     mod_name = pbandj.genMod(self.pb)
     global proto
     proto = __import__(mod_name)
     self.simple = models.Simple()
     self.simple.val = 1234
     self.simple.save()
     self.con = Converter()
Beispiel #6
0
 def setUp(self):
     self.module_name = "enum_test"
     self.pb = ProtocolBuffer(self.module_name)
     self.emsg= genMsg('EnumTest',
                                     models.EnumTest)
     self.pb.addMessage(self.emsg)
     self.django_class_fields = [field for field in 
                            models.EnumTest._meta.local_fields]
     self.pb_field_names = [f.name for f in self.emsg.mapped_fields]
     mod_name = pbandj.genMod(self.pb)
     global proto
     proto = __import__(mod_name)
     emsg = proto.EnumTest()
     emsg.enum_test = proto.EnumTest.ENUM_TEST_VAL1
     self.emsg = emsg
     self.converter = Converter()
     
     enum_db = models.EnumTest(enum_test='Val1')
     enum_db.save()
     self.enum_db = enum_db
Beispiel #7
0
 def setUp(self):
     self.module_name = "m2m_test"
     self.pb = ProtocolBuffer(self.module_name)
     self.m2m = genMsg('ManyToManyTest',
                                     models.ManyToManyTest)
     self.pb.addMessage(self.m2m)
     
     self.django_class_fields = [field for field in 
                            models.ManyToManyTest._meta.local_fields +
                            models.ManyToManyTest._meta.many_to_many]
     self.pb_fields_by_name = dict([(f.name, f) for f in self.m2m.mapped_fields])
     mod_name = pbandj.genMod(self.pb)
     global proto
     proto = __import__(mod_name)
     self.simple1 = models.Simple()
     self.simple1.val = 1234
     self.simple1.save()
     self.simple2 = models.Simple()
     self.simple2.val = 5678
     self.simple2.save()
     self.con = Converter()
Beispiel #8
0
 def setUp(self):
     self.module_name = "m2m_through_test_no_recurse"
     self.pb = ProtocolBuffer(self.module_name)
     self.m2m = genMsg('ManyToManyThroughTest',
                                     models.ManyToManyThroughTest, recurse_fk=False)
     self.pb.addMessage(self.m2m)
     
     self.django_class_fields = [field for field in 
                            models.ManyToManyThroughTest._meta.local_fields +
                            models.ManyToManyThroughTest._meta.many_to_many]
     
     self.django_assoc_class_fields = [field for field in 
                            models.M2MAssocTest._meta.local_fields +
                            models.M2MAssocTest._meta.many_to_many]
     
     self.pb_fields_by_name = dict([(f.name, f) for f in self.m2m.mapped_fields])
     self.pb_assoc_fields_by_name = dict([(f.name, f) for f in self.pb_fields_by_name['m2m_test'].pb_type.mapped_fields])
     mod_name = pbandj.genMod(self.pb)
     global proto
     proto = __import__(mod_name)
     self.simple = models.Simple()
     self.simple.val = 1234
     self.simple.save()
     self.con = Converter()
Beispiel #9
0
#
'''test_pbandj.py - Unittests for pbandj

Authors: Zach Walker ([email protected])
Dec 2009
'''
import unittest
import os
from datetime import datetime

# Set the enviroment variable Django looks at to find db settings
from django.conf import ENVIRONMENT_VARIABLE
os.environ[ENVIRONMENT_VARIABLE] = 'django_test.settings'

from pbandj.pbandj import genMod, DJANGO_PROTO
genMod(DJANGO_PROTO)

from django.db import models as django_models
from pbandj.model import ProtocolBuffer
from pbandj.type_map import DJ2PB, genMsg
from pbandj.conversion import Converter
from pbandj import pbandj
from django_test.test_app import models
from protobuf.socketrpc import RpcService


class MessageRenameTestCase(unittest.TestCase):
    '''Test mapping when message name does not match
    django type name
    '''
    global proto
Beispiel #10
0
#!python

import os
from django.conf import ENVIRONMENT_VARIABLE
os.environ[ENVIRONMENT_VARIABLE] = 'settings'
from pbandj import pbandj
#from django.core.management import setup_environ
#try:
#    import settings # Assumed to be in the same directory.
#    
#except ImportError:
#    import sys
#    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
#    sys.exit(1)



if __name__ == "__main__":
    #setup_environ(settings)
    from addressbook import models
    proto = models.genProto()
    pbandj.genMod(proto)   
Beispiel #11
0
#!/usr/bin/python

# Set the enviroment variable Django looks at to find db settings
import os
from django.conf import ENVIRONMENT_VARIABLE
os.environ[ENVIRONMENT_VARIABLE] = 'settings'
#from django.core.management import setup_environ
#try:
#    import settings # Assumed to be in the same directory.
#
#except ImportError:
#    import sys
#    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
#    sys.exit(1)

from pbandj import pbandj

if __name__ == "__main__":
    #setup_environ(settings)
    from addressbook import models
    proto = models.genProto()
    pbandj.genMod(pbandj.DJANGO_PROTO)
    mod = __import__(proto.python_mod_name())
    port = 8091
    for service in proto.services:
        proto.services[service].start(mod, port)
        port += 1
Beispiel #12
0
#!/usr/bin/python

# Set the enviroment variable Django looks at to find db settings
import os
from django.conf import ENVIRONMENT_VARIABLE
os.environ[ENVIRONMENT_VARIABLE] = 'settings'
#from django.core.management import setup_environ
#try:
#    import settings # Assumed to be in the same directory.
#    
#except ImportError:
#    import sys
#    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
#    sys.exit(1)


from pbandj import pbandj

if __name__ == "__main__":
    #setup_environ(settings)
    from addressbook import models
    proto = models.genProto()
    pbandj.genMod(pbandj.DJANGO_PROTO)
    mod = __import__(proto.python_mod_name())
    port = 8091
    for service in proto.services:
        proto.services[service].start(mod, port)
        port += 1
Beispiel #13
0
#!python

import os
from django.conf import ENVIRONMENT_VARIABLE
os.environ[ENVIRONMENT_VARIABLE] = 'settings'
from pbandj import pbandj
#from django.core.management import setup_environ
#try:
#    import settings # Assumed to be in the same directory.
#
#except ImportError:
#    import sys
#    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
#    sys.exit(1)

if __name__ == "__main__":
    #setup_environ(settings)
    from addressbook import models
    proto = models.genProto()
    pbandj.genMod(proto)