Esempio n. 1
0
 def setUp(self):
     dao = TestDao()
     self.wof_inst = WOF(dao, TEST_CONFIG_FILE)
     waterml_schema_path = os.path.join(os.path.dirname(__file__),
                                        'cuahsiTimeSeries_v1_0.xsd')
     waterml_schema_doc = etree.parse(waterml_schema_path)
     self.waterml_schema = etree.XMLSchema(waterml_schema_doc)
Esempio n. 2
0
 def setUp(self):
     dao = TestDao()
     self.wof_inst = WOF(dao, TEST_CONFIG_FILE)
     waterml_schema_path = os.path.join(os.path.dirname(__file__),
                                     'cuahsiTimeSeries_v1_0.xsd')
     waterml_schema_doc = etree.parse(waterml_schema_path)
     self.waterml_schema = etree.XMLSchema(waterml_schema_doc)
Esempio n. 3
0
    def setUp(self):
        dao = TestDao()
        testConfig = os.path.join(os.path.dirname(__file__), TEST_CONFIG_FILE)
        self.wof_inst = WOF(dao, testConfig)

        if not os.path.exists(
                os.path.join(os.path.abspath(os.path.curdir),
                             'watermlcvs.json')):
            wof.vocabularies.update_watermlcvs()

        waterml_schema_path = os.path.join(os.path.dirname(__file__),
                                           'cuahsiTimeSeries_v1_1.xsd')
        waterml_schema_doc = etree.parse(waterml_schema_path)
        self.waterml_schema = etree.XMLSchema(waterml_schema_doc)
Esempio n. 4
0
database_connection_string = 'mssql+pyodbc://odm_user2:water123@JAMTAY-PC\SQLEXPRESS/LittleBear11'

2.  Example for SQLite

swis_connection_string = 'sqlite:///C:/PythonSandbox/WOFpy_Sandbox/WOFpy/examples/swis/swis2.db'

You can use relative paths too, e.g. if you are calling the above database from the same directory, 
the connection string can just be:

