Example #1
0
def test_get_subscription_by_wrong_name_type(
    controller: Controller, subscription_name: str
):
    """Check search with subscription_name wrong type"""
    with pytest.raises(SubscriptionException) as exc:
        controller.get_subscription_by_name(subscription_name)
    expected_exc_msg = WRONG_TYPE_MSG.format(
        expected=str, recieved_type=type(subscription_name), field=subscription_name
    )
    assert str(exc.value) == expected_exc_msg
Example #2
0
def test_get_not_exist_subscription(controller_subs_not_found: Controller):
    """Check correct behaviour in case of nonexistent subscription_name"""
    with pytest.raises(SubsNotFoundException) as exc:
        assert controller_subs_not_found.get_subscription_by_name(
            "Definitely not exist"
        )
    assert (
        str(exc.value) == "Subscription with name 'Definitely not exist' was not found"
    )
Example #3
0
def test_get_subscription_by_name(controller: Controller):
    """Check correct format of found subscription:
        _id from database is not in the dict
        type(result) == Subscription
        type(start_date) == date, not datetime
        other fields values and types have no changes
    """
    actual_result = controller.get_subscription_by_name("Sky Store")
    expected_result = Subscription(
        owner="Mary",
        name="Sky Store",
        frequency="monthly",
        start_date=date(2019, 4, 13),
        price=12.97,
        currency="CNY",
        comment="Generation date: 23/06/2020, 10:46:41",
    )
    assert actual_result == expected_result
Example #4
0
def test_get_subscription_by_empty_name(controller: Controller):
    """Check correct behaviour in case of empty subscription_name"""
    with pytest.raises(InvalidValueException) as exc:
        controller.get_subscription_by_name("")
    expected_err_msg = "Field length should be more than one"
    assert str(exc.value) == expected_err_msg