Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | def test_compute_metadata_npm(self): | ||||
} | } | ||||
""" | """ | ||||
declared_metadata = { | declared_metadata = { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'type': 'SoftwareSourceCode', | 'type': 'SoftwareSourceCode', | ||||
'name': 'test_metadata', | 'name': 'test_metadata', | ||||
'version': '0.0.2', | 'version': '0.0.2', | ||||
'description': 'Simple package.json test for indexer', | 'description': 'Simple package.json test for indexer', | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'git+https://github.com/moranegg/metadata_test', | 'git+https://github.com/moranegg/metadata_test', | ||||
'schema:author': { | 'author': [{ | ||||
'type': 'Person', | 'type': 'Person', | ||||
'name': 'Morane G', | 'name': 'Morane G', | ||||
'email': 'moranegg@example.com', | 'email': 'moranegg@example.com', | ||||
}, | }], | ||||
} | } | ||||
# when | # when | ||||
result = MAPPINGS["NpmMapping"].translate(content) | result = MAPPINGS["NpmMapping"].translate(content) | ||||
# then | # then | ||||
self.assertEqual(declared_metadata, result) | self.assertEqual(declared_metadata, result) | ||||
def test_extract_minimal_metadata_dict(self): | def test_extract_minimal_metadata_dict(self): | ||||
""" | """ | ||||
Test the creation of a coherent minimal metadata set | Test the creation of a coherent minimal metadata set | ||||
""" | """ | ||||
# given | # given | ||||
metadata_list = [{ | metadata_list = [{ | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'name': 'test_1', | 'name': 'test_1', | ||||
'version': '0.0.2', | 'version': '0.0.2', | ||||
'description': 'Simple package.json test for indexer', | 'description': 'Simple package.json test for indexer', | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'git+https://github.com/moranegg/metadata_test', | 'git+https://github.com/moranegg/metadata_test', | ||||
}, { | }, { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'name': 'test_0_1', | 'name': 'test_0_1', | ||||
'version': '0.0.2', | 'version': '0.0.2', | ||||
'description': 'Simple package.json test for indexer', | 'description': 'Simple package.json test for indexer', | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'git+https://github.com/moranegg/metadata_test' | 'git+https://github.com/moranegg/metadata_test' | ||||
}, { | }, { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'name': 'test_metadata', | 'name': 'test_metadata', | ||||
'version': '0.0.2', | 'version': '0.0.2', | ||||
'schema:author': 'moranegg', | 'author': 'moranegg', | ||||
}] | }] | ||||
# when | # when | ||||
results = extract_minimal_metadata_dict(metadata_list) | results = extract_minimal_metadata_dict(metadata_list) | ||||
# then | # then | ||||
expected_results = { | expected_results = { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
"version": '0.0.2', | "version": '0.0.2', | ||||
"description": 'Simple package.json test for indexer', | "description": 'Simple package.json test for indexer', | ||||
"name": ['test_1', 'test_0_1', 'test_metadata'], | "name": ['test_1', 'test_0_1', 'test_metadata'], | ||||
"schema:author": 'moranegg', | "author": ['moranegg'], | ||||
"schema:codeRepository": | "codeRepository": | ||||
'git+https://github.com/moranegg/metadata_test', | 'git+https://github.com/moranegg/metadata_test', | ||||
} | } | ||||
self.assertEqual(expected_results, results) | self.assertEqual(expected_results, results) | ||||
def test_index_content_metadata_npm(self): | def test_index_content_metadata_npm(self): | ||||
""" | """ | ||||
testing NPM with package.json | testing NPM with package.json | ||||
- one sha1 uses a file that can't be translated to metadata and | - one sha1 uses a file that can't be translated to metadata and | ||||
Show All 16 Lines | def test_index_content_metadata_npm(self): | ||||
metadata_indexer.run(sha1s, policy_update='ignore-dups') | metadata_indexer.run(sha1s, policy_update='ignore-dups') | ||||
results = list(metadata_indexer.idx_storage.content_metadata_get( | results = list(metadata_indexer.idx_storage.content_metadata_get( | ||||
sha1s)) | sha1s)) | ||||
expected_results = [{ | expected_results = [{ | ||||
'translated_metadata': { | 'translated_metadata': { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'type': 'SoftwareSourceCode', | 'type': 'SoftwareSourceCode', | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'git+https://github.com/moranegg/metadata_test', | 'git+https://github.com/moranegg/metadata_test', | ||||
'description': 'Simple package.json test for indexer', | 'description': 'Simple package.json test for indexer', | ||||
'name': 'test_metadata', | 'name': 'test_metadata', | ||||
'version': '0.0.1' | 'version': '0.0.1' | ||||
}, | }, | ||||
'id': hash_to_bytes('26a9f72a7c87cc9205725cfd879f514ff4f3d8d5') | 'id': hash_to_bytes('26a9f72a7c87cc9205725cfd879f514ff4f3d8d5') | ||||
}, { | }, { | ||||
'translated_metadata': { | 'translated_metadata': { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'type': 'SoftwareSourceCode', | 'type': 'SoftwareSourceCode', | ||||
'codemeta:issueTracker': | 'issueTracker': | ||||
'https://github.com/npm/npm/issues', | 'https://github.com/npm/npm/issues', | ||||
'schema:author': { | 'author': [{ | ||||
'type': 'Person', | 'type': 'Person', | ||||
'name': 'Isaac Z. Schlueter', | 'name': 'Isaac Z. Schlueter', | ||||
'email': 'i@izs.me', | 'email': 'i@izs.me', | ||||
'schema:url': 'http://blog.izs.me', | 'url': 'http://blog.izs.me', | ||||
}, | }], | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'git+https://github.com/npm/npm', | 'git+https://github.com/npm/npm', | ||||
'description': 'a package manager for JavaScript', | 'description': 'a package manager for JavaScript', | ||||
'schema:license': 'Artistic-2.0', | 'license': 'https://spdx.org/licenses/Artistic-2.0', | ||||
'version': '5.0.3', | 'version': '5.0.3', | ||||
'name': 'npm', | 'name': 'npm', | ||||
'keywords': [ | 'keywords': [ | ||||
'install', | 'install', | ||||
'modules', | 'modules', | ||||
'package manager', | 'package manager', | ||||
'package.json' | 'package.json' | ||||
], | ], | ||||
'schema:url': 'https://docs.npmjs.com/' | 'url': 'https://docs.npmjs.com/' | ||||
}, | }, | ||||
'id': hash_to_bytes('d4c647f0fc257591cc9ba1722484229780d1c607') | 'id': hash_to_bytes('d4c647f0fc257591cc9ba1722484229780d1c607') | ||||
}, { | }, { | ||||
'translated_metadata': None, | 'translated_metadata': None, | ||||
'id': hash_to_bytes('02fb2c89e14f7fab46701478c83779c7beb7b069') | 'id': hash_to_bytes('02fb2c89e14f7fab46701478c83779c7beb7b069') | ||||
}] | }] | ||||
for result in results: | for result in results: | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | def test_compute_metadata_maven(self): | ||||
</repository> | </repository> | ||||
</repositories> | </repositories> | ||||
</project>""" | </project>""" | ||||
result = MAPPINGS["MavenMapping"].translate(raw_content) | result = MAPPINGS["MavenMapping"].translate(raw_content) | ||||
self.assertEqual(result, { | self.assertEqual(result, { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'type': 'SoftwareSourceCode', | 'type': 'SoftwareSourceCode', | ||||
'name': 'Maven Default Project', | 'name': 'Maven Default Project', | ||||
'schema:identifier': 'com.mycompany.app', | 'identifier': 'com.mycompany.app', | ||||
'version': '1.2.3', | 'version': '1.2.3', | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'http://repo1.maven.org/maven2/com/mycompany/app/my-app', | 'http://repo1.maven.org/maven2/com/mycompany/app/my-app', | ||||
}) | }) | ||||
def test_revision_metadata_indexer(self): | def test_revision_metadata_indexer(self): | ||||
metadata_indexer = RevisionMetadataTestIndexer() | metadata_indexer = RevisionMetadataTestIndexer() | ||||
fill_obj_storage(metadata_indexer.objstorage) | fill_obj_storage(metadata_indexer.objstorage) | ||||
fill_storage(metadata_indexer.storage) | fill_storage(metadata_indexer.storage) | ||||
tool = metadata_indexer.idx_storage.indexer_configuration_get( | tool = metadata_indexer.idx_storage.indexer_configuration_get( | ||||
{'tool_'+k: v for (k, v) in TRANSLATOR_TOOL.items()}) | {'tool_'+k: v for (k, v) in TRANSLATOR_TOOL.items()}) | ||||
assert tool is not None | assert tool is not None | ||||
metadata_indexer.idx_storage.content_metadata_add([{ | metadata_indexer.idx_storage.content_metadata_add([{ | ||||
'indexer_configuration_id': tool['id'], | 'indexer_configuration_id': tool['id'], | ||||
'id': b'cde', | 'id': b'cde', | ||||
'translated_metadata': { | 'translated_metadata': { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'type': 'SoftwareSourceCode', | 'type': 'SoftwareSourceCode', | ||||
'codemeta:issueTracker': | 'issueTracker': | ||||
'https://github.com/librariesio/yarn-parser/issues', | 'https://github.com/librariesio/yarn-parser/issues', | ||||
'version': '1.0.0', | 'version': '1.0.0', | ||||
'name': 'yarn-parser', | 'name': 'yarn-parser', | ||||
'schema:author': 'Andrew Nesbitt', | 'author': ['Andrew Nesbitt'], | ||||
'url': | 'url': | ||||
'https://github.com/librariesio/yarn-parser#readme', | 'https://github.com/librariesio/yarn-parser#readme', | ||||
'processorRequirements': {'node': '7.5'}, | 'processorRequirements': {'node': '7.5'}, | ||||
'license': 'AGPL-3.0', | 'license': 'AGPL-3.0', | ||||
'keywords': ['yarn', 'parse', 'lock', 'dependencies'], | 'keywords': ['yarn', 'parse', 'lock', 'dependencies'], | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'git+https://github.com/librariesio/yarn-parser.git', | 'git+https://github.com/librariesio/yarn-parser.git', | ||||
'description': | 'description': | ||||
'Tiny web service for parsing yarn.lock files', | 'Tiny web service for parsing yarn.lock files', | ||||
} | } | ||||
}]) | }]) | ||||
sha1_gits = [ | sha1_gits = [ | ||||
hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | ||||
] | ] | ||||
metadata_indexer.run(sha1_gits, 'update-dups') | metadata_indexer.run(sha1_gits, 'update-dups') | ||||
results = list(metadata_indexer.idx_storage.revision_metadata_get( | results = list(metadata_indexer.idx_storage.revision_metadata_get( | ||||
sha1_gits)) | sha1_gits)) | ||||
expected_results = [{ | expected_results = [{ | ||||
'id': hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | 'id': hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | ||||
'tool': TRANSLATOR_TOOL, | 'tool': TRANSLATOR_TOOL, | ||||
'translated_metadata': { | 'translated_metadata': { | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | ||||
'url': | 'url': | ||||
'https://github.com/librariesio/yarn-parser#readme', | 'https://github.com/librariesio/yarn-parser#readme', | ||||
'schema:codeRepository': | 'codeRepository': | ||||
'git+https://github.com/librariesio/yarn-parser.git', | 'git+https://github.com/librariesio/yarn-parser.git', | ||||
'schema:author': 'Andrew Nesbitt', | 'author': ['Andrew Nesbitt'], | ||||
'license': 'AGPL-3.0', | 'license': 'AGPL-3.0', | ||||
'version': '1.0.0', | 'version': '1.0.0', | ||||
'description': | 'description': | ||||
'Tiny web service for parsing yarn.lock files', | 'Tiny web service for parsing yarn.lock files', | ||||
'codemeta:issueTracker': | 'issueTracker': | ||||
'https://github.com/librariesio/yarn-parser/issues', | 'https://github.com/librariesio/yarn-parser/issues', | ||||
'name': 'yarn-parser', | 'name': 'yarn-parser', | ||||
'keywords': ['yarn', 'parse', 'lock', 'dependencies'], | 'keywords': ['yarn', 'parse', 'lock', 'dependencies'], | ||||
}, | }, | ||||
}] | }] | ||||
for result in results: | for result in results: | ||||
del result['tool']['id'] | del result['tool']['id'] | ||||
# then | # then | ||||
self.assertEqual(expected_results, results) | self.assertEqual(expected_results, results) |