swis_connection_string = 'sqlite:///swis2.db' 
'''

LCM_connection_string = 'sqlite:///LCM_Data/LCM.db'

dao = LCMDao(LCM_connection_string,'LCM_config.cfg')
LCM_wof = WOF(dao)
LCM_wof.config_from_file('LCM_config.cfg')

app = create_app(LCM_wof)
app.config.from_object(config.DevConfig)

ODMWOFService = create_wof_service_class(LCM_wof)

soap_app = soaplib.core.Application(services=[ODMWOFService],
                                    tns='http://www.cuahsi.org/his/1.0/ws/',
                                    name='WaterOneFlow')

soap_wsgi_app = soaplib.core.server.wsgi.Application(soap_app)

app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
     '/soap/wateroneflow': soap_wsgi_app,   
Esempio n. 5
0
from wof import WOF
from wof.soap import create_wof_service_class
from wof.flask import config, create_app

from examples.swis.swis_dao import SwisDao
from examples.barebones.LCM_dao import LCMDao

logging.basicConfig(level=logging.DEBUG)

swis_dao = SwisDao('swis/swis_config.cfg',
                   database_uri='sqlite:///swis/swis2.db')
lcm_dao = LCMDao('sqlite:///barebones/LCM_Data/LCM.db',
                 'barebones/LCM_config.cfg')

swis_wof = WOF(swis_dao)
swis_wof.config_from_file('swis/swis_config.cfg')

lcm_wof = WOF(lcm_dao)
lcm_wof.config_from_file('barebones/LCM_config.cfg')
#Create the Flask applications
swis_flask_app = create_app(swis_wof)
lcm_flask_app = create_app(lcm_wof)

#Create the soaplib classes
SWISWOFService = create_wof_service_class(swis_wof)
LCMWOFService = create_wof_service_class(lcm_wof)

#Create the soaplib applications
swis_soap_app = soaplib.core.Application(services=[SWISWOFService],
    tns='http://www.cuahsi.org/his/1.0/ws/',
Esempio n. 6
0
class TestWOF(unittest.TestCase):
    """
    Tests wof response generation methods for validation against
    the WaterML 1.0 schema.
    """
    def setUp(self):
        dao = TestDao()
        self.wof_inst = WOF(dao, TEST_CONFIG_FILE)
        waterml_schema_path = os.path.join(os.path.dirname(__file__),
                                           'cuahsiTimeSeries_v1_0.xsd')
        waterml_schema_doc = etree.parse(waterml_schema_path)
        self.waterml_schema = etree.XMLSchema(waterml_schema_doc)

    def response_to_StringIO(self, response, root_name):
        """
        Converts WOF method response to StringIO object.
        """
        response_output = StringIO.StringIO()
        response.export(response_output,
                        0,
                        name_=root_name,
                        namespacedef_=NSDEF)
        response_output.seek(0)
        return response_output

    def save_response(self, response, filename, root_name):
        f = open(filename, 'w')
        response.export(f, 0, name_=root_name, namespacedef_=NSDEF)
        f.close()

    def compare_output_to_known_xml(self, response_stringIO,
                                    known_xml_filename):
        """
        Make sure response output is as expected. This tests that a
        response contains the same XML as in the known XML file.
        """
        known_file_path = os.path.join(os.path.dirname(__file__), TEST_XML_DIR,
                                       known_xml_filename)
        # Use objectify and etree to remove whitespace from XML for comparison
        response_tree = objectify.parse(response_stringIO)
        known_tree = objectify.parse(known_file_path)
        response_string = etree.tostring(response_tree)
        known_string = etree.tostring(known_tree)
        assert response_string == known_string

    def test_get_all_sites(self):
        response = self.wof_inst.create_get_site_response()
        response_string = self.response_to_StringIO(response, 'sitesResponse')
        self.compare_output_to_known_xml(response_string, 'get_all_sites.xml')

    def test_get_one_site(self):
        response = self.wof_inst.create_get_site_response('TEST:SITE_A')
        response_string = self.response_to_StringIO(response, 'sitesResponse')
        self.compare_output_to_known_xml(response_string, 'get_one_site.xml')

    def test_get_multiple_sites(self):
        response = self.wof_inst.create_get_site_response(
            'TEST:SITE_A,TEST:SITE_B')
        response_string = self.response_to_StringIO(response, 'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_multiple_sites.xml')

    def test_get_all_variables(self):
        response = self.wof_inst.create_get_variable_info_response()
        response_string = self.response_to_StringIO(response,
                                                    'variablesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_all_variables.xml')

    def test_get_one_variable(self):
        response = self.wof_inst.create_get_variable_info_response(
            'TESTVocab:Temp')
        response_string = self.response_to_StringIO(response,
                                                    'variablesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_one_variable.xml')

    def test_get_multiple_variables(self):
        response = self.wof_inst.create_get_variable_info_response(
            'TESTVocab:Flow,TESTVocab:TP')
        response_string = self.response_to_StringIO(response,
                                                    'variablesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_multiple_variables.xml')

    def test_get_site_info_novar(self):
        response = self.wof_inst.create_get_site_info_response('TEST:SITE_A')
        response_string = self.response_to_StringIO(response, 'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_siteinfo_novar.xml')

    def test_get_site_info_withvar(self):
        response = self.wof_inst.create_get_site_info_response(
            'TEST:SITE_B', 'TESTVocab:TP')
        response_string = self.response_to_StringIO(response, 'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_siteinfo_withvar.xml')

    def test_get_values_encloses_por(self):
        response = self.wof_inst.create_get_values_response(
            'TEST:SITE_A',
            'TESTVocab:Temp',
            startDateTime='2007-03-05 00:00',
            endDateTime='2007-05-06 00:00')
        response_string = self.response_to_StringIO(response,
                                                    'timeSeriesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_values_encloses_por.xml')
Esempio n. 7
0
database_connection_string = 'mssql+pyodbc://odm_user2:water123@JAMTAY-PC\SQLEXPRESS/LittleBear11'

2.  Example for SQLite

swis_connection_string = 'sqlite:///C:/PythonSandbox/WOFpy_Sandbox/WOFpy/examples/swis/swis2.db'

You can use relative paths too, e.g. if you are calling the above database from the same directory, 
the connection string can just be:

swis_connection_string = 'sqlite:///swis2.db' 
'''

LCM_connection_string = 'sqlite:///LCM_Data/LCM.db'

dao = LCMDao(LCM_connection_string, 'LCM_config.cfg')
LCM_wof = WOF(dao)
LCM_wof.config_from_file('LCM_config.cfg')

app = create_app(LCM_wof)
app.config.from_object(config.DevConfig)

ODMWOFService = create_wof_service_class(LCM_wof)

soap_app = soaplib.core.Application(services=[ODMWOFService],
                                    tns='http://www.cuahsi.org/his/1.0/ws/',
                                    name='WaterOneFlow')

soap_wsgi_app = soaplib.core.server.wsgi.Application(soap_app)

app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
    '/soap/wateroneflow': soap_wsgi_app,
Esempio n. 8
0
from wof import WOF
from wof.soap import create_wof_service_class
from wof.flask import config, create_app

from examples.swis.swis_dao import SwisDao
from examples.barebones.LCM_dao import LCMDao

logging.basicConfig(level=logging.DEBUG)

swis_dao = SwisDao('swis/swis_config.cfg',
                   database_uri='sqlite:///swis/swis2.db')
lcm_dao = LCMDao('sqlite:///barebones/LCM_Data/LCM.db',
                 'barebones/LCM_config.cfg')

swis_wof = WOF(swis_dao)
swis_wof.config_from_file('swis/swis_config.cfg')

lcm_wof = WOF(lcm_dao)
lcm_wof.config_from_file('barebones/LCM_config.cfg')
#Create the Flask applications
swis_flask_app = create_app(swis_wof)
lcm_flask_app = create_app(lcm_wof)

#Create the soaplib classes
SWISWOFService = create_wof_service_class(swis_wof)
LCMWOFService = create_wof_service_class(lcm_wof)

