예제 #1
0
    def test_external_documentation_fields_values(self):
        """ Test Top.external_documentation group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.external_documentation.any_field.url = 'http://example.com'
        top.external_documentation.any_field.title = 'the-title'
        top.external_documentation.any_field.description = 'the-description'
        top.external_documentation.any_field.source = 'http://example.com'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(
            new_top.external_documentation.any_field.url,
            'http://example.com')
        self.assertEqual(
            new_top.external_documentation.any_field.title,
            'the-title')
        self.assertEqual(
            new_top.external_documentation.any_field.description,
            'the-description')
        self.assertEqual(
            new_top.external_documentation.any_field.source,
            'http://example.com')
예제 #2
0
    def test_identity_fields_values(self):
        """ Test contacts group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.identity.bspace = 'b-space'
        top.identity.btime = 'b-time'
        top.identity.dataset = dataset.vid
        top.identity.id = dataset.id
        top.identity.revision = 7
        top.identity.source = 'example.com'
        top.identity.subset = 'mortality'
        top.identity.type = '?'
        top.identity.variation = 1
        top.identity.version = '0.0.7'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.identity.bspace, 'b-space')
        self.assertEqual(new_top.identity.btime, 'b-time')
        self.assertEqual(new_top.identity.dataset, dataset.vid)
        self.assertEqual(new_top.identity.id, dataset.id)
        self.assertEqual(new_top.identity.revision, 7)
        self.assertEqual(new_top.identity.source, 'example.com')
        self.assertEqual(new_top.identity.subset, 'mortality')
        self.assertEqual(new_top.identity.type, '?')
        self.assertEqual(new_top.identity.variation, 1)
        self.assertEqual(new_top.identity.version, '0.0.7')
예제 #3
0
    def test_identity_fields_values(self):
        """ Test contacts group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.identity.bspace = 'b-space'
        top.identity.btime = 'b-time'
        top.identity.dataset = dataset.vid
        top.identity.id = dataset.id
        top.identity.revision = 7
        top.identity.source = 'example.com'
        top.identity.subset = 'mortality'
        top.identity.type = '?'
        top.identity.variation = 1
        top.identity.version = '0.0.7'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.identity.bspace, 'b-space')
        self.assertEqual(new_top.identity.btime, 'b-time')
        self.assertEqual(new_top.identity.dataset, dataset.vid)
        self.assertEqual(new_top.identity.id, dataset.id)
        self.assertEqual(new_top.identity.revision, 7)
        self.assertEqual(new_top.identity.source, 'example.com')
        self.assertEqual(new_top.identity.subset, 'mortality')
        self.assertEqual(new_top.identity.type, '?')
        self.assertEqual(new_top.identity.variation, 1)
        self.assertEqual(new_top.identity.version, '0.0.7')
예제 #4
0
    def test_uses_exactly_two_db_hits_to_build_config(self):

        # create appropriate tree in the database
        configs = [
            ('names.fqname', self.dataset.fqname),
            ('names.name', self.dataset.name),
            ('names.vid', self.dataset.vid),
            ('names.vname', self.dataset.vname),

            # about
            ('about.access', 'restricted'),
            ('about.footnote', None),
            ('about.grain', 'hospital')
        ]

        self._create_db_tree(configs)

        # now collect all queries
        queries = []

        def before_cursor_execute(conn, cursor, statement, parameters, context,
                                  executemany):
            queries.append((statement, parameters))

        event.listen(self.db.engine, 'before_cursor_execute',
                     before_cursor_execute)

        # build from db
        top = Top()
        top.build_from_db(self.dataset)
        expected_queries = [
            'dataset retrieve', 'all configs retrieve while cache building'
        ]
        self.assertEqual(len(expected_queries), len(queries))
예제 #5
0
    def test_build_tree_from_database(self):
        """ Populates property tree with values from database. """

        # create appropriate tree in the database
        self._create_db_tree()

        # build from db
        top = Top()
        top.build_from_db(self.dataset)
        self.assertEqual(top.names.vid, self.dataset.vid)
예제 #6
0
    def test_build_tree_from_database(self):
        """ Populates property tree with values from database. """

        # create appropriate tree in the database
        self._create_db_tree()

        # build from db
        top = Top()
        top.build_from_db(self.dataset)
        self.assertEqual(top.names.vid, self.dataset.vid)
예제 #7
0
    def test_change_tree_build_from_database(self):

        # create appropriate tree in the database
        self._create_db_tree()

        # build from db
        top = Top()
        top.build_from_db(self.dataset)

        # change and test
        assert top.is_bound()
        vid_value_config = self.db.session.query(Config).filter_by(key='vid', type='metadata').one()
        self.assertNotEqual(vid_value_config.value, 'vid-2')
        top.names.vid = 'vid-2'
        vid_value_config = self.db.session.query(Config).filter_by(key='vid', type='metadata').one()
        self.assertEqual(vid_value_config.value, 'vid-2')
예제 #8
0
    def test_build_fields_values(self):
        """ Test Top().build group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.build.key1 = 'value1'
        top.build.key2 = 'value2'
        top.build.key3 = 'value3'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.build.key1, 'value1')
        self.assertEqual(new_top.build.key2, 'value2')
        self.assertEqual(new_top.build.key3, 'value3')
예제 #9
0
    def test_requirements_fields_values(self):
        """ Test Top.requirements group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.requirements.xlrd = 'xlrd'
        top.requirements.requests = 'requests'
        top.requirements.suds = 'suds'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.requirements.xlrd, 'xlrd')
        self.assertEqual(new_top.requirements.requests, 'requests')
        self.assertEqual(new_top.requirements.suds, 'suds')
예제 #10
0
    def test_versions_fields_values(self):
        """ Test Top().versions group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.versions['1'].date = '2015-04-12T15:49:55.077036'
        top.versions['1'].description = 'Adding coverage'
        top.versions['1'].version = '0.0.2'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.versions['1'].date, '2015-04-12T15:49:55.077036')
        self.assertEqual(new_top.versions['1'].description, 'Adding coverage')
        self.assertEqual(new_top.versions['1'].version, '0.0.2')
예제 #11
0
    def test_change_tree_build_from_database(self):

        # create appropriate tree in the database
        self._create_db_tree()

        # build from db
        top = Top()
        top.build_from_db(self.dataset)

        # change and test
        assert top.is_bound()
        vid_value_config = self.db.session.query(Config).filter_by(
            key='vid', type='metadata').one()
        self.assertNotEqual(vid_value_config.value, 'vid-2')
        top.names.vid = 'vid-2'
        vid_value_config = self.db.session.query(Config).filter_by(
            key='vid', type='metadata').one()
        self.assertEqual(vid_value_config.value, 'vid-2')
예제 #12
0
    def test_versions_fields_values(self):
        """ Test Top().versions group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.versions['1'].date = '2015-04-12T15:49:55.077036'
        top.versions['1'].description = 'Adding coverage'
        top.versions['1'].version = '0.0.2'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.versions['1'].date,
                         '2015-04-12T15:49:55.077036')
        self.assertEqual(new_top.versions['1'].description, 'Adding coverage')
        self.assertEqual(new_top.versions['1'].version, '0.0.2')
예제 #13
0
    def test_names_fields_values(self):
        """ Test Top().names group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.names.fqname = 'fq-name'
        top.names.name = 'name'
        top.names.vid = 'd001'
        top.names.vname = 'vname'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.names.fqname, 'fq-name')
        self.assertEqual(new_top.names.name, 'name')
        self.assertEqual(new_top.names.vid, 'd001')
        self.assertEqual(new_top.names.vname, 'vname')
