def testIoCGeneralQueryWithSimpleRowMapper(self): appContext = ApplicationContext(XMLConfig("support/databaseTestMySQLApplicationContext.xml")) factory = appContext.get_object("connection_factory") databaseTemplate = DatabaseTemplate(factory) results = databaseTemplate.query("select * from animal", rowhandler=SimpleRowMapper(testSupportClasses.Person))
def urlfrontier_set_up(self): self.frontier_ctx = ApplicationContext(TestableURLFrontierContext()) self.dao_ctx = ApplicationContext(TestableDAOContext())
def setUp(self): print "New DatabaseInteractionTest running" self.contact = Contact(first_name="Jordan", last_name="Degner", email="*****@*****.**") self.organization = Organization( name="Yee University", organization_url="http://com.bee.yee", contacts=[self.contact], email_key="*****@*****.**", emails=["*****@*****.**", "*****@*****.**"], phone_numbers=[5555555555, "(555)555-5555"], facebook="http://www.facebook.com/yee", twitter="http://www.twitter.com/yee", address="5124 Yeesy Street Omaha, NE 68024", keywords="intj enfp entp isfp enfj istj", types=[ OrgTypesEnum.RELIGIOUS, OrgTypesEnum.GOVERNMENT, OrgTypesEnum.PROSECUTION, ], page_rank_info=PageRankInfoDTO( total_with_self=10, total=10, references=[ PageRankVectorDTO(org_domain='yoyodyne.com', count=2, pages=[ UrlCountPairDTO( url='http://www.yoyodyne.com/', count=2) ]), PageRankVectorDTO( org_domain='trystero.org', count=4, pages=[ UrlCountPairDTO(url='http://www.yoyodyne.com/', count=3), UrlCountPairDTO( url='http://www.yoyodyne.com/contacts.php', count=1) ]), PageRankVectorDTO(org_domain='thurnandtaxis.info', count=4, pages=[ UrlCountPairDTO( url='http://www.yoyodyne.com/', count=4) ]) ])) self.publication = Publication( title="The Book of Yee", authors="Sam Adams, {0} {1}".format(self.contact.first_name, self.contact.last_name), publisher="{0} {1}".format(self.contact.first_name, self.contact.last_name)) self.urlmetadata = URLMetadata(url="http://google.com") self.user = User(first_name="Bee", last_name="Yee", email="*****@*****.**", password="******", background="I love bees and yees", account_type=AccountType.COLLABORATOR) self.ctx = ApplicationContext(TestableDAOContext())
class MySampleServiceAppContext(PythonConfig): def __init__(self): PythonConfig.__init__(self) @Object def mySampleService(self): return MySampleService() @Object def mySampleServiceExporter(self): return PyroServiceExporter(self.mySampleService(), "service", "localhost", 7000) if __name__ == "__main__": import logging from springpython.context import ApplicationContext logger = logging.getLogger("springpython") loggingLevel = logging.DEBUG logger.setLevel(loggingLevel) ch = logging.StreamHandler() ch.setLevel(loggingLevel) formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) print "Starting up context that exposese reported issue..." ctx = ApplicationContext(MySampleServiceAppContext())
if __name__ == '__main__': """This allows the script to be run as a tiny webserver, allowing quick testing and development. For more scalable performance, integration with Apache web server would be a good choice.""" logger = logging.getLogger("springpython") loggingLevel = logging.DEBUG logger.setLevel(loggingLevel) ch = logging.StreamHandler() ch.setLevel(loggingLevel) formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) applicationContext = ApplicationContext( XMLConfig(config_location="applicationContext.xml")) filterChainProxy = applicationContext.get_object("filterChainProxy") SecurityContextHolder.setStrategy(SecurityContextHolder.MODE_GLOBAL) SecurityContextHolder.getContext() conf = { "/": { "tools.staticdir.root": os.getcwd(), 'tools.sessions.on': True, "tools.filterChainProxy.on": True }, "/images": { "tools.staticdir.on": True, "tools.staticdir.dir": "images" },
def setUp(self): SecurityContextHolder.setContext(SecurityContext()) self.appContext = ApplicationContext(XMLConfig("support/providerApplicationContext.xml")) self.auth_manager = self.appContext.get_object("inMemoryDaoAuthenticationManager")
def setUp(self): SecurityContextHolder.setContext(SecurityContext()) self.appContext = ApplicationContext(XMLConfig("support/providerApplicationContext.xml")) self.auth_manager = self.appContext.get_object("dao_mgr_hiding_exception") self.mock = self.mock() self.appContext.get_object("dataSource").stubConnection.mockCursor = self.mock
def org_partner_map(request): """ Generates the data needed to display the organization partner map and then stores it in the cache. Data returned as a JSON string. Returns: Partner map configurations encoded in JSON. """ if request.method != 'GET': return HttpResponseNotAllowed(request) pmap = cache.get('partner_map') last_update = cache.get('partner_map_last_update') if not pmap or not last_update or (datetime.utcnow() - last_update > REFRESH_PARTNER_MAP): new_pmap = { "nodes": [], "links": [], "types": { 'ADVOCACY': OrgTypesEnum.ADVOCACY, 'EDUCATION': OrgTypesEnum.EDUCATION, 'GOVERNMENT': OrgTypesEnum.GOVERNMENT, 'NGO': OrgTypesEnum.NGO, "PREVENTION": OrgTypesEnum.PREVENTION, "PROTECTION": OrgTypesEnum.PROTECTION, "PROSECUTION": OrgTypesEnum.PROSECUTION, 'RELIGIOUS': OrgTypesEnum.RELIGIOUS, 'RESEARCH': OrgTypesEnum.RESEARCH, 'UNKNOWN': OrgTypesEnum.UNKNOWN } } cache.set('partner_map_last_update', datetime.utcnow()) ctx = ApplicationContext(DAOContext()) org_dao = ctx.get_object('OrganizationDAO') try: organizations = org_dao.all('name', 'id', 'partners', 'types', 'address') except: logger.error('Error fetching organizations') return HttpResponseServerError(request) i = 0 for org in organizations: new_pmap["nodes"].append({ "name": org.name, "id": str(org.id), "types": org.types, "addr": org.address }) for part in org.partners: partner_id = str(part.id) for j in xrange(0, i): if new_pmap["nodes"][j]["id"] == partner_id: new_pmap["links"].append({"source": i, "target": j}) i += 1 pmap = MongoJSONEncoder().encode(new_pmap) cache.set('partner_map', pmap) return HttpResponse(pmap, content_type="application/json")
def setUp(self): print "New ItemPipelineTest running" self.org = ScrapedOrganization( name="Yoyodyne", address="1234 Yoyodyne Way, San Narciso, CA", types=[OrgTypesEnum.GOVERNMENT, OrgTypesEnum.RESEARCH], phone_numbers=["4026170423"], emails=["*****@*****.**"], contacts=[], organization_url="www.yoyodyne.com", partners=[ { 'organization_url': 'http://www.acumenfund.org/' }, { 'organization_url': 'http://www.afghaninstituteoflearning.org/' }, { 'organization_url': 'http://www.prajwalaindia.com/' }, { 'organization_url': 'http://www.mencanstoprape.org/' }, { 'organization_url': 'http://novofoundation.org/' }, ], page_rank_info={ "total_with_self": 10, "total": 10, "references": [{ "org_domain": 'yoyodyne.com', "count": 2, "pages": [{ "url": 'http://www.yoyodyne.com/', "count": 2 }] }, { "org_domain": 'trystero.org', "count": 4, "pages": [{ "url": 'http://www.yoyodyne.com/', "count": 3 }, { "url": 'http://www.yoyodyne.com/contacts.php', "count": 1 }] }, { "org_domain": 'thurnandtaxis.info', "count": 4, "pages": [{ "url": 'http://www.yoyodyne.com/', "count": 4 }] }] }) self.contact = ScrapedContact(first_name="Djordan", last_name="Jdegner", phones=['5555555555'], email='*****@*****.**', organization={'name': 'Yoyodyne'}, position='Software Jdeveloper') self.ctx = ApplicationContext(TestablePipelineContext())
def before_all(context): configuration = XMLConfig("resources/spring/application-context.xml") context.container = ApplicationContext(configuration)
import json from datetime import datetime, timedelta from django.core.cache import cache from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseServerError from springpython.context import ApplicationContext # project imports from HTResearch.DataModel.enums import OrgTypesEnum from HTResearch.Utilities.context import DAOContext from HTResearch.Utilities.logutil import LoggingSection, get_logger from HTResearch.Utilities.encoder import MongoJSONEncoder from HTResearch.Utilities import decorators #region Globals logger = get_logger(LoggingSection.CLIENT, __name__) ctx = ApplicationContext(DAOContext()) REFRESH_COORDS_LIST = timedelta(minutes=5) REFRESH_PARTNER_MAP = timedelta(minutes=20) REFRESH_ORG_BREAKDOWN = timedelta(minutes=20) REFRESH_COUNT = timedelta(minutes=20) #endregion @decorators.safe_apicall def heatmap_coordinates(request): """ Gets all the lat/long values for all organizations. Returns: List of lat/long coordinates encoded in JSON. """
def prepare_config(target_dir, is_https): app_ctx = ApplicationContext(app_context.SecWallContext()) start = Start(target_dir, app_ctx, is_https) start.prepare_config()
if __name__ == "__main__": # Turn on some logging in order to see what is happening behind the scenes... logger = logging.getLogger("dataValidator") loggingLevel = logging.DEBUG logger.setLevel(loggingLevel) #ch = logging.StreamHandler() ch = logging.FileHandler("dataValidator.log", mode='a') ch.setLevel(loggingLevel) formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) path = os.path.dirname(__file__) appContext = ApplicationContext(XMLConfig(path + "/dataValidator.xml")) connection = appContext.get_object("mqConnection") try: # Open the channel channel = connection.channel() # Declare the exchange exchange = channel.exchange_declare(exchange='rawdata', type='fanout', passive=False, durable=True, auto_delete=False, internal=False, nowait=False, arguments={})
def init_context(): """ Initialize spring context in order to parse arguments """ return ApplicationContext(ArgumentParserContext())
def setUp(self): self.app_ctx = ApplicationContext(app_context.SecWallContext()) self.test_dir = tempfile.mkdtemp(prefix='tmp-sec-wall-')
def setUp(self): self.app_ctx = ApplicationContext(app_context.SecWallContext()) self.test_dir = tempfile.mkdtemp(prefix=self.temp_dir_prefix) open(os.path.join(self.test_dir, '.sec-wall-config'), 'w') open(os.path.join(self.test_dir, 'config.py'), 'w') open(os.path.join(self.test_dir, 'zdaemon.conf'), 'w')