Ejemplo n.º 1
0
class TestOrderProductDAO(DatabseBackedTestCase):
    def setUp(self):
        self.dao = OrderProductDAO()
        super(self.__class__, self).setUp()

    def test_save(self):
        order_product = OrderProduct(name="Amoxidal")
        order_product.id = self.dao.save(order_product)
        self.assertGreater(order_product.id, 0)

        order_product.name += " Duo"
        self.assertGreater(order_product.save(), 0)
        self.assertEqual("Amoxidal Duo", order_product.name)

    def test_mass_update_ordered_on(self):
        today = date.today()
        tomorrow = today + timedelta(days=1)
        amoxidal = OrderProduct(name="Amoxidal", ordered_on=tomorrow)
        amoxidal.save()
        sertal = OrderProduct(name="Sertal", ordered_on=tomorrow)
        sertal.save()
        affected_rows = self.dao.mass_update_ordered_on(
            today, (amoxidal.id, sertal.id))
        self.assertEqual(2, affected_rows)

    def test_find_all_unique_names_ordered_between(self):
        today = date.today()
        a_week_from_today = today + timedelta(weeks=1)
        two_weeks_from_today = today + timedelta(weeks=2)
        a_month_from_today = today + timedelta(weeks=4)

        OrderProduct(name="Amoxidal", ordered_on=a_week_from_today).save()
        OrderProduct(name="amoxidal", ordered_on=two_weeks_from_today).save()
        OrderProduct(name="Sertal", ordered_on=two_weeks_from_today).save()
        OrderProduct(name="sertal", ordered_on=a_week_from_today).save()

        unique_names = self.dao.find_all_unique_names_ordered_between(
            today, a_month_from_today)
        self.assertEqual(2, len(unique_names))

        amoxidalre = re.compile(r'amoxidal', re.IGNORECASE)
        sertalre = re.compile(r'sertal', re.IGNORECASE)
        for regex in (amoxidalre, sertalre):
            matched = filter(lambda name: re.match(regex, name), unique_names)
            self.assertEqual(1, len(matched))
Ejemplo n.º 2
0
class TestOrderProductDAO(DatabseBackedTestCase):
    def setUp(self):
        self.dao = OrderProductDAO()
        super(self.__class__, self).setUp()

    def test_save(self):
        order_product = OrderProduct(name="Amoxidal")
        order_product.id = self.dao.save(order_product)
        self.assertGreater(order_product.id, 0)

        order_product.name += " Duo"
        self.assertGreater(order_product.save(), 0)
        self.assertEqual("Amoxidal Duo", order_product.name)

    def test_mass_update_ordered_on(self):
        today = date.today()        
        tomorrow = today + timedelta(days=1)
        amoxidal = OrderProduct(name="Amoxidal", ordered_on=tomorrow)
        amoxidal.save()
        sertal = OrderProduct(name="Sertal", ordered_on=tomorrow)
        sertal.save()
        affected_rows = self.dao.mass_update_ordered_on(today, (amoxidal.id, sertal.id))
        self.assertEqual(2, affected_rows)

    def test_find_all_unique_names_ordered_between(self):
        today = date.today()
        a_week_from_today = today + timedelta(weeks=1)
        two_weeks_from_today = today + timedelta(weeks=2)
        a_month_from_today = today + timedelta(weeks=4)

        OrderProduct(name="Amoxidal", ordered_on=a_week_from_today).save()
        OrderProduct(name="amoxidal", ordered_on=two_weeks_from_today).save()
        OrderProduct(name="Sertal", ordered_on=two_weeks_from_today).save()
        OrderProduct(name="sertal", ordered_on=a_week_from_today).save()
        
        unique_names = self.dao.find_all_unique_names_ordered_between(today, a_month_from_today)
        self.assertEqual(2, len(unique_names))
    
        amoxidalre = re.compile(r'amoxidal', re.IGNORECASE)
        sertalre = re.compile(r'sertal', re.IGNORECASE)
        for regex in (amoxidalre, sertalre):
            matched = filter(lambda name: re.match(regex, name), unique_names)
            self.assertEqual(1, len(matched))
Ejemplo n.º 3
0
 def setUp(self):
     self.dao = OrderProductDAO()
     super(self.__class__, self).setUp()
Ejemplo n.º 4
0
 def setUp(self):
     self.dao = OrderProductDAO()
     super(self.__class__, self).setUp()