Beispiel #1
0
    def test_get_schema_url(self):
        # given
        schema_template = MagicMock(name='schema_template')
        ingest_api = MagicMock(name='ingest_api')
        latest_url = 'https://schema.humancellatlas.org/type/biomaterial/5.0.0/donor_organism'

        spec = {
            'schema': {
                'high_level_entity': 'type',
                'domain_entity': 'biomaterial',
                'module': 'donor_organism',
                'url': latest_url
            }
        }

        schema_template.lookup = MagicMock(name='lookup', return_value=spec)
        template_manager = TemplateManager(schema_template, ingest_api)
        template_manager.get_latest_schema_url = MagicMock(
            return_value=latest_url)

        # when:
        url = template_manager.get_schema_url('cell_suspension')

        # then:
        self.assertEqual(
            'https://schema.humancellatlas.org/type/biomaterial/5.0.0/donor_organism',
            url)
    def test_create_row_template_with_default_values(self, determine_strategy, build_raw):
        # given:
        schema_template = MagicMock('schema_template')
        ingest_api = MagicMock(name='ingest_api')

        # and:
        schema_url = 'http://schema.sample.com/profile'
        self._mock_schema_lookup(schema_template, schema_url=schema_url, main_category='profile',
                                 object_type='profile_type')

        # and:
        build_raw.return_value = MagicMock('column_spec')
        determine_strategy.return_value = FakeConversion('')

        # and:
        workbook = Workbook()
        worksheet = workbook.create_sheet('profile')
        worksheet['A4'] = 'profile.name'

        # when:
        template_manager = TemplateManager(schema_template, ingest_api)
        template_manager.get_schema_url = MagicMock(return_value=schema_url)
        row_template = template_manager.create_row_template(worksheet)

        # then:
        content_defaults = row_template.default_values
        self.assertIsNotNone(content_defaults)
        self.assertEqual(schema_url, content_defaults.get('describedBy'))
        self.assertEqual('profile', content_defaults.get('schema_type'))
    def test_create_row_template_with_default_values(self, determine_strategy):
        # given:
        schema_template = MagicMock('schema_template')
        ingest_api = MagicMock(name='mock_ingest_api')

        # and:
        domain_entity = "profile/profile_type"
        schema_url = "http://schema.sample.com/profile"
        schema_template.get_tabs_config = MagicMock()
        schema_template.lookup_metadata_schema_name_given_title = MagicMock(
            return_value="profile_type")
        schema_template.get_latest_schema = MagicMock(return_value=schema_url)
        schema = {
            "schema": {
                "domain_entity": domain_entity,
                "url": schema_url
            }
        }
        property_schema = {
            "description": "Property description",
            "value_type": "string"
        }
        spec_map = {"profile_type": schema, "profile.name": property_schema}
        schema_template.lookup_property_from_template = lambda key: spec_map.get(
            key)

        # and:
        determine_strategy.return_value = FakeConversion('')

        # and:
        workbook = Workbook()
        worksheet = workbook.create_sheet('profile')
        worksheet['A4'] = 'profile.name'
        ingest_worksheet = IngestWorksheet(worksheet)

        # when:
        template_manager = TemplateManager(schema_template, ingest_api)
        template_manager.get_schema_url = MagicMock(return_value=schema_url)
        row_template = template_manager.create_row_template(ingest_worksheet)

        # then:
        content_defaults = row_template.default_values
        self.assertIsNotNone(content_defaults)
        self.assertEqual(schema_url, content_defaults.get('describedBy'))
        self.assertEqual('profile', content_defaults.get('schema_type'))