Unverified Commit 36ba5d26 authored by Daniel's avatar Daniel Committed by GitHub

Cleanup test code for Amundsen People (#73)

parent 7b09a2fa
......@@ -555,32 +555,7 @@ def update_table_tags() -> Response:
return make_response(payload, HTTPStatus.INTERNAL_SERVER_ERROR)
# TODO: Implement real support
# TODO: Implement
@metadata_blueprint.route('/user', methods=['GET'])
def get_user() -> Response:
try:
user_id = get_query_param(request.args, 'user_id')
user_info = {
'first_name': 'Firstname',
'last_name': 'Lastname',
'email': 'test@test.com',
'display_name': 'Firstname Lastname',
'profile_url': 'https://github.com/lyft/amundsenfrontendlibrary',
'user_id': user_id,
'github_name': 'lyft',
'is_active': True,
'manager_name': 'Roald Amundsen',
'role_name': 'Software Engineer',
'slack_url': 'https://slack.com',
'team_name': 'Amundsen Team',
}
if user_id == 'alumni':
user_info['is_active'] = False
status_code = HTTPStatus.OK
payload = jsonify({'user': user_info})
return make_response(payload, status_code)
except Exception as e:
message = 'Encountered exception: ' + str(e)
logging.exception(message)
return make_response(jsonify({'user': {}, 'msg': message}), HTTPStatus.INTERNAL_SERVER_ERROR)
return make_response(jsonify({'msg': 'Not implemented'}), HTTPStatus.NOT_IMPLEMENTED)
......@@ -28,7 +28,7 @@ valid_search_fields = {
def _create_error_response(*, message: str, payload: Dict, status_code: int) -> Response:
logging.info(message)
payload['mg'] = message
payload['msg'] = message
return make_response(jsonify(payload), status_code)
......@@ -68,15 +68,7 @@ def search_table() -> Response:
@search_blueprint.route('/user', methods=['GET'])
def search_user() -> Response:
search_term = get_query_param(request.args, 'query', 'Endpoint takes a "query" parameter')
page_index = get_query_param(request.args, 'page_index', 'Endpoint takes a "page_index" parameter')
error_response = _validate_search_term(search_term=search_term, page_index=int(page_index))
if error_response is not None:
return error_response
results_dict = _search_user(search_term=search_term, page_index=page_index)
return make_response(jsonify(results_dict), results_dict.get('status_code', HTTPStatus.INTERNAL_SERVER_ERROR))
return make_response(jsonify({'msg': 'Not implemented'}), HTTPStatus.NOT_IMPLEMENTED)
def _create_url_with_field(*, search_term: str, page_index: int) -> str:
......@@ -157,68 +149,6 @@ def _search_user(*, search_term: str, page_index: int) -> Dict[str, Any]:
'users': users,
}
# TEST CODE
users['total_results'] = 3
users['results'] = [
{
'type': 'user',
'active': True,
'birthday': '10-10-2000',
'department': 'Department',
'email': 'mail@address.com',
'first_name': 'Ash',
'github_username': 'github_user',
'id': 12345,
'last_name': 'Ketchum',
'manager_email': 'manager_email',
'name': 'Ash Ketchum',
'offboarded': False,
'office': 'Kanto Region',
'role': 'Pokemon Trainer',
'start_date': '05-04-2016',
'team_name': 'Kanto Trainers',
'title': 'Pokemon Master',
},
{
'type': 'user',
'active': True,
'birthday': '06-01-2000',
'department': 'Department',
'email': 'mail@address.com',
'first_name': 'Gary',
'github_username': 'github_user',
'id': 12345,
'last_name': 'Oak',
'manager_email': 'manager_email',
'name': 'Gary Oak',
'offboarded': False,
'office': 'Kanto Region',
'role': 'Pokemon Trainer',
'start_date': '05-04-2016',
'team_name': 'Kanto Trainers',
'title': 'Pokemon Master',
},
{
'type': 'user',
'active': False,
'birthday': '06-01-60',
'department': 'Department',
'email': 'mail@address.com',
'first_name': 'Professor',
'github_username': 'github_user',
'id': 12345,
'last_name': 'Oak',
'manager_email': 'manager_email',
'name': 'Professor Oak',
'offboarded': False,
'office': 'Kanto Region',
'role': 'Scientist',
'start_date': '05-04-2016',
'team_name': 'Team Oak',
'title': 'Pokemon Researcher',
},
]
return results_dict
......
......@@ -70,11 +70,9 @@ export class NavBar extends React.Component<NavBarProps, NavBarState> {
})
}
{
// TODO PEOPLE - Add link to user profile
this.state.loggedInUser &&
// TODO PEOPLE - Uncomment when enabling people
//<Link to={`/user/${this.state.loggedInUser.user_id}`}>
<Avatar name={this.state.loggedInUser.display_name} size={32} round={true} />
//</Link>
}
</div>
</div>
......
......@@ -178,12 +178,7 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
key: ResourceType.table,
content: this.getTabContent(this.props.tables, 'tables'),
},
// TODO PEOPLE - Uncomment when enabling people
// {
// title: `Users (${ this.props.users.total_results })`,
// key: ResourceType.user,
// content: this.getTabContent(this.props.users, 'users'),
// },
// TODO PEOPLE - Add users tab
];
return (
......
......@@ -9,13 +9,11 @@ export function searchAll(action: SearchAllRequest) {
const { term, options } = action;
return axios.all([
axios.get(`${BASE_URL}/table?query=${term}&page_index=${options.tableIndex || 0}`),
// TODO PEOPLE - Uncomment when enabling People feature
// axios.get(`${BASE_URL}/user?query=${term}&page_index=${options.userIndex || 0}`),
]).then(axios.spread((tableResponse: AxiosResponse<SearchResponse> /*, userResponse: AxiosResponse<SearchResponse>*/) => {
// TODO PEOPLE - Add request for people here
]).then(axios.spread((tableResponse: AxiosResponse<SearchResponse>) => {
return {
search_term: tableResponse.data.search_term,
tables: tableResponse.data.tables,
// users: userResponse.data.users,
}
})).catch((error: AxiosError) => {
// TODO - handle errors
......
......@@ -200,71 +200,3 @@ class SearchTest(unittest.TestCase):
'/hive?page_index=1'
self.assertEqual(_create_url_with_field(search_term=search_term,
page_index=1), expected)
# ----- User Search Tests ---- #
def test_search_user_fail_if_no_query(self) -> None:
"""
Test request failure if 'query' is not provided in the query string
to the search endpoint
:return:
"""
with local_app.test_client() as test:
response = test.get('/api/search/v0/user', query_string=dict(page_index='0'))
self.assertEqual(response.status_code, HTTPStatus.INTERNAL_SERVER_ERROR)
def test_search_user_fail_if_no_page_index(self) -> None:
"""
Test request failure if 'page_index' is not provided in the query string
to the search endpoint
:return:
"""
with local_app.test_client() as test:
response = test.get('/api/search/v0/user', query_string=dict(query='test'))
self.assertEqual(response.status_code, HTTPStatus.INTERNAL_SERVER_ERROR)
# TODO - Uncomment test once the API is integrated
# @responses.activate
# def test_search_user_success(self) -> None:
# """
# Test request success
# :return:
# """
# responses.add(responses.GET, local_app.config['SEARCHSERVICE_ENDPOINT'],
# json=self.mock_search_table_results, status=HTTPStatus.OK)
#
# with local_app.test_client() as test:
# response = test.get('/api/search/v0/user', query_string=dict(query='test', page_index='0'))
# data = json.loads(response.data)
# self.assertEqual(response.status_code, HTTPStatus.OK)
#
# users = data.get('users')
# self.assertEqual(users.get('total_results'), self.mock_search_table_results.get('total_results'))
# self.assertCountEqual(users.get('results'), self.expected_parsed_search_table_results)
# @responses.activate
# def test_search_user_fail_on_non_200_response(self) -> None:
# """
# Test request failure if search endpoint returns non-200 http code
# :return:
# """
# responses.add(responses.GET, local_app.config['SEARCHSERVICE_ENDPOINT'],
# json=self.mock_search_table_results, status=HTTPStatus.INTERNAL_SERVER_ERROR)
#
# with local_app.test_client() as test:
# response = test.get('/api/search/v0/user', query_string=dict(query='test', page_index='0'))
# self.assertEqual(response.status_code, HTTPStatus.INTERNAL_SERVER_ERROR)
@responses.activate
def test_search_user_fail_on_proccessing_bad_response(self) -> None:
"""
Test catching exception if there is an error processing the results
from the search endpoint
:return:
"""
responses.add(responses.GET, local_app.config['SEARCHSERVICE_ENDPOINT'],
json=self.bad_search_results, status=HTTPStatus.OK)
with local_app.test_client() as test:
response = test.get('/api/search/v0/table', query_string=dict(query='test', page_index='0'))
self.assertEqual(response.status_code, HTTPStatus.INTERNAL_SERVER_ERROR)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment