def test_update_service_creates_a_history_record_with_current_data(notify_db_session): 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' 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 assert Service.get_history_model().query.filter_by(name='service_name').one().version == 1 assert Service.get_history_model().query.filter_by(name='updated_service_name').one().version == 2
def test_dao_fetch_service_creator(notify_db_session): active_user_1 = create_user(email="*****@*****.**", state="active") active_user_2 = create_user(email="*****@*****.**", state="active") service = Service( name="service_name", email_from="email_from", message_limit=1000, restricted=False, created_by=active_user_1, ) dao_create_service( service, active_user_1, service_permissions=[ SMS_TYPE, EMAIL_TYPE, INTERNATIONAL_SMS_TYPE, ], ) service.created_by_id = active_user_2.id service.name = "New Name" dao_update_service(service) assert Service.query.count() == 1 history_model = Service.get_history_model() entries = history_model.query.all() assert len(entries) == 2 assert entries[1].created_by_id == active_user_2.id assert active_user_1 == dao_fetch_service_creator(service.id)
def add_service_post(): form = ServiceForm() if form.validate_on_submit(): service = Service() service.name = form.name.data service.username = form.username.data service.password = form.password.data service.ip = form.ip.data db.session.add(service) db.session.commit() flash(u'添加服务器完成') else: flash(u'数据校验失败') return redirect(url_for('.add_service'))
def test_update_service_creates_a_history_record_with_current_data(sample_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=sample_user ) dao_create_service(service, sample_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" 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 assert Service.get_history_model().query.filter_by(name="service_name").one().version == 1 assert Service.get_history_model().query.filter_by(name="updated_service_name").one().version == 2
def service_init_func(row): c = Service() c.name = row['nom'] c.description = row['description'] return c