Beispiel #1
0
def test_update_service_creates_a_history_record_with_current_data(
        notify_db_session, current_sms_provider, ses_provider):
    user = create_user()
    assert Service.query.count() == 0
    assert Service.get_history_model().query.count() == 0
    service = Service(name="service_name",
                      email_from="email_from",
                      message_limit=1000,
                      restricted=False,
                      created_by=user)
    dao_create_service(service, user)

    assert Service.query.count() == 1
    assert Service.query.first().version == 1
    assert Service.get_history_model().query.count() == 1

    service.name = 'updated_service_name'
    service.sms_provider_id = current_sms_provider.id
    dao_update_service(service)

    assert Service.query.count() == 1
    assert Service.get_history_model().query.count() == 2

    service_from_db = Service.query.first()

    assert service_from_db.version == 2

    service_history = Service.get_history_model().query.filter_by(
        name='service_name').one()
    assert service_history.version == 1
    assert service_history.sms_provider_id is None
    service_history = Service.get_history_model().query.filter_by(
        name='updated_service_name').one()
    assert service_history.version == 2
    assert service_history.sms_provider_id == current_sms_provider.id