Exemplo n.º 1
0
    def test_update_domain_aoi(self, access_token_first, user_first,
                               domain_aois):
        """
        Test: Update domain's area of interest's description by providing aoi ID via the url
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        aoi_id = domain_aois[0].id
        update_data = {
            "areas_of_interest": [{
                "description": str(uuid.uuid4())[:5]
            }]
        }

        # Update area of interest's description
        update_resp = send_request(self.METHOD, AOI_URL % aoi_id,
                                   access_token_first, update_data)
        print response_info(update_resp)
        assert update_resp.status_code == requests.codes.OK
        assert update_resp.json()['areas_of_interest'][0]['id'] == aoi_id

        # Retrieve area of interest & assert its description has been updated
        get_resp = send_request('get', AOI_URL % aoi_id, access_token_first)
        print response_info(get_resp)
        assert get_resp.status_code == requests.codes.OK
        assert get_resp.json(
        )['area_of_interest']['description'] == update_data[
            'areas_of_interest'][0]['description']
Exemplo n.º 2
0
    def test_update_domain_aoi_with_empty_description_field(
            self, access_token_first, user_first, domain_aois):
        """
        Test: Update domain aoi without providing the description field
        Expect: 400; description is required
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        aoi_id = domain_aois[0].id

        # Update with description field set to None
        update_data_1 = {"areas_of_interest": [{"description": None}]}
        updated_resp = send_request(self.METHOD, AOI_URL % aoi_id,
                                    access_token_first, update_data_1)
        print response_info(updated_resp)
        assert updated_resp.status_code == requests.codes.BAD

        # Update with description field set to empty string
        update_data_2 = {"areas_of_interest": [{"description": ""}]}
        updated_resp = send_request(self.METHOD, AOI_URL % aoi_id,
                                    access_token_first, update_data_2)
        print response_info(updated_resp)
        assert updated_resp.status_code == requests.codes.BAD

        # Update with description field set whitespaces
        update_data_3 = {"areas_of_interest": [{"description": "    "}]}
        updated_resp = send_request(self.METHOD, AOI_URL % aoi_id,
                                    access_token_first, update_data_3)
        print response_info(updated_resp)
        assert updated_resp.status_code == requests.codes.BAD
Exemplo n.º 3
0
    def test_add_aois_with_empty_description_field(self, access_token_first,
                                                   user_first):
        """
        Test: Attempt to add area of interest with empty (None or empty string) value for description field
        Expect: 400; description field is required
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        # data with description's value set to None
        data_1 = dict(areas_of_interest=[dict(description=None)])
        resp = send_request(self.METHOD, AOIS_URL, access_token_first, data_1)
        print response_info(resp)
        assert resp.status_code == requests.codes.BAD

        # data with description's value set to an empty string
        data_2 = dict(areas_of_interest=[dict(description="")])
        resp = send_request(self.METHOD, AOIS_URL, access_token_first, data_2)
        print response_info(resp)
        assert resp.status_code == requests.codes.BAD

        # data with description's value set to whitespaces
        data_3 = dict(areas_of_interest=[dict(description="           ")])
        resp = send_request(self.METHOD, AOIS_URL, access_token_first, data_3)
        print response_info(resp)
        assert resp.status_code == requests.codes.BAD
Exemplo n.º 4
0
    def test_update_custom_field_by_id(self, user_first, access_token_first,
                                       domain_custom_fields):
        """
        Test: Update domain custom field by ID
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        custom_field_id = domain_custom_fields[0].id

        # Update custom field by id
        data = {
            'custom_field': {
                'id': domain_custom_fields[0].id,
                'name': str(uuid.uuid4())[:5]
            }
        }
        update_resp = send_request('put', self.CF_URL % custom_field_id,
                                   access_token_first, data)
        print response_info(update_resp)
        assert update_resp.status_code == requests.codes.OK
        assert update_resp.json()['custom_field']['id'] == custom_field_id

        # Retrieve custom field and assert on its updated name
        get_resp = send_request('get', self.CF_URL % custom_field_id,
                                access_token_first)
        print response_info(get_resp)
        assert get_resp.status_code == requests.codes.OK
        assert get_resp.json(
        )['custom_field']['name'] != domain_custom_fields[0].name
        assert get_resp.json(
        )['custom_field']['name'] == data['custom_field']['name']
