doi2dataset/tests/test_license_processor.py
Alexander Minges eb270cba9b
All checks were successful
Test pipeline / test (push) Successful in 12s
Update testing documentation and improve test structure
2025-05-20 15:17:18 +02:00

62 lines
No EOL
2.1 KiB
Python

import pytest
from doi2dataset import LicenseProcessor, License
def test_license_processor_cc_by():
"""Test processing a CC BY license"""
data = {
"primary_location": {
"license": "cc-by"
}
}
license_obj = LicenseProcessor.process_license(data)
assert isinstance(license_obj, License)
assert license_obj.short == "cc-by"
assert license_obj.name == "CC BY 4.0"
assert license_obj.uri == "https://creativecommons.org/licenses/by/4.0/"
def test_license_processor_cc0():
"""Test processing a CC0 license"""
data = {
"primary_location": {
"license": "cc0"
}
}
license_obj = LicenseProcessor.process_license(data)
assert isinstance(license_obj, License)
assert license_obj.short == "cc0"
assert license_obj.name == "CC0 1.0"
assert license_obj.uri == "https://creativecommons.org/publicdomain/zero/1.0/"
def test_license_processor_unknown_license():
"""Test processing an unknown license"""
data = {
"primary_location": {
"license": "unknown-license"
}
}
license_obj = LicenseProcessor.process_license(data)
assert isinstance(license_obj, License)
assert license_obj.short == "unknown-license"
# Verify properties exist and have expected values based on implementation
assert license_obj.name == "unknown-license" or license_obj.name == ""
assert hasattr(license_obj, "uri")
def test_license_processor_no_license():
"""Test processing with no license information"""
data = {
"primary_location": {}
}
license_obj = LicenseProcessor.process_license(data)
assert isinstance(license_obj, License)
assert license_obj.short == "unknown"
assert license_obj.name == ""
assert license_obj.uri == ""
def test_license_processor_no_primary_location():
"""Test processing with no primary location"""
data = {}
license_obj = LicenseProcessor.process_license(data)
assert isinstance(license_obj, License)
assert license_obj.short == "unknown"
assert license_obj.name == ""
assert license_obj.uri == ""