#Create the soaplib applications
swis_soap_app = soaplib.core.Application(
    services=[SWISWOFService],
Esempio n. 9
0
class TestWOF(unittest.TestCase):
    """
    Tests wof response generation methods for validation against
    the WaterML 1.0 schema.
    """

    def setUp(self):
        dao = TestDao()
        self.wof_inst = WOF(dao, TEST_CONFIG_FILE)
        waterml_schema_path = os.path.join(os.path.dirname(__file__),
                                        'cuahsiTimeSeries_v1_0.xsd')
        waterml_schema_doc = etree.parse(waterml_schema_path)
        self.waterml_schema = etree.XMLSchema(waterml_schema_doc)

    def response_to_StringIO(self, response, root_name):
        """
        Converts WOF method response to StringIO object.
        """
        response_output = StringIO.StringIO()
        response.export(response_output, 0, name_=root_name,
                        namespacedef_=NSDEF)
        response_output.seek(0)
        return response_output

    def save_response(self, response, filename, root_name):
        f = open(filename, 'w')
        response.export(f, 0, name_=root_name,
                        namespacedef_=NSDEF)
        f.close()
        
    def compare_output_to_known_xml(self,
                                    response_stringIO,
                                    known_xml_filename):
        """
        Make sure response output is as expected. This tests that a
        response contains the same XML as in the known XML file.
        """
        known_file_path = os.path.join(os.path.dirname(__file__),
                                       TEST_XML_DIR, known_xml_filename)
        # Use objectify and etree to remove whitespace from XML for comparison
        response_tree = objectify.parse(response_stringIO)
        known_tree = objectify.parse(known_file_path)
        response_string = etree.tostring(response_tree)
        known_string = etree.tostring(known_tree)
        assert response_string == known_string

    def test_get_all_sites(self):
        response = self.wof_inst.create_get_site_response()
        response_string = self.response_to_StringIO(response,
                                                    'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_all_sites.xml')

    def test_get_one_site(self):
        response = self.wof_inst.create_get_site_response(
            'TEST:SITE_A')
        response_string = self.response_to_StringIO(response,
                                                    'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_one_site.xml')

    def test_get_multiple_sites(self):
        response = self.wof_inst.create_get_site_response(
            'TEST:SITE_A,TEST:SITE_B')
        response_string = self.response_to_StringIO(response,
                                                    'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_multiple_sites.xml')

    def test_get_all_variables(self):
        response = self.wof_inst.create_get_variable_info_response()
        response_string = self.response_to_StringIO(response,
                                                    'variablesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_all_variables.xml')

    def test_get_one_variable(self):
        response = self.wof_inst.create_get_variable_info_response(
            'TESTVocab:Temp')
        response_string = self.response_to_StringIO(response,
                                                    'variablesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_one_variable.xml')

    def test_get_multiple_variables(self):
        response = self.wof_inst.create_get_variable_info_response(
            'TESTVocab:Flow,TESTVocab:TP')
        response_string = self.response_to_StringIO(response,
                                                    'variablesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_multiple_variables.xml')

    def test_get_site_info_novar(self):
        response = self.wof_inst.create_get_site_info_response('TEST:SITE_A')
        response_string = self.response_to_StringIO(response,
                                                    'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_siteinfo_novar.xml')

    def test_get_site_info_withvar(self):
        response = self.wof_inst.create_get_site_info_response(
            'TEST:SITE_B',
            'TESTVocab:TP')
        response_string = self.response_to_StringIO(response,
                                                    'sitesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_siteinfo_withvar.xml')

    def test_get_values_encloses_por(self):
        response = self.wof_inst.create_get_values_response(
            'TEST:SITE_A',
            'TESTVocab:Temp',
            startDateTime='2007-03-05 00:00',
            endDateTime='2007-05-06 00:00')
        response_string = self.response_to_StringIO(response,
                                                    'timeSeriesResponse')
        self.compare_output_to_known_xml(response_string,
                                         'get_values_encloses_por.xml')
Esempio n. 10
0
import soaplib
from soaplib.core.server import wsgi

from wof import WOF
from wof.soap import create_wof_service_class
from wof.flask import config, create_app

from examples.swis.swis_dao import SwisDao
from examples.barebones.LCM_dao import LCMDao

logging.basicConfig(level=logging.DEBUG)

swis_dao = SwisDao("swis/swis_config.cfg", database_uri="sqlite:///swis/swis2.db")
lcm_dao = LCMDao("sqlite:///barebones/LCM_Data/LCM.db", "barebones/LCM_config.cfg")

swis_wof = WOF(swis_dao)
swis_wof.config_from_file("swis/swis_config.cfg")

lcm_wof = WOF(lcm_dao)
lcm_wof.config_from_file("barebones/LCM_config.cfg")
# Create the Flask applications
swis_flask_app = create_app(swis_wof)
lcm_flask_app = create_app(lcm_wof)

# Create the soaplib classes
SWISWOFService = create_wof_service_class(swis_wof)
LCMWOFService = create_wof_service_class(lcm_wof)

# Create the soaplib applications
swis_soap_app = soaplib.core.Application(
    services=[SWISWOFService], tns="http://www.cuahsi.org/his/1.0/ws/", name="WaterOneFlow"