def test_post_with_same_organizer_name(self, token_first, user_first, test_eventbrite_credentials): """ Send POST request with valid event organizer data and response should be 201 but when we will try to create organizer with same name again, API will raise InvalidUsage 400 error. """ name = "organizer_%s" % fake.uuid4(), event_organizer = { "user_id": user_first['id'], "name": name, "email": "*****@*****.**", "about": "He is a testing engineer" } response = requests.post(SocialNetworkApiUrl.EVENT_ORGANIZERS, data=json.dumps(event_organizer), headers=get_headers(token_first)) logger.info(response.text) assert response.status_code == codes.CREATED, 'Status should be Ok, Resource created (201)' assert 'Location' in response.headers response = response.json() event_organizer_id = response['id'] assert event_organizer_id > 0 # Now try to create organizer with same name. It will raise 400 (InvalidUsage) response = requests.post(SocialNetworkApiUrl.EVENT_ORGANIZERS, data=json.dumps(event_organizer), headers=get_headers(token_first)) logger.info(response.text) assert response.status_code == codes.BAD, 'Status should be 400, InvalidUsage' EventOrganizer.session.commit() event_organizer = EventOrganizer.get_by_id(event_organizer_id) assert event_organizer, 'Event organizer not found in db' EventOrganizer.delete(event_organizer.id)
def delete(self, venue_id): """ This endpoint deletes one organizer owned by this user. :param int | long venue_id: venue id :Example: headers = { 'Authorization': 'Bearer <access_token>', 'Content-Type': 'application/json' } response = requests.delete( API_URL + '/organizers/1', headers=headers, ) .. Response:: { 'message': 'Organizer has been deleted successfully' } .. HTTP Status:: 200 (Resource Deleted) 404 (Not found) 500 (Internal Server Error) """ organizer = EventOrganizer.get_by_user_id_organizer_id( request.user.id, venue_id) if organizer: EventOrganizer.delete(organizer) return dict(message='Organizer has been deleted successfully') else: raise ResourceNotFound("Organizer not found")
def delete(self): """ This endpoint deletes one or more organizer owned by this user. :Example: organizers_ids = { 'ids': [1,2,3] } headers = { 'Authorization': 'Bearer <access_token>', 'Content-Type': 'application/json' } data = json.dumps(organizers_ids) response = requests.post( API_URL + '/event-organizers/', data=data, headers=headers, ) .. Response:: { 'message': '3 event organizers have been deleted successfully' } .. HTTP Status:: 200 (Resource Deleted) 207 (Not all deleted) 400 (Bad request) 500 (Internal Server Error) """ deleted, not_deleted = [], [] # Get json data from request req_data = get_valid_json_data(request) organizer_ids = req_data['ids'] if 'ids' in req_data and isinstance( req_data['ids'], list) else [] # If no organizer id is given, return 400 (Bad request) if organizer_ids: for _id in organizer_ids: organizer = EventOrganizer.get_by_user_id_organizer_id( request.user.id, _id) if organizer: EventOrganizer.delete(_id) deleted.append(_id) else: not_deleted.append(_id) if not not_deleted: return dict( message='%s event organizer(s) deleted successfully' % len(deleted)) return dict(message='Unable to delete %s event organizer(s)' % len(not_deleted), deleted=deleted, not_deleted=not_deleted), 207 else: raise InvalidUsage('Bad request, include ids as list data', error_code=400)
def test_post_with_valid_token(self, token_first, user_first, test_eventbrite_credentials): """ Send POST request with valid event organizer data and response should be 201 (id in response content) """ event_organizer = { "user_id": user_first['id'], "name": "organizer_%s" % fake.uuid4(), "email": "*****@*****.**", "about": "He is a testing engineer" } response = requests.post(SocialNetworkApiUrl.EVENT_ORGANIZERS, data=json.dumps(event_organizer), headers=get_headers(token_first)) logger.info(response.text) assert response.status_code == codes.CREATED, 'Status should be Ok, Resource created (201)' assert 'Location' in response.headers response = response.json() assert response['id'] > 0 EventOrganizer.session.commit() event_organizer = EventOrganizer.get_by_id(response['id']) assert event_organizer, 'Event organizer created successfully in db' EventOrganizer.delete(event_organizer.id)