def test_is_newest(self): uuid = testdata.get_hash() it = Item(price=1000, body={}, uuid=uuid) self.assertTrue(it.is_newest()) it.save() it = Item(price=100, body={}, uuid=uuid) self.assertFalse(it.is_newest())
def test_is_richest(self): uuid = testdata.get_hash() it = WatchlistItem.create(price=100, body={}, uuid=uuid) it = WatchlistItem.create(price=10, body={}, uuid=uuid) it = Item(price=1000, body={}, uuid=uuid) self.assertFalse(it.is_cheapest()) self.assertTrue(it.is_richest())
def test_richest(self): uuid = testdata.get_hash() it = WatchlistItem.create(price=10, body={}, uuid=uuid) it = WatchlistItem.create(price=1, body={}, uuid=uuid) it = WatchlistItem.create(price=1000, body={}, uuid=uuid) it = WatchlistItem.create(price=100, body={}, uuid=uuid) it = Item(price=0, body={}, uuid=uuid) richest = it.richest self.assertEqual(1000, richest.price)
def test_new_old_price(self): uuid = testdata.get_hash() body = { "url": testdata.get_url(), "title": testdata.get_words(), } oit = WatchlistItem.create(price=10, body=dict(body), uuid=uuid) it = Item(price=1, body=dict(body), uuid=uuid) s = it.html_detail() self.assertTrue("<b>$1.00</b>" in s) self.assertTrue("was <b>$10.00</b>" in s)
def test_last_newest_in_db(self): uuid = testdata.get_hash() oit1 = WatchlistItem.create(price=10, body={}, uuid=uuid) oit2 = WatchlistItem.create(price=100, body={}, uuid=uuid) it = Item(price=1000, body={}, uuid=uuid) it.save() self.assertEqual(it.last.pk, oit2.pk) it = Item(price=1000, body={}, uuid=uuid) it.newest = oit2 self.assertEqual(it.last.pk, oit1.pk)
def test_equality(self): uuid = testdata.get_hash() price = 10 it = Item(price=price, body={}, uuid=uuid) # make sure when there is non of this item in the db it acts as expected self.assertFalse(it.is_cheaper()) self.assertFalse(it.is_richer()) self.assertTrue(it.is_newest()) self.assertTrue(it.is_cheapest()) self.assertTrue(it.is_stocked()) self.assertTrue(it.is_richest()) # now make sure it acts as expected when there is another item wit = WatchlistItem.create(price=price, body={}, uuid=uuid) self.assertFalse(it.is_cheaper()) self.assertFalse(it.is_richer()) self.assertFalse(it.is_newest()) self.assertTrue(it.is_cheapest()) self.assertTrue(it.is_stocked()) self.assertTrue(it.is_richest())
def get_item(item=None, **kwargs): if item: body = dict(item.newest.body) body.update(kwargs) body.setdefault("uuid", item.uuid) kwargs = body price = kwargs.pop("price", testdata.get_int(1000)) uuid = kwargs.pop("uuid", testdata.get_hash()) kwargs.setdefault("url", testdata.get_url()) kwargs.setdefault("digital", testdata.get_bool()) kwargs.setdefault("image", testdata.get_url()) kwargs.setdefault("title", testdata.get_words()) if isinstance(price, float): kwargs["price"] = price price = int(price * 100.0) else: kwargs["price"] = float(price) * 0.01 it = Item(price=price, body=kwargs, uuid=uuid) return it
def test_get_hash(self): h = testdata.get_hash() self.assertEqual(32, len(h))