예제 #1
0
    def test_delete_with_valid_token(self, token_first,
                                     new_event_in_db_second):
        """
        - Try to delete event data using id, if deleted you expect 200 response
        - Then again try to delete event using same event id and expect 403 response
        """
        event_id = new_event_in_db_second['id']
        response = requests.delete(SocialNetworkApiUrl.EVENT % event_id,
                                   headers=auth_header(token_first))
        logger.info(response.text)
        assert response.status_code == codes.OK, str(response.text)
        response = requests.delete(SocialNetworkApiUrl.EVENT % event_id,
                                   headers=auth_header(token_first))

        # check if event delete activity
        user_id = new_event_in_db_second['user_id']
        db.db.session.commit()
        CampaignsTestsHelpers.assert_for_activity(
            user_id, Activity.MessageIds.EVENT_DELETE, event_id)
        activity = Activity.get_by_user_id_type_source_id(
            user_id=user_id,
            source_id=event_id,
            type_=Activity.MessageIds.EVENT_DELETE)
        assert activity, 'Activity not found'
        data = json.loads(activity.params)
        assert data['event_title'] == new_event_in_db_second['title']

        logger.info(response.text)
        assert response.status_code == codes.FORBIDDEN, 'Unable to delete event as it is not present there (403)'
예제 #2
0
def get_events_with_query(token,
                          search=None,
                          social_network_id=None,
                          sort_by=None,
                          sort_type=None,
                          user_id=None):
    url = SocialNetworkApiUrl.EVENTS
    if search:
        url += '?search=%s' % search
    if social_network_id:
        url += '?social_network_id=%s' % social_network_id if url.find('?') == -1 \
            else '&social_network_id=%s' % social_network_id
    if sort_by:
        url += '?sort_by=%s' % sort_by if url.find(
            '?') == -1 else '&sort_by=%s' % sort_by
    if sort_type:
        url += '?sort_type=%s' % sort_type if url.find(
            '?') == -1 else '&sort_type=%s' % sort_type
    if user_id:
        url += '?user_id=%s' % user_id if url.find(
            '?') == -1 else '&user_id=%s' % user_id
    response = requests.get(url, headers=auth_header(token))
    logger.info(response.text)
    assert response.status_code == codes.OK, 'Status should be Ok (200)'
    return response.json()['events']
예제 #3
0
 def test_match_event_organizer_fields(self, user_first, token_first,
                                       test_eventbrite_credentials):
     """
     Send POST request with valid event organizer data and response should be 201 (id in response content)
     Then get data from api and test if expected fields exist and have some data.
     """
     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']
     EventOrganizer.session.commit()
     response = requests.get(SocialNetworkApiUrl.EVENT_ORGANIZERS,
                             headers=auth_header(token_first))
     assert response.status_code == codes.OK
     results = response.json()
     assert 'event_organizers' in results
     assert len(results['event_organizers']) == 1
     match_event_organizer_fields(results['event_organizers'][0])
예제 #4
0
 def test_post_with_invalid_token(self):
     """
     Send POST request to create venue endpoint with invalid token in header and response should be 401 unauthorized
     """
     response = requests.post(SocialNetworkApiUrl.VENUES,
                              headers=auth_header('invalid_token'))
     logger.info(response.text)
     assert response.status_code == codes.UNAUTHORIZED, 'It should be unauthorized (401)'
예제 #5
0
 def test_get_with_invalid_token(self):
     """
     Send POST request with invalid_token in header and response should be 401 (unauthorized)
     """
     response = requests.post(SocialNetworkApiUrl.VENUES,
                              headers=auth_header('invalid_token'))
     logger.info(response.text)
     assert response.status_code == codes.UNAUTHORIZED, 'It should be unauthorized (401)'
     assert 'venues' not in response.json()
예제 #6
0
 def test_get_with_invalid_token(self):
     """
     Send GET request with invalid token in header and response should be un-authorize access
     """
     response = requests.post(SocialNetworkApiUrl.EVENT_ORGANIZERS,
                              headers=auth_header('invalid_token'))
     logger.info(response.text)
     assert response.status_code == codes.UNAUTHORIZED, 'It should be unauthorized (401)'
     assert 'organizers' not in response.json()
예제 #7
0
 def test_get_with_valid_token(self, token_first):
     """
     Send GET request to venues and response should be 200.
     """
     response = requests.get(SocialNetworkApiUrl.VENUES,
                             headers=auth_header(token_first))
     logger.info(response.text)
     assert response.status_code == codes.OK, 'Status should be Ok (200)'
     results = response.json()
     assert 'venues' in results
