Пример #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
Пример #2
0
def test_get_all_subscriptions_wrong_value(controller: Controller):
    """Check that Controller raises exception in case of empty owner field"""
    with pytest.raises(SubscriptionException) as exc:
        result = controller.get_subscriptions_list("")
        assert result == subscriptions_obj_list
    expected_exc_msg = "Field length should be more than one"
    assert expected_exc_msg == str(exc.value)
Пример #3
0
def test_delete_subscription_wrong_name(controller: Controller, name):
    """Test that Controller will not delete subscription with subscription name type"""
    with pytest.raises(SubscriptionException) as exc:
        assert controller.delete_subscription(name)
    assert str(exc.value) == WRONG_TYPE_MSG.format(expected=str,
                                                   recieved_type=type(name),
                                                   field=name)
Пример #4
0
def test_get_all_subscriptions(controller: Controller, owner: str):
    """Check that Controller returned correct list of Subscription objects:
        - No _id specified in each subscription
        - type is not dict, but Subscription
        - start_date field type is not datetime, but date
    """
    result = controller.get_subscriptions_list(owner)
    assert result == subscriptions_obj_list
Пример #5
0
def test_add_subscription_wrong_values(
    generated_subscription: dict, controller: Controller, field: str, value
):
    """Check that Controller will not add subscription with wrong field values"""
    sub_dict = generated_subscription.copy()
    sub_dict[field] = value
    with pytest.raises(SubscriptionException):
        assert controller.add_subscription(sub_dict)
Пример #6
0
def test_get_all_subscriptions_wrong_type(controller: Controller, owner):
    """Check that Controller raises exception in case of invalid owner field type"""
    with pytest.raises(SubscriptionException) as exc:
        result = controller.get_subscriptions_list(owner)
        assert result == subscriptions_obj_list
    expected_exc_msg = WRONG_TYPE_MSG.format(
        expected=str, recieved_type=type(owner), field=owner
    )
    assert expected_exc_msg == str(exc.value)
Пример #7
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"
    )
Пример #8
0
def test_add_subscription_with_none_fields(
    controller: Controller, generated_subscription: dict, paramNone: str
):
    """Check subscribe addition with one of the field equals None"""
    sub_dict = generated_subscription.copy()
    sub_dict[paramNone] = None
    with pytest.raises(SubscriptionException) as exc:
        assert controller.add_subscription(sub_dict)
    # Receive expected type from valid subscription instance by field name
    expected_exc_msg = WRONG_TYPE_MSG.format(
        expected=type(generated_subscription[paramNone]),
        recieved_type=type(None),
        field=None,
    )
    assert str(exc.value) == expected_exc_msg
Пример #9
0
def test_add_subscription_wrong_types(
    generated_subscription: dict, controller: Controller, field: str, value
):
    """Check that Controller will not add subscription with wrong field types"""
    sub_dict = generated_subscription.copy()
    sub_dict[field] = value
    with pytest.raises(SubscriptionException) as exc:
        assert controller.add_subscription(sub_dict)
    # Receive expected type from valid subscription instance by field name
    expected_exc_msg = WRONG_TYPE_MSG.format(
        expected=type(generated_subscription[field]),
        recieved_type=type(value),
        field=value,
    )
    assert str(exc.value) == expected_exc_msg
Пример #10
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
Пример #11
0
def test_get_next_payment_date(controller: Controller):
    """Check that client can get next_payment_date attribute for subscriptions in subscription list"""
    subscriptions_list = controller.get_subscriptions_list()
    assert type(subscriptions_list[0]) == Subscription
    for subs in subscriptions_list:
        assert type(subs.next_payment_date) is date
Пример #12
0
def test_delete_subscription_empty_name(controller: Controller):
    """Test that Controller will not delete subscription with subscription name value"""
    with pytest.raises(SubscriptionException) as exc:
        assert controller.delete_subscription("")
    assert str(exc.value) == EMPTY_FIELD_MSG
Пример #13
0
def test_delete_subscription(controller: Controller):
    """Test existing subscription deletion"""
    assert controller.delete_subscription("Youtube Music") == 1
Пример #14
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
Пример #15
0
def controller_subs_not_found(mock_dbhelper_not_found: DBHelper) -> Controller:
    """Returns Controller instance with DBHelper mock with SubsNotFoundException"""
    database = mock_dbhelper_not_found
    return Controller(database)
Пример #16
0
def test_add_subscription_empty(controller: Controller):
    """Check that Controller will not add empty subscription"""
    with pytest.raises(SubscriptionException):
        assert controller.add_subscription({})
Пример #17
0
def controller(mock_dbhelper: DBHelper) -> Controller:
    """Returns Controller class instance"""
    database = mock_dbhelper
    return Controller(database)
Пример #18
0
def test_add_subscription(generated_subscription: dict, controller: Controller):
    """Check successful subscription addition with correct parameters"""
    result = controller.add_subscription(generated_subscription)
    assert type(result) == ObjectId