예제 #1
0
def event_data_tests(method, url, data, token):
    """

    :param method:
    :param url:
    :param data:
    :param token:
    :return:
    """
    event = data.copy()

    # Update with invalid event id
    event['id'] = 231232132133  # We will find a better way to test it
    response = send_request(method, url, token, data=event)
    # response = send_post_request(SocialNetworkApiUrl.EVENT % event['id'],
    #                              event, token)
    logger.info(response.text)
    assert response.status_code == 404, 'Event not found with this id'

    # Update with invalid social network event id
    event = data.copy()
    event['social_network_event_id'] = -1
    response = send_request(method, url, token, data=event)
    logger.info(response.text)
    assert response.status_code == 404, 'Event not found with this social network event id'

    event = data.copy()

    # success case, event should be updated
    datetime_now = datetime.datetime.now()
    event['title'] = 'Test update event'
    event['start_datetime'] = (
        datetime_now +
        datetime.timedelta(days=50)).strftime('%Y-%m-%dT%H:%M:%SZ')
    event['end_datetime'] = (
        datetime_now +
        datetime.timedelta(days=60)).strftime('%Y-%m-%dT%H:%M:%SZ')
    response = send_request(method, url, token, data=event)
    logger.info(response.text)
    assert response.status_code == 200, 'Status should be Ok, Resource Modified (204)'
    event_db = Event.get_by_id(event['id'])
    Event.session.commit(
    )  # needed to refresh session otherwise it will show old objects
    event_db = event_db.to_json()
    assert event['title'] == event_db['title'], 'event_title is modified'
    assert event['start_datetime'] == event_db['start_datetime'].replace(' ', 'T') + 'Z', \
        'start_datetime is modified'
    assert event['end_datetime'] == event_db['end_datetime'].replace(' ', 'T') + 'Z', \
        'end_datetime is modified'
예제 #2
0
    def test_put_with_valid_token(self, token_first, new_event_in_db_second):
        """
        - Get event data from db (using fixture - event_in_db)
        - Using event id, send PUT request to update event data
        - Should get 200 response
        - Check if activity is created or not
        """
        event = copy.deepcopy(new_event_in_db_second)
        # Success case, event should be updated
        datetime_now = datetime.datetime.utcnow()
        datetime_now = datetime_now.replace(microsecond=0)
        event['title'] = 'Test update event'
        event['start_datetime'] = (datetime_now +
                                   datetime.timedelta(days=50)).strftime(
                                       DatetimeUtils.ISO8601_FORMAT)
        event['end_datetime'] = (datetime_now +
                                 datetime.timedelta(days=60)).strftime(
                                     DatetimeUtils.ISO8601_FORMAT)
        response = send_request('put',
                                SocialNetworkApiUrl.EVENT % event['id'],
                                token_first,
                                data=event)
        logger.info(response.text)
        assert response.status_code == codes.OK, '{} {}'.format(
            response.text, event)
        db.db.session.commit()
        event_occurrence_in_db = Event.get_by_id(event['id'])
        Event.session.commit(
        )  # needed to refresh session otherwise it will show old objects
        event_occurrence_in_db = event_occurrence_in_db.to_json()
        assert event['title'] == event_occurrence_in_db[
            'title'], 'event_title is modified'
        assert event['start_datetime'].split('.')[0] + 'Z' == event_occurrence_in_db['start_datetime'] \
                                                                  .replace(' ', 'T') + 'Z', \
            'start_datetime is modified'
        assert (event['end_datetime']).split('.')[0] + 'Z' == event_occurrence_in_db['end_datetime'] \
                                                                  .replace(' ', 'T') + 'Z', \
            'end_datetime is modified'

        # Check activity updated
        CampaignsTestsHelpers.assert_for_activity(
            event_occurrence_in_db['user_id'],
            Activity.MessageIds.EVENT_UPDATE, event['id'])
        activity = Activity.get_by_user_id_type_source_id(
            user_id=event_occurrence_in_db['user_id'],
            source_id=event['id'],
            type_=Activity.MessageIds.EVENT_UPDATE)
        data = json.loads(activity.params)
        assert data['event_title'] == event['title']