def test_custom_form_create_complex_fields_missing_required( db, client, user, jwt): session = get_complex_custom_form_session(db, user) track = TrackSubFactory(event=session.event) db.session.commit() data = json.dumps({ 'data': { 'type': 'session', "attributes": { "title": "Move Away", "subtitle": "Moooove", "language": "English", }, "relationships": { "event": { "data": { "id": str(session.event_id), "type": "event" } }, "track": { "data": { "id": str(track.id), "type": "track" } }, }, } }) response = client.post( '/v1/sessions', content_type='application/vnd.api+json', headers=jwt, data=data, ) db.session.refresh(session) assert response.status_code == 422 assert json.loads(response.data) == { 'errors': [{ 'detail': "Missing required fields ['best_friend', 'slides_url']", 'source': { 'pointer': '/data/attributes' }, 'status': 422, 'title': 'Unprocessable Entity', }], 'jsonapi': { 'version': '1.0' }, } assert session.title != 'Move Away' assert session.subtitle != 'Moooove' assert session.language is None
def test_create_session_required_fields_complete(db, client, user, jwt): session = get_simple_custom_form_session(db, user) track = TrackSubFactory(event=session.event) db.session.commit() data = json.dumps({ 'data': { 'type': 'session', "attributes": { "title": "Move Away", "subtitle": "Moooove", "level": "Expert", "short-abstract": "Speaking since birth", "complex-field-values": { "bojack": "horseman" }, # Should be ignored and saved as None }, "relationships": { "event": { "data": { "id": str(session.event_id), "type": "event" } }, "track": { "data": { "id": str(track.id), "type": "track" } }, }, } }) response = client.post( '/v1/sessions', content_type='application/vnd.api+json', headers=jwt, data=data, ) assert response.status_code == 201 session = Session.query.get(json.loads(response.data)['data']['id']) assert session.title == 'Move Away' assert session.subtitle == 'Moooove' assert session.level == 'Expert' assert session.short_abstract == 'Speaking since birth' assert session.complex_field_values is None
def test_custom_form_create_complex_fields_complete(db, client, user, jwt): session = get_complex_custom_form_session(db, user) track = TrackSubFactory(event=session.event) db.session.commit() data = json.dumps({ 'data': { 'type': 'session', "attributes": { "title": "Move Away", "subtitle": "Moooove", "slides-url": "http://gypsie.com", "complex-field-values": { "best-friend": "Tester" }, }, "relationships": { "event": { "data": { "id": str(session.event_id), "type": "event" } }, "track": { "data": { "id": str(track.id), "type": "track" } }, }, } }) response = client.post( '/v1/sessions', content_type='application/vnd.api+json', headers=jwt, data=data, ) session = Session.query.get(json.loads(response.data)['data']['id']) assert response.status_code == 201 assert session.title == 'Move Away' assert session.subtitle == 'Moooove' assert session.slides_url == 'http://gypsie.com' assert session.complex_field_values['best_friend'] == 'Tester'