def sample_get_projects(): url = os.environ.get('FLN_URL') oauth_token = os.environ.get('FLN_OAUTH_TOKEN') session = Session(oauth_token=oauth_token, url=url) query = create_get_projects_object( project_ids=[ 201, 202, 203, ], project_details=create_get_projects_project_details_object( full_description=True, jobs=True, qualifications=True, ), user_details=create_get_projects_user_details_object( basic=True, profile_description=True, reputation=True, ), ) try: p = get_projects(session, query) except ProjectsNotFoundException as e: print('Error message: {}'.format(e.message)) print('Server response: {}'.format(e.error_code)) return None else: return p
def test_create_get_projects_object(self): query = create_get_projects_object( project_ids=[ 201, 202, 203, ], project_details=create_get_projects_project_details_object( full_description=True, ), user_details=create_get_projects_user_details_object(basic=True, ), ) self.assertIn(('projects[]', [201, 202, 203]), query.items())
def test_get_project_by_id(self): project_id = 2 project_details = create_get_projects_project_details_object( full_description=True, ) params = { 'full_description': True, } self.session.session.get = Mock() self.session.session.get.return_value = FakeGetProjectsByIdGetResponse( ) get_project_by_id(self.session, project_id, project_details) self.session.session.get.assert_called_once_with( 'https://fake-fln.com/api/projects/0.1/projects/{}/'.format( project_id), params=params, verify=True)
def test_get_projects(self): query = create_get_projects_object( project_ids=[ 201, 202, 203, ], project_details=create_get_projects_project_details_object( full_description=True, ), user_details=create_get_projects_user_details_object(basic=True, ), ) self.session.session.get = Mock() self.session.session.get.return_value = FakeGetProjectsGetResponse() get_projects(self.session, query) self.session.session.get.assert_called_once_with( 'https://fake-fln.com/api/projects/0.1/projects/', params=query, verify=True)
def sample_get_project_by_id(): url = os.environ.get('FLN_URL') oauth_token = os.environ.get('FLN_OAUTH_TOKEN') session = Session(oauth_token=oauth_token, url=url) project_id = 15389177 project_details = create_get_projects_project_details_object( full_description=True) user_details = create_get_projects_user_details_object(basic=True) try: p = get_project_by_id(session, project_id, project_details, user_details) except ProjectsNotFoundException as e: print('Error message: {}'.format(e.message)) print('Server response: {}'.format(e.error_code)) return None else: return p
def test_get_project_by_id_error(self): project_id = 2 project_details = create_get_projects_project_details_object( full_description=True, ) params = { 'full_description': True, } response = FakeErrorResponse() self.session.session.get = Mock() self.session.session.get.return_value = response with self.assertRaises(ProjectsNotFoundException) as cm: get_project_by_id(self.session, project_id, project_details) e = cm.exception self.assertEqual(str(e), response.json()['message']) self.assertEqual(e.request_id, response.json()['request_id']) self.assertEqual(e.error_code, response.json()['error_code'])
def test_search_projects(self): query = 'logo design' limit = 3 offset = 0 query_data = { 'query': query, 'limit': limit, 'offset': offset, } search_filter = create_search_projects_filter( sort_field='time_updated', or_search_query=True, ) project_details = create_get_projects_project_details_object( jobs=True, ) user_details = create_get_projects_user_details_object(basic=True, ) query_data.update(search_filter) query_data.update(project_details) query_data.update(user_details) self.session.session.get = Mock() self.session.session.get.return_value = FakeSearchProjectsGetResponse() p = search_projects( self.session, query=query, search_filter=search_filter, project_details=project_details, user_details=user_details, limit=limit, offset=offset, ) self.session.session.get.assert_called_once_with( 'https://fake-fln.com/api/projects/0.1/projects/all/', params=query_data, verify=True) self.assertEquals(len(p['projects']), query_data['limit'])