예제 #8
0
 def test_get_with_invalid_token(self):
     """
     - Try to get events using invalid access_token.
     - Expect 401 (unauthorized) in response
     """
     response = requests.get(SocialNetworkApiUrl.EVENTS,
                             headers=auth_header('invalid_token'))
     logger.info(response.text)
     assert response.status_code == codes.UNAUTHORIZED, 'It should be unauthorized (401)'
     assert 'events' not in response.json()
예제 #9
0
 def test_event_get_with_valid_token(self, token_second):
     """
     - Get events using valid access_token
     - As the test user is newly created. so, initially there will be no events
     """
     response = requests.get(SocialNetworkApiUrl.EVENTS,
                             headers=auth_header(token_second))
     logger.info(response.text)
     assert response.status_code == codes.OK, 'Status should be Ok (200)'
     events = response.json()['events']
     assert len(
         events) == 0, 'There shouldn\'t be some events for test user'
예제 #10
0
 def test_get_with_valid_token(self, token_first):
     """
     Send GET request with valid token in header and id. Response should be 200
     """
     response = requests.get(SocialNetworkApiUrl.EVENT_ORGANIZERS,
                             headers=auth_header(token_first))
     logger.info(response.text)
     # to most messages we placed on RHS of asserts
     assert response.status_code == codes.OK, "Response: {}".format(
         response.text)
     results = response.json()
     assert 'event_organizers' in results
예제 #11
0
 def test_match_venue_fileds(self, token_first, venue_in_db_second):
     """
     Creates venue for social network events, send GET request to venues and test if expected
     fields exist in response from api.
     """
     response = requests.get(SocialNetworkApiUrl.VENUE %
                             venue_in_db_second['id'],
                             headers=auth_header(token_first))
     logger.info(response.text)
     assert response.status_code == codes.OK, 'Status should be Ok (200)'
     results = response.json()
     assert 'venue' in results
     assert len(results) == 1
     match_venue_fields(results['venue'])
예제 #12
0
 def test_events_get_with_valid_token(self, token_first,
                                      event_in_db_second):
     """
     event_in_db fixture creates an event entry in db. So, when request is made, it should return that created event
     for test user
     """
     response = requests.get(SocialNetworkApiUrl.EVENTS,
                             headers=auth_header(token_first))
     logger.info(response.text)
     assert response.status_code == codes.OK, 'Status should be Ok (200)'
     events = response.json()['events']
     assert len(events) >= 1, 'There should be some events for test user'
     for event in events:
         match_event_fields(event)
예제 #13
0
 def test_events_get_in_domain_of_user(self, token_same_domain, event_in_db,
                                       event_in_db_second):
     """
     Here one user tries to get events in its domain. It should get 2 events created by some other user of
     same domain.
     """
     response = requests.get(SocialNetworkApiUrl.EVENTS,
                             headers=auth_header(token_same_domain))
     logger.info(response.text)
     assert response.status_code == codes.OK, 'Status should be Ok (200)'
     events = response.json()['events']
     assert len(
         events) >= 2, 'There should be 2 events for user of same domain'
     for event in events:
         match_event_fields(event)
예제 #14
0
    def test_get_by_id_with_valid_token(self, token_first, token_same_domain,
                                        event_in_db_second):
        """
        - Get event using id and response should be 200
        - Get event by some other user of same domain using id and response should be 200
        - Delete venue_id and organizer_id from event response data
        - Then compare values from the event data in db table and response event data
        """
        event = copy.deepcopy(event_in_db_second)
        for access_token in (token_first, token_same_domain):
            response = requests.get(SocialNetworkApiUrl.EVENT % event['id'],
                                    headers=auth_header(access_token))
            logger.info(response.text)
            assert response.status_code == codes.OK, "Response: {}".format(
                response.text)
            results = response.json()
            assert 'event' in results
            match_event_fields(results['event'])
            api_event = results['event']

            if event.get('venue_id'):
                del event['venue_id']
            if event.get('organizer_id') or event.get('organizer_id') == '':
                del event['organizer_id']
            comparison = '\n{0: <20}  |  {1: <40} |  {2: <40}\n'.format(
                'Key', 'Expected', 'Found')
            comparison += '=' * 100 + '\n'
            status = True
            for key, val in event.items():
                mismatch = ''
                if event[key] == api_event[key]:
                    mismatch = '**'
                comparison += '{0: <20}  {1}|  {2: <40} |  {3: <40}\n'.format(
                    key, mismatch, event[key], api_event[key])
                comparison += '-' * 100 + '\n'
                status = status and event[key] == api_event[key]

            assert status, 'Event values were not matched\n' + comparison