def test_fetch_codes_with_exception(session): # pylint: disable=unused-argument """Assert that code type details can not be fetch by table name.""" code_type = 'membership_type' with patch.object(importlib, 'import_module', side_effect=Exception(Error.UNDEFINED_ERROR, None)): with pytest.raises(BusinessException) as exception: CodesService.fetch_codes(code_type) assert exception.value.code == 'UNDEFINED_ERROR'
def test_fetch_codes_not_found(session): # pylint: disable=unused-argument """Assert that code type details can not be fetch by table name.""" # Table is not exists code_type = 'membership_type1' data = CodesService.fetch_codes(code_type) assert not data data = CodesService.fetch_codes(None) assert not data data = CodesService.fetch_codes('') assert not data # The table is not the code, type or status table. code_type = 'user' data = CodesService.fetch_codes(code_type) assert not data
def get(code_type): """Return the codes by giving name.""" try: codes = CodeService.fetch_codes(code_type=code_type) if codes is not None: response, status = jsonify(codes), http_status.HTTP_200_OK else: response, status = {'message': f'The code type ({code_type}) could not be found.'}, \ http_status.HTTP_404_NOT_FOUND except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status
def test_fetch_codes(session): # pylint: disable=unused-argument """Assert that code type details can be fetch by table name.""" code_type = 'membership_type' data = CodesService.fetch_codes(code_type) assert data is not None assert data[0]['name'] == 'USER'