예제 #1
0
    def test_events_post_with_valid_token(self, token_first, test_event):
        """
        Post event and it should create an event with 201 response
        """
        event_data = test_event

        # Success case
        response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                     token_first)
        logger.info(response.text)
        assert response.status_code == codes.CREATED, 'Status should be Ok, Resource Created (201)'
        event_id = response.json()['id']
        db.db.session.commit()
        CampaignsTestsHelpers.assert_for_activity(
            event_data['user_id'], Activity.MessageIds.EVENT_CREATE, event_id)
        activities = Activity.get_by_user_id_type_source_id(
            user_id=event_data['user_id'],
            source_id=event_id,
            type_=Activity.MessageIds.EVENT_CREATE)
        data = json.loads(activities.params)
        assert data['event_title'] == event_data['title']

        assert event_id > 0, 'Event id should be a positive number'
        test_event[
            'id'] = event_id  # Add created event id  in test_event so it can be deleted in tear_down
예제 #2
0
 def test_events_post_with_invalid_token(self):
     """
     Post event using invalid token and response should be 401 (unauthorized user)
     """
     response = send_post_request(SocialNetworkApiUrl.EVENTS, {},
                                  'invalid_token')
     logger.info(response.text)
     assert response.status_code == codes.UNAUTHORIZED, 'It should be unauthorized (401)'
     assert 'events' not in response.json()
예제 #3
0
def create_event(token, event_data, title, start_datetime):
    end_datetime = start_datetime + timedelta(hours=3)
    data = dict(
        title=title,
        start_datetime=start_datetime.strftime(DatetimeUtils.ISO8601_FORMAT),
        end_datetime=end_datetime.strftime(DatetimeUtils.ISO8601_FORMAT))
    event_data.update(data)
    response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data, token)
    logger.info(response.text)
    assert response.status_code == codes.CREATED, response.text
예제 #4
0
 def test_meetup_with_invalid_address(self, token_first, meetup_event_data,
                                      test_meetup_credentials):
     """
     Send post request with invalid meetup_event data (change venue_id) and response should be 404 with error code
     4065 (Address invalid)
     """
     event_data = meetup_event_data
     event_data['venue_id'] = -1
     response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                  token_first)
     logger.info(response.text)
     assert response.status_code == codes.NOT_FOUND, 'Venue not Found in database'
예제 #5
0
 def test_meetup_with_valid_address(self, token_first, meetup_event_data,
                                    test_meetup_credentials):
     """
     Send Post request with meetup_event data and response should be 201 (event created)
     """
     event_data = meetup_event_data
     response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                  token_first)
     logger.info(response.text)
     assert response.status_code == codes.CREATED, 'Event should be created, address is valid'
     event_id = response.json()['id']
     meetup_event_data['id'] = event_id
예제 #6
0
 def test_eventbrite_with_missing_required_fields(
         self, token_first, eventbrite_missing_data,
         test_eventbrite_credentials):
     """
     Post event data with missing required keys and response should be 400 (4053 - Missing Keys)
     """
     key, event_data = eventbrite_missing_data
     event_data[key] = ''
     response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                  token_first)
     logger.info(response.text)
     assert response.status_code == codes.BAD, 'It should fail'
     response = response.json()
     assert response['error']['code'] == EventInputMissing.error_code, \
         'There should be an missing field error for %s KeyError' % key
예제 #7
0
    def test_events_post_with_invalid_social_network_id(
            self, token_first, test_event):
        """
        Post event using invalid social_network_id i.e equal to -1. response should be 500 with 4052 error code
        (Social Network not found)
        """
        event_data = test_event

        # test with a social network that does not exists
        event_data['social_network_id'] = -1
        response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                     token_first)
        logger.info(response.text)
        assert response.status_code == codes.INTERNAL_SERVER_ERROR
        response = response.json()
        assert 'error' in response and response['error']['code'] == SocialNetworkError.error_code, \
            'Social Network not found'
예제 #8
0
    def test_events_post_no_venue(self, token_first, test_event):
        """
        Post event using invalid venue_id i.e equal to -1. response should be 404 with 4065 error code
        (Venue not found)
        """
        event_data = test_event
        social_network_id = event_data['social_network_id']
        event_data['social_network_id'] = social_network_id

        # test with invalid venue
        event_data['venue_id'] = sys.maxint
        response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                     token_first)
        logger.info(response.text)
        assert response.status_code == codes.NOT_FOUND
        response = response.json()
        assert 'error' in response and response['error'][
            'code'] == VenueNotFound.error_code, 'Venue not found'
예제 #9
0
    def test_events_post_no_event_implementation(self, token_first,
                                                 test_event):
        """
        Post event using invalid social_network_id i.e equal to 1. response should be 500 with 4062 error code
        (Social Network have no events implementations)
        """
        event_data = test_event

        # test social network which have no implementation for events
        event_data['social_network_id'] = 1
        response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                     token_first)
        logger.info(response.text)
        assert response.status_code == codes.INTERNAL_SERVER_ERROR
        response = response.json()

        assert 'error' in response and response['error']['code'] == SocialNetworkNotImplemented.error_code, \
            'Social Network have no events implementation'
예제 #10
0
    def test_events_post_no_event_organizer(self, token_first, test_event):
        """
        Post event using invalid event_organizer i.e equal to -1. response should be 201
        (Event organizer not found)
            url -> localhost:8007/v1/events
        """
        event_data = test_event
        social_network_id = event_data['social_network_id']
        event_data['social_network_id'] = social_network_id
        social_network = SocialNetwork.get_by_id(social_network_id)

        # test with invalid organizer
        event_data['organizer_id'] = -1
        response = send_post_request(SocialNetworkApiUrl.EVENTS, event_data,
                                     token_first)
        logger.info(response.text)
        if social_network.name.lower() == MEETUP:
            assert response.status_code == codes.BAD_REQUEST, "Response: {}".format(
                response.text)
            return
        else:
            assert response.status_code == codes.CREATED, "Response: {}".format(
                response.text)