Skip to content

test_contract#

load_test_json#

Source code in tests/unit/apps/core/models/test_contract.py
def load_test_json(filename) -> Dict:
    with open(test_data_path + filename) as json_file:
        data = json.load(json_file)
    return data

legacy_contract_json#

Source code in tests/unit/apps/core/models/test_contract.py
@pytest.fixture
def legacy_contract_json():
    return load_test_json("legacy_contract.json")

test_create_contract#

Source code in tests/unit/apps/core/models/test_contract.py
def test_create_contract(contract):
    contract.save()
    assert contract.id is not None

test_contract_from_legacy#

Test that creating contract from legacy json keeps all values from contract_json.

Source code in tests/unit/apps/core/models/test_contract.py
def test_contract_from_legacy(legacy_contract_json):
    """Test that creating contract from legacy json keeps all values from contract_json."""
    legacy_contract_json["contract_json"]["created"] = normalize_datetime_str(
        legacy_contract_json["contract_json"]["created"]
    )
    legacy_contract_json["contract_json"]["modified"] = normalize_datetime_str(
        legacy_contract_json["contract_json"]["modified"]
    )
    contract, created = Contract.create_or_update_from_legacy(legacy_contract_json)
    assert created
    to_legacy = contract.to_legacy()
    assert to_legacy["contract_json"] == legacy_contract_json["contract_json"]
    assert to_legacy["id"] == legacy_contract_json["id"]

test_contract_from_legacy_empty_description#

Test that empty description clears description.

Source code in tests/unit/apps/core/models/test_contract.py
def test_contract_from_legacy_empty_description(legacy_contract_json):
    """Test that empty description clears description."""
    legacy_contract_json["contract_json"]["description"] = "test"
    contract, created = Contract.create_or_update_from_legacy(legacy_contract_json)
    assert created
    assert contract.description == {"und": "test"}

    legacy_contract_json["contract_json"]["description"] = ""
    contract, created = Contract.create_or_update_from_legacy(legacy_contract_json)
    assert not created
    assert contract.description is None

test_contract_from_legacy_too_big_quota#

Test that quota value is clamped to max bigint value (needed for some legacy test data).

Source code in tests/unit/apps/core/models/test_contract.py
def test_contract_from_legacy_too_big_quota(legacy_contract_json):
    """Test that quota value is clamped to max bigint value (needed for some legacy test data)."""
    legacy_contract_json["contract_json"]["quota"] = 1.23e25
    contract, created = Contract.create_or_update_from_legacy(legacy_contract_json)
    assert created
    assert contract.quota == models.BigIntegerField.MAX_BIGINT