예제 #14
0
    def test_names_fields_values(self):
        """ Test Top().names group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.names.fqname = 'fq-name'
        top.names.name = 'name'
        top.names.vid = 'd001'
        top.names.vname = 'vname'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.names.fqname, 'fq-name')
        self.assertEqual(new_top.names.name, 'name')
        self.assertEqual(new_top.names.vid, 'd001')
        self.assertEqual(new_top.names.vname, 'vname')
예제 #15
0
    def test_about_group_fields_values(self):
        """ Test about group fields values. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.about.access = 'restricted'
        top.about.footnote = 'the-footnote'
        top.about.grain = 'hospital'
        top.about.groups = ['health', 'california']
        top.about.license = 'ckdbl'
        top.about.processed = 'processed'
        top.about.rights = 'public'
        top.about.source = 'http://example.com'
        top.about.space = 'California'
        top.about.subject = 'Subject'
        top.about.summary = 'The Inpatient Mortality Indicators (IMIs) are a subset of...'
        top.about.tags = ['tag1', 'tag2']
        top.about.time = '15:55'  # TODO: How to convert time?  ESB: You don't; it's usually an ISO duration, or integer year.
        top.about.title = 'Inpatient Mortality Indicators'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.about.access, 'restricted')
        self.assertEqual(new_top.about.footnote, 'the-footnote')
        self.assertEqual(new_top.about.grain, 'hospital')
        self.assertEqual(new_top.about.groups, ['health', 'california'])
        self.assertEqual(new_top.about.license, 'ckdbl')
        self.assertEqual(new_top.about.processed, 'processed')
        self.assertEqual(new_top.about.rights, 'public')
        self.assertEqual(new_top.about.source, 'http://example.com')
        self.assertEqual(new_top.about.space, 'California')
        self.assertEqual(new_top.about.subject, 'Subject')
        self.assertEqual(
            new_top.about.summary,
            'The Inpatient Mortality Indicators (IMIs) are a subset of...')

        self.assertEqual(new_top.about.tags, ['tag1', 'tag2'])
        self.assertEqual(new_top.about.time,
                         '15:55')  # TODO: How to convert time?
        self.assertEqual(new_top.about.title, 'Inpatient Mortality Indicators')
예제 #16
0
    def test_about_group_fields_values(self):
        """ Test about group fields values. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.about.access = 'restricted'
        top.about.footnote = 'the-footnote'
        top.about.grain = 'hospital'
        top.about.groups = ['health', 'california']
        top.about.license = 'ckdbl'
        top.about.processed = 'processed'
        top.about.rights = 'public'
        top.about.source = 'http://example.com'
        top.about.space = 'California'
        top.about.subject = 'Subject'
        top.about.summary = 'The Inpatient Mortality Indicators (IMIs) are a subset of...'
        top.about.tags = ['tag1', 'tag2']
        top.about.time = '15:55'  # TODO: How to convert time?  ESB: You don't; it's usually an ISO duration, or integer year.
        top.about.title = 'Inpatient Mortality Indicators'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.about.access, 'restricted')
        self.assertEqual(new_top.about.footnote, 'the-footnote')
        self.assertEqual(new_top.about.grain, 'hospital')
        self.assertEqual(new_top.about.groups, ['health', 'california'])
        self.assertEqual(new_top.about.license, 'ckdbl')
        self.assertEqual(new_top.about.processed, 'processed')
        self.assertEqual(new_top.about.rights, 'public')
        self.assertEqual(new_top.about.source, 'http://example.com')
        self.assertEqual(new_top.about.space, 'California')
        self.assertEqual(new_top.about.subject, 'Subject')
        self.assertEqual(
            new_top.about.summary,
            'The Inpatient Mortality Indicators (IMIs) are a subset of...')

        self.assertEqual(new_top.about.tags, ['tag1', 'tag2'])
        self.assertEqual(new_top.about.time, '15:55')  # TODO: How to convert time?
        self.assertEqual(new_top.about.title, 'Inpatient Mortality Indicators')
예제 #17
0
    def test_dependencies_fields_values(self):
        """ Test Top.dependencies group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.dependencies.counties = 'census.gov-index-counties'
        top.dependencies.facility_index = 'oshpd.ca.gov-facilities-index-facilities_index-2010e2014'
        top.dependencies.facility_info = 'oshpd.ca.gov-facilities-index-facilities'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.dependencies.counties,
                         'census.gov-index-counties')
        self.assertEqual(
            new_top.dependencies.facility_index,
            'oshpd.ca.gov-facilities-index-facilities_index-2010e2014')
        self.assertEqual(new_top.dependencies.facility_info,
                         'oshpd.ca.gov-facilities-index-facilities')
