def get_random_quote(request): handle_session(request.session, request.current_route_url()) quotes = gerulib.get_quotes().get('quotes') quotes_len = len(quotes) random_quote = random.randint(0, quotes_len - 1) response = gerulib.get_quote(random_quote) return dict(quote_number=random_quote, quote=response.get('quote'))
def get_quote(request): try: handle_session(request.session, request.current_route_url()) response = gerulib.get_quote(request.matchdict.get('quote_number')) except ValueError: raise httpexceptions.exception_response(HTTPStatus.NOT_FOUND) return dict(quote_number=request.matchdict.get('quote_number'), quote=response.get('quote'))
def test_if_quote_value_is_a_instance_of_str(): assert isinstance(get_quote(2).get('quote'), str)
def test_get_quote_should_return_quote(): expected = {'quote': 'Simple is better than complex.'} assert expected == get_quote(2)
def test_get_quote_should_be_instance_of_dict(): assert isinstance(get_quote(2), dict)