Exemplo n.º 5
0
    def test_add_existing_aoi_to_domain(self, access_token_first, domain_aois,
                                        user_first):
        """
        Test: Attempt to an aoi to domain that already exists
        Expect: 400
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        # Necessary data for test case
        existing_aoi_description = domain_aois[0].name
        data = dict(
            areas_of_interest=[dict(description=existing_aoi_description)])

        create_resp = send_request(self.METHOD, AOIS_URL, access_token_first,
                                   data)
        json_resp = create_resp.json()
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.BAD

        # AOI ID must be provided in error response
        assert 'id' in json_resp['error']
        existing_aoi_id = json_resp['error']['id']
        assert existing_aoi_id == domain_aois[0].id

        # Retrieving AOI using the provided ID from the error response should work
        get_resp = send_request('get', AOI_URL % existing_aoi_id,
                                access_token_first)
        print response_info(get_resp)
        assert get_resp.status_code == requests.codes.OK
        assert get_resp.json(
        )['area_of_interest']['domain_id'] == domain_aois[0].domain_id
        assert get_resp.json(
        )['area_of_interest']['description'] == existing_aoi_description
Exemplo n.º 6
0
    def test_add_duplicate_source_in_same_domain(self, user_first, access_token_first):
        """
        Test:  Add same source in the same domain
        """
        # Create source
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()
        data = dict(source=dict(description='job fair', notes='recruited initials: ahb'))
        send_request('post', self.URL, access_token_first, data)

        # Create same source in same domain again
        create_resp = send_request('post', self.URL, access_token_first, data)
        print response_info(create_resp)
        assert create_resp.status_code == self.INVALID
Exemplo n.º 7
0
 def test_delete_custom_fields_without_access_token(self):
     """
     Test:  Access end point without an access token
     """
     del_resp = send_request('delete', self.CFS_URL, None)
     print response_info(del_resp)
     assert del_resp.status_code == requests.codes.UNAUTHORIZED
Exemplo n.º 8
0
    def test_update_domains_custom_fields(self, access_token_first, user_first,
                                          domain_custom_fields):
        """
        Test:  Update domain custom fields
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        # Update all of domain's custom fields
        data = {
            'custom_fields': [{
                'id': domain_custom_fields[0].id,
                'name': str(uuid.uuid4())[:5]
            }, {
                'id': domain_custom_fields[1].id,
                'name': str(uuid.uuid4())[:5]
            }]
        }
        update_resp = send_request('put', self.CFS_URL, access_token_first,
                                   data)
        print response_info(update_resp)
        assert update_resp.status_code == requests.codes.OK

        created_cfs = update_resp.json()['custom_fields']
        domain_cf_ids = [cf.id for cf in domain_custom_fields]

        assert len(created_cfs) == len(data['custom_fields'])
        assert len([
            cf['id'] for cf in created_cfs if cf['id'] in domain_cf_ids
        ]) == len(data['custom_fields'])
Exemplo n.º 9
0
    def test_get_source(self, user_first, access_token_first):
        """
        Test: Get a source from user's domain by providing source's ID
        """
        # Create source
        user_first.role_id = Role.get_by_name('TALENT_ADMIN').id
        db.session.commit()
        data = dict(source=dict(description='job fair', notes='recruited initials: ahb'))
        create_resp = send_request('post', self.URL, access_token_first, data)

        # Retrieve source
        source_id = create_resp.json()['source']['id']
        get_resp = send_request('get', self.URL_PLUS_ID % source_id, access_token_first)
        print response_info(get_resp)
        assert get_resp.status_code == self.OK
        assert isinstance(get_resp.json()['source'], dict)
Exemplo n.º 10
0
    def test_update_domain_aois(self, access_token_first, user_first,
                                domain_aois):
        """
        Test: Update domain's areas of interest in bulk
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        aoi_1_id, aoi_2_id = domain_aois[0].id, domain_aois[1].id
        update_data = {
            'areas_of_interest': [{
                "id": aoi_1_id,
                "description": str(uuid.uuid4())[:5]
            }, {
                "id": aoi_2_id,
                "description": str(uuid.uuid4())[:5]
            }]
        }
        update_resp = send_request(self.METHOD, AOIS_URL, access_token_first,
                                   update_data)
        print response_info(update_resp)
        assert update_resp.status_code == requests.codes.OK
        assert len(update_resp.json()['areas_of_interest']) == len(
            update_data['areas_of_interest'])
        for data in update_resp.json()['areas_of_interest']:
            assert data['id'] in [aoi_1_id, aoi_2_id]
Exemplo n.º 11
0
 def test_add_source_without_access_token(self):
     """
     Test:  Unauthenticated user accessing source endpoint
     :return:
     """
     create_resp = send_request('post', self.URL, None, {})
     print response_info(create_resp)
     assert create_resp.status_code == self.UNAUTHORIZED
Exemplo n.º 12
0
 def test_add_custom_fields_without_access_token(self, user_first):
     """
     Test:  Access end point without an access token
     """
     user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
     db.session.commit()
     resp = send_request('post', self.URL, None, {})
     print response_info(resp)
     assert resp.status_code == requests.codes.UNAUTHORIZED
Exemplo n.º 13
0
 def test_get_an_aoi_belonging_to_a_diff_domain(self, access_token_second,
                                                domain_aois):
     """
     Test: Get area of interest of a different domain
     Expect: 403
     """
     aoi_id = domain_aois[0].id
     get_resp = send_request(self.METHOD, AOI_URL % aoi_id,
                             access_token_second)
     print response_info(get_resp)
     assert get_resp.status_code == requests.codes.FORBIDDEN
Exemplo n.º 14
0
 def test_get_domain_aois(self, user_first, access_token_first,
                          domain_aois):
     """
     Test: Get all of domain's areas of interest
     """
     number_of_aois_in_domain = len(domain_aois)
     get_resp = send_request(self.METHOD, AOIS_URL, access_token_first)
     print response_info(get_resp)
     assert get_resp.status_code == requests.codes.OK
     assert len(
         get_resp.json()['areas_of_interest']) == number_of_aois_in_domain
Exemplo n.º 15
0
    def test_get_domain_sources(self, user_first, access_token_first):
        """
        Test: Get all domain's sources
        """
        # Create some sources
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()
        number_of_sources_created = random.randrange(2, 8)
        for _ in range(number_of_sources_created):
            send_request(method='post', url=self.URL, access_token=access_token_first,
                         data=dict(source=dict(description=str(uuid.uuid4())[:5])))

        user_first.role_id = Role.get_by_name('USER').id
        db.session.commit()
        # Retrieve all sources in user's domain
        get_resp = send_request('get', self.URL, access_token_first)
        print response_info(get_resp)
        assert get_resp.status_code == self.OK
        assert isinstance(get_resp.json()['sources'], list)
        assert len(get_resp.json()['sources']) == number_of_sources_created
Exemplo n.º 16
0
 def test_add_source_to_domain(self, user_first, access_token_first):
     """
     Test: Add a source to domain
     """
     user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
     db.session.commit()
     data = dict(source=dict(description='job fair', notes='recruited initials: ahb'))
     create_resp = send_request('post', self.URL, access_token_first, data)
     print response_info(create_resp)
     assert create_resp.status_code == self.CREATED
     assert 'id' in create_resp.json()['source']
Exemplo n.º 17
0
 def test_add_custom_fields_with_whitespaced_name(self, access_token_first,
                                                  user_first):
     """
     Test: Attempt to create a custom field with empty
     """
     user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
     db.session.commit()
     data = {'custom_fields': [{'name': '   '}]}
     create_resp = send_request('post', self.URL, access_token_first, data)
     print response_info(create_resp)
     assert create_resp.status_code == requests.codes.BAD
Exemplo n.º 18
0
    def test_update_non_existing_aoi(self, access_token_first, user_first):
        """
        Test: Attempt to update an area of interest that doesn't exist
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        update_data = {'areas_of_interest': [{'description': fake.word()}]}
        updated_resp = send_request(self.METHOD, AOI_URL % MAX_INT,
                                    access_token_first, update_data)
        print response_info(updated_resp)
        assert updated_resp.status_code == requests.codes.NOT_FOUND
Exemplo n.º 19
0
    def test_delete_non_existing_aoi(self, access_token_first, user_first):
        """
        Test: Attempt to delete area of interest that doesn't exist
        Expect: 404
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        del_resp = send_request(self.METHOD, AOI_URL % MAX_INT,
                                access_token_first)
        print response_info(del_resp)
        assert del_resp.status_code == requests.codes.NOT_FOUND
Exemplo n.º 20
0
 def test_add_aois_without_access_token(self, user_first):
     """
     Test: access domain aois resource without access token
     Expect: 401
     """
     user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
     db.session.commit()
     resp = send_request(method=self.METHOD,
                         url=AOIS_URL,
                         access_token=None,
                         data=None)
     print response_info(resp)
     assert resp.status_code == requests.codes.UNAUTHORIZED
Exemplo n.º 21
0
    def test_delete_domain_aois(self, access_token_first, user_first,
                                domain_aois):
        """
        Test: Delete all of domain's AOIS
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        domain_aoi_ids = [aoi.id for aoi in domain_aois]

        # Delete all of domain's AOIS
        del_resp = send_request(self.METHOD, AOIS_URL, access_token_first)
        print response_info(del_resp)
        assert del_resp.status_code == requests.codes.OK
        assert len(del_resp.json()['areas_of_interest']) == len(domain_aois)
        assert set([aoi['id'] for aoi in del_resp.json()['areas_of_interest']
                    ]) == set(domain_aoi_ids)

        # Domain AOIS should not exists in db anymore
        get_resp = send_request('get', AOIS_URL, access_token_first)
        print response_info(get_resp)
        assert get_resp.json()['areas_of_interest'] == []
Exemplo n.º 22
0
    def test_get_non_existing_custom_field(self, user_first,
                                           access_token_first):
        """
        Test: Retrieve custom field using an id that is not recognized
        """
        user_first.role_id = Role.get_by_name('USER').id
        db.session.commit()

        non_existing_cf_id = sys.maxint

        get_resp = send_request('get', self.CF_URL % non_existing_cf_id,
                                access_token_first)
        print response_info(get_resp)
        assert get_resp.status_code == requests.codes.NOT_FOUND
Exemplo n.º 23
0
    def test_delete_non_existing_custom_field(self, user_first,
                                              access_token_first):
        """
        Test: Delete custom field using an ID that is not recognized
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        non_existing_cf_id = sys.maxint

        del_resp = send_request('delete', self.CF_URL % non_existing_cf_id,
                                access_token_first)
        print response_info(del_resp)
        assert del_resp.status_code == requests.codes.NOT_FOUND
Exemplo n.º 24
0
    def test_delete_another_domains_aoi(self, access_token_second, user_second,
                                        domain_aois):
        """
        Test: Attempt to delete area of interest of another domain
        Expect: 403; no aoi should be deleted
        """
        user_second.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        aoi_id = domain_aois[0].id
        del_resp = send_request(self.METHOD, AOI_URL % aoi_id,
                                access_token_second)
        print response_info(del_resp)
        assert del_resp.status_code == requests.codes.FORBIDDEN
Exemplo n.º 25
0
 def test_get_a_specified_aoi(self, access_token_first, domain_aois):
     """
     Test: Get area of interest by providing its ID
     """
     aoi_id = domain_aois[0].id
     get_resp = send_request(self.METHOD, AOI_URL % aoi_id,
                             access_token_first)
     print response_info(get_resp)
     assert get_resp.status_code == requests.codes.OK
     assert get_resp.json(
     )['area_of_interest']['domain_id'] == domain_aois[0].domain_id
     assert get_resp.json()['area_of_interest']['id'] == aoi_id
     assert get_resp.json(
     )['area_of_interest']['description'] == domain_aois[0].name
Exemplo n.º 26
0
    def test_update_non_existing_custom_field(self, user_first,
                                              access_token_first):
        """
        Test: Update custom field using an id that is not recognized
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        non_existing_cf_id = sys.maxint

        data = {'custom_field': {'name': str(uuid.uuid4())[:5]}}
        update_resp = send_request('put', self.CF_URL % non_existing_cf_id,
                                   access_token_first, data)
        print response_info(update_resp)
        assert update_resp.status_code == requests.codes.NOT_FOUND
Exemplo n.º 27
0
    def test_get_custom_field_of_another_domain(self, access_token_second,
                                                domain_custom_fields):
        """
        Test: Retrieve custom fields of another domain
        """
        user_first.role_id = Role.get_by_name('USER').id
        db.session.commit()

        custom_field_id = domain_custom_fields[0].id

        # Retrieve another domain's custom field
        get_resp = send_request('get', self.CF_URL % custom_field_id,
                                access_token_second)
        print response_info(get_resp)
        assert get_resp.status_code == requests.codes.FORBIDDEN
Exemplo n.º 28
0
    def test_add_aois_to_domain(self, access_token_first, user_first):
        """
        Test: Add areas of interest to users' domain
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        create_resp = send_request(self.METHOD, AOIS_URL, access_token_first,
                                   DATA)
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.CREATED
        assert len(create_resp.json()['areas_of_interest']) == len(
            DATA['areas_of_interest'])
        assert all(
            [aoi.get('id') for aoi in create_resp.json()['areas_of_interest']])
Exemplo n.º 29
0
    def test_add_custom_field_to_domain_with_role_user(self,
                                                       access_token_first,
                                                       user_first):
        """
        Test:  Add custom fields to domain with role user
        Expect: 401, Unauthorized
        """
        user_first.update(role_id=Role.get_by_name('USER').id)

        # Create domain custom field
        data = {'custom_fields': [{'name': fake.uuid4()}]}
        create_resp = send_request('post', self.URL, access_token_first, data)
        print response_info(create_resp)

        assert create_resp.status_code == requests.codes.UNAUTHORIZED
Exemplo n.º 30
0
    def test_add_duplicate_custom_fields_to_domain(self, access_token_first,
                                                   user_first):
        """
        Test:  Add identical custom fields to the same domain
        Expect:  201, but only one should be created
        """
        user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
        db.session.commit()

        name = str(uuid.uuid4())[:5]
        data = {'custom_fields': [{'name': name}, {'name': name}]}

        # Create domain custom fields
        create_resp = send_request('post', self.URL, access_token_first, data)
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.BAD