예제 #18
0
    def test_contacts_fields_values(self):
        """ Test contacts group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.contacts.creator.role = 'c-developer'
        top.contacts.creator.org = 'c-home'
        top.contacts.creator.email = '*****@*****.**'
        top.contacts.creator.name = 'c-tester'
        top.contacts.creator.url = 'http://creator.example.com'
        # FIXME: Populate maintainer, source and analyst too.

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.contacts.creator.role, 'c-developer')
        self.assertEqual(new_top.contacts.creator.org, 'c-home')
        self.assertEqual(new_top.contacts.creator.email, '*****@*****.**')
        self.assertEqual(new_top.contacts.creator.name, 'c-tester')
        self.assertEqual(new_top.contacts.creator.url, 'http://creator.example.com')
예제 #19
0
    def test_dependencies_fields_values(self):
        """ Test Top.dependencies group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.dependencies.counties = 'census.gov-index-counties'
        top.dependencies.facility_index = 'oshpd.ca.gov-facilities-index-facilities_index-2010e2014'
        top.dependencies.facility_info = 'oshpd.ca.gov-facilities-index-facilities'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(
            new_top.dependencies.counties,
            'census.gov-index-counties')
        self.assertEqual(
            new_top.dependencies.facility_index,
            'oshpd.ca.gov-facilities-index-facilities_index-2010e2014')
        self.assertEqual(
            new_top.dependencies.facility_info,
            'oshpd.ca.gov-facilities-index-facilities')
예제 #20
0
    def test_build_fields_values(self):
        """ Test Top().build group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.build.key1 = 'value1'
        top.build.key2 = 'value2'
        top.build.key3 = 'value3'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(
            new_top.build.key1,
            'value1')
        self.assertEqual(
            new_top.build.key2,
            'value2')
        self.assertEqual(
            new_top.build.key3,
            'value3')
예제 #21
0
    def test_contacts_fields_values(self):
        """ Test contacts group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.contacts.creator.role = 'c-developer'
        top.contacts.creator.org = 'c-home'
        top.contacts.creator.email = '*****@*****.**'
        top.contacts.creator.name = 'c-tester'
        top.contacts.creator.url = 'http://creator.example.com'
        # FIXME: Populate maintainer, source and analyst too.

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.contacts.creator.role, 'c-developer')
        self.assertEqual(new_top.contacts.creator.org, 'c-home')
        self.assertEqual(new_top.contacts.creator.email, '*****@*****.**')
        self.assertEqual(new_top.contacts.creator.name, 'c-tester')
        self.assertEqual(new_top.contacts.creator.url,
                         'http://creator.example.com')
예제 #22
0
    def test_requirements_fields_values(self):
        """ Test Top.requirements group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.requirements.xlrd = 'xlrd'
        top.requirements.requests = 'requests'
        top.requirements.suds = 'suds'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(
            new_top.requirements.xlrd,
            'xlrd')
        self.assertEqual(
            new_top.requirements.requests,
            'requests')
        self.assertEqual(
            new_top.requirements.suds,
            'suds')
예제 #23
0
    def test_external_documentation_fields_values(self):
        """ Test Top.external_documentation group fields of the metadata config. """
        # Test both - setting and saving to db.
        top = Top()
        dataset = DatasetFactory()
        top.link_config(self.my_library.database.session, dataset)

        top.external_documentation.any_field.url = 'http://example.com'
        top.external_documentation.any_field.title = 'the-title'
        top.external_documentation.any_field.description = 'the-description'
        top.external_documentation.any_field.source = 'http://example.com'

        # build from db and check
        new_top = Top()
        new_top.build_from_db(dataset)
        self.assertEqual(new_top.external_documentation.any_field.url,
                         'http://example.com')
        self.assertEqual(new_top.external_documentation.any_field.title,
                         'the-title')
        self.assertEqual(new_top.external_documentation.any_field.description,
                         'the-description')
        self.assertEqual(new_top.external_documentation.any_field.source,
                         'http://example.com')
예제 #24
0
 def metadata(self):
     """Access process configuarion values as attributes. """
     from ambry.metadata.schema import Top  # cross-module import
     top = Top()
     top.build_from_db(self.dataset)
     return top