Esempio n. 1
0
def test_domain_model_validation_test__creates_DomainModel_object(mocker):
    mocked_init = mocker.patch.object(domain_model.DomainModel,
                                      "__init__",
                                      autospec=True,
                                      return_value=None)
    domain_model_validation_test(DomainModel)
    mocked_init.assert_called_once()
Esempio n. 2
0
def test_domain_model_validation_test__calls_validate_with_no_expected_error(
        mocker):
    mocked_validate = mocker.patch.object(domain_model.DomainModelWithUuid,
                                          "validate",
                                          autospec=True)
    test_uuid = uuid.UUID("abc8a386-b6e0-47ed-a752-f2721545f3c6")
    domain_model_validation_test(DomainModelWithUuid, "uuid", test_uuid)
    mocked_validate.assert_called_once()
Esempio n. 3
0
def test_domain_model_validation_test__calls_validate_with_no_expected_error__and_uuid_passed_as_additional_kwarg(
    mocker, ):
    mocked_validate = mocker.patch.object(domain_model.DomainModelWithUuid,
                                          "validate",
                                          autospec=True)
    test_uuid = uuid.UUID("abc8a386-b6e0-47ed-a752-f2721545f3c6")
    domain_model_validation_test(DomainModelWithUuid,
                                 additional_kwargs={"uuid": test_uuid})
    mocked_validate.assert_called_once()
Esempio n. 4
0
def test_domain_model_validation_test__catches_error(mocker):
    spied_raises = mocker.spy(misc_test_utils.pytest, "raises")
    expected_error = ValueError()
    mocker.patch.object(
        domain_model.DomainModelWithUuid,
        "validate",
        autospec=True,
        side_effect=expected_error,
    )
    test_uuid = uuid.UUID("abc8a386-b6e0-47ed-a752-f2721545f3c6")
    domain_model_validation_test(DomainModelWithUuid,
                                 "uuid",
                                 test_uuid,
                                 expected_error=ValueError)
    spied_raises.assert_called_once()
Esempio n. 5
0
def test_domain_model_validation_test__raises_assertion_error_if_single_expected_text_is_not_in_expected_error(
    mocker, ):
    expected_text = "test"
    expected_error = ValueError()
    mocker.patch.object(
        domain_model.DomainModelWithUuid,
        "validate",
        autospec=True,
        side_effect=expected_error,
    )
    test_uuid = uuid.UUID("abc8a386-b6e0-47ed-a752-f2721545f3c6")
    with pytest.raises(AssertionError):
        domain_model_validation_test(
            DomainModelWithUuid,
            "uuid",
            test_uuid,
            expected_error=ValueError,
            expected_texts_in_error=expected_text,
        )