Ejemplo n.º 1
0
 def test_from_dict_fail_fast_with_missing_info(self):
     # given:
     data = {}
     # then:
     with self.assertRaises(MetadataParseException):
         # when
         MetadataResource.from_dict(data)
Ejemplo n.º 2
0
    def test_generate_complete_experiment_graph(self):
        # given
        ingest_client = self.mock_ingest
        crawler = GraphCrawler(MetadataService(ingest_client))

        test_assay_process = MetadataResource.from_dict(
            self.mock_files.get_entity('processes', 'mock-assay-process'))
        test_project = MetadataResource.from_dict(
            self.mock_files.get_entity('projects', 'mock-project'))

        # when
        experiment_graph = crawler.generate_complete_experiment_graph(
            test_assay_process, test_project)

        # then
        expected_links = self.mock_files.get_links_json()

        nodes = self._get_nodes(expected_links)

        self.assertEqual(
            set([node.uuid for node in experiment_graph.nodes.get_nodes()]),
            nodes)
        self.assertEqual(len(experiment_graph.links.get_links()),
                         len(expected_links.get('links', [])))
        self.assertEqual(experiment_graph.links.to_dict(), expected_links)
Ejemplo n.º 3
0
    def test_provenance_from_dict_fail_fast(self):
        # given:
        uuid_value = '3f3212da-d5d0-4e55-b31d-83243fa02e0d'
        data = {'uuid': uuid_value,  # unexpected structure structure
                'submissionDate': 'a submission date',
                'updateDate': 'an update date'}

        # then:
        with self.assertRaises(MetadataParseException):
            # when
            MetadataResource.provenance_from_dict(data)
Ejemplo n.º 4
0
    def test_provenance_from_dict_newer_version(self):
        # given:
        uuid_value = '3f3212da-d5d0-4e55-b31d-83243fa02e0d'
        data = self._create_test_data(uuid_value)
        data['content']['describedBy'] = 'https://15.1.1/cell_suspension'

        # when:
        metadata_provenance = MetadataResource.provenance_from_dict(data)

        # then:
        self.assertEqual(15, metadata_provenance.schema_major_version)
        self.assertEqual(1, metadata_provenance.schema_minor_version)
Ejemplo n.º 5
0
    def test_provenance_from_dict_older_version(self):
        # given:
        uuid_value = '3f3212da-d5d0-4e55-b31d-83243fa02e0d'
        data = self._create_test_data(uuid_value)
        data['content']['describedBy'] = 'https://13.1.1/cell_suspension'

        # when:
        metadata_provenance = MetadataResource.provenance_from_dict(data)

        # then:
        self.assertIsNotNone(metadata_provenance)
        self.assertIsNone(metadata_provenance.to_dict().get('schema_major_version'))
        self.assertIsNone(metadata_provenance.to_dict().get('schema_minor_version'))
Ejemplo n.º 6
0
    def test_generate_experiment_process_graph(self):
        # given
        ingest_client = self.mock_ingest
        crawler = GraphCrawler(MetadataService(ingest_client))

        test_assay_process = MetadataResource.from_dict(
            self.mock_files.get_entity('processes', 'mock-assay-process'))

        # when
        experiment_graph = crawler.generate_experiment_graph(
            test_assay_process)

        # then
        self.assertEqual(len(experiment_graph.nodes.get_nodes()), 15)
        self.assertEqual(len(experiment_graph.links.get_links()), 4)
Ejemplo n.º 7
0
    def test_generate_supplementary_files_graph(self):
        # given
        ingest_client = self.mock_ingest
        crawler = GraphCrawler(MetadataService(ingest_client))

        test_project = MetadataResource.from_dict(
            self.mock_files.get_entity('projects', 'mock-project'))

        # when
        experiment_graph = crawler.generate_supplementary_files_graph(
            test_project)

        # then
        self.assertEqual(len(experiment_graph.nodes.get_nodes()), 3)
        self.assertEqual(len(experiment_graph.links.get_links()),
                         1)  # project, and 2 supplementary files
Ejemplo n.º 8
0
    def write_metadata(self, metadata: MetadataResource, project_uuid: str):

        # TODO1: only proceed if lastContentModified > last

        dest_object_key = f'{project_uuid}/metadata/{metadata.concrete_type()}/{metadata.uuid}_{metadata.dcp_version}.json'

        metadata_json = metadata.get_content(with_provenance=True)
        data_stream = DcpStagingClient.dict_to_json_stream(metadata_json)
        self.write_to_staging_bucket(dest_object_key, data_stream)

        # TODO2: patch dcpVersion
        #patch_url = metadata.metadata_json['_links']['self']['href']
        #self.ingest_client.patch(patch_url, {"dcpVersion": metadata.dcp_version})

        if metadata.metadata_type == "file":
            self.write_file_descriptor(metadata, project_uuid)
Ejemplo n.º 9
0
    def test_provenance_from_dict(self):
        # given:
        uuid_value = '3f3212da-d5d0-4e55-b31d-83243fa02e0d'
        data = self._create_test_data(uuid_value)
        data['content']['describedBy'] = 'https://some-schema/1.2.3'

        # when:
        metadata_provenance = MetadataResource.provenance_from_dict(data)

        # then:
        self.assertIsNotNone(metadata_provenance)
        self.assertEqual(data['uuid']['uuid'], metadata_provenance.document_id)
        self.assertEqual('a date', metadata_provenance.submission_date)
        self.assertEqual('another date', metadata_provenance.update_date)
        self.assertEqual(1, metadata_provenance.schema_major_version)
        self.assertEqual(2, metadata_provenance.schema_minor_version)
Ejemplo n.º 10
0
    def test_from_dict(self):
        # given:
        uuid_value = '3f3212da-d5d0-4e55-b31d-83243fa02e0d'
        data = self._create_test_data(uuid_value)

        # when:
        metadata = MetadataResource.from_dict(data)

        # then:
        self.assertIsNotNone(metadata)
        self.assertEqual('biomaterial', metadata.metadata_type)
        self.assertEqual(data['content'], metadata.metadata_json)
        self.assertEqual(utils.to_dcp_version(data['dcpVersion']), metadata.dcp_version)

        # and:
        self.assertEqual(uuid_value, metadata.uuid)
Ejemplo n.º 11
0
 def project_for_process(self,
                         process: MetadataResource) -> MetadataResource:
     return MetadataResource.from_dict(
         list(
             self.ingest_client.get_related_entities(
                 "projects", process.full_resource, "projects"))[0])
Ejemplo n.º 12
0
 def get_process(self, process_uuid) -> MetadataResource:
     return MetadataResource.from_dict(
         self.ingest_client.get_entity_by_uuid('processes', process_uuid))
Ejemplo n.º 13
0
 def from_metadata_resource(metadata: MetadataResource) -> 'ProtocolLink':
     return ProtocolLink(metadata.concrete_type(), metadata.uuid)