Example #1
0
    def test_crud(self):
        it = WatchlistItem(uuid=testdata.get_ascii(16),
                           body={
                               "foo": 1,
                               "bar": 2
                           },
                           price=17.14)

        def assertSubDict(d1, d2):
            for k, v in d1.items():
                self.assertEqual(v, d2[k])

        self.assertEqual(1714, it.price)
        #self.assertEqual({"foo": 1, "bar": 2}, it.body)
        assertSubDict({"foo": 1, "bar": 2}, it.body)

        it.save()
        self.assertLess(0, it.pk)

        self.assertEqual(1714, it.price)
        #self.assertEqual({"foo": 1, "bar": 2}, it.body)
        assertSubDict({"foo": 1, "bar": 2}, it.body)

        it2 = WatchlistItem.query.get_pk(it.pk)
        self.assertEqual(1714, it2.price)
        #self.assertEqual({"foo": 1, "bar": 2}, it2.body)
        assertSubDict({"foo": 1, "bar": 2}, it2.body)
        self.assertEqual(it.pk, it2.pk)
Example #2
0
    def test_price(self):
        it = WatchlistItem()
        it.price = 12.34
        self.assertEqual(1234, it.price)

        it.price = 1256
        self.assertEqual(1256, it.price)
Example #3
0
    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())
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    def test_fset(self):
        uuid = testdata.get_ascii(16)
        body = {
            "uuid": uuid,
            "price": 100.0,
        }
        it = WatchlistItem(body=body)
        self.assertEqual(10000, it.price)
        self.assertEqual(uuid, it.uuid)

        body = {
            "uuid": testdata.get_ascii(16),
            "price": 200.0,
        }
        it.body = body
        self.assertEqual(10000, it.price)
        self.assertEqual(uuid, it.uuid)
        self.assertNotEqual(uuid, it.body["uuid"])
Example #7
0
    def test_multi(self):
        uuid = testdata.get_ascii(16)

        it = WatchlistItem(uuid=uuid, body={"foo": 1}, price=17.14)
        it.save()

        it2 = WatchlistItem(uuid=uuid, body={"foo": 1}, price=17.15)
        it2.save()

        self.assertEqual(it.uuid, it2.uuid)
        self.assertLess(it.pk, it2.pk)
Example #8
0
 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)
Example #9
0
    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())