def test_stock_find_stock(): """ Tests Stock.find_stock() """ stock1 = Stock(name="Name1X", ticker="TKRC") stock1.save() stock2 = Stock(name="Name2Y", ticker="TKFF") stock2.save() TestCase.assertCountEqual(None, [stock1, stock2], Stock.find_stock("")) TestCase.assertCountEqual(None, [stock1, stock2], Stock.find_stock("Name")) TestCase.assertCountEqual(None, [stock1], Stock.find_stock("Name1")) TestCase.assertCountEqual(None, [stock2], Stock.find_stock("e2")) single_stock_find = Stock.find_stock("", 1)[0] assert single_stock_find == stock1 or single_stock_find == stock2
def resolve_stock_find(_self, _info, text, first=None, **_args): """ Finds a stock given a case insensitive name. (see :py:meth:`stocks.models.Stock.find_stock`) :param text: The text the user want to search for. :type name: str. :param first: The maximum number of results to return :type name: int. :returns: :py:class:`django.db.models.query.QuerySet` of :py:class:`stocks.stocks.Stock` """ if first: return Stock.find_stock(text, first) return Stock.find_stock(text)