Beispiel #1
0
class ApplicationSuite(object):

    def __init__(self, client, application):
        self.client = client
        self.application = application

        self.commodity_suite = CommodityTestSuite(self.client, self.application)
        self.good_suite = GoodTestSuite(self.client, self.application)

    def good(self, name, number_l, number_g, price_retail, price_gross):
        # if number_l is None and number_g is None:
        #     numeric = False
        numeric = False if number_l is None and number_g is None else True
        with self.application.app_context():
            com = Commodity.query.filter(Commodity.name == name)
            if com.count() > 0:
                com_id = com[0].id
            else:
                com_id = self.commodity_suite.create_commodity(name, numeric, "")["id"]
        res = self.good_suite.create_good(com_id, number_l, number_g, price_retail, price_gross)
        good_id = res["id"]

        return good_id

    def acceptance_mail(self, file_name, pointsale_id, date):

        pass
Beispiel #2
0
class CommodityTest(BaseTestCase):

    def set_up(self):
        self.commodity_suite = CommodityTestSuite(self.client, self.application)

    def testCommodityRestCRUD(self):
        """
        Проверяем CRUD номенклатуры
        """
        self.commodity()

    def commodity(self):
        """
        Тестируем создание/редактирование/получение/удаление номенклатуры.
        """

        COMS = (
            ((u"ЛТД", True, ""), (u"ЛТД2", True, u"1Т")),
            ((u"Вечерние челны", True, ""), (u"Веч. Челны", False, "")),
            ((u"Машинка", False, ""), (u"Машинка", False, u"25ИГР"))
        )

        with self.application.app_context():

            for com in COMS:
                #Тестируем создание
                name, numeric, thematic = com[0]
                name_new, numeric_new, thematic_new = com[1]
                data = self.commodity_suite._create_commodity(name, numeric, thematic)
                assert data.status_code, 200

                com = Commodity.query.filter(Commodity.name==name).one()
                self.assertEqual(com.numeric, numeric)
                self.assertEqual(com.thematic, thematic)

                #Тестируем получение
                data = self.commodity_suite._get_commodity(com.id)
                self.assertEqual(data.status_code, 200)
                js = self.commodity_suite._deserialize(data.data)
                self.assertEqual(js["id"], com.id)
                self.assertEqual(js['name'], com.name)
                self.assertEqual(js['numeric'], com.numeric)
                self.assertEqual(js['thematic'], com.thematic)
                #Тестируем редактирование
                data = self.commodity_suite._update_commodity(com.id, name_new, numeric_new, thematic_new)
                com = Commodity.query.get(com.id)
                self.assertEqual(data.status_code, 200)
                self.assertEqual(com.name, name_new)
                self.assertEqual(com.numeric, numeric_new)
                self.assertEqual(com.thematic, thematic_new)

                data = self.commodity_suite._get_commodity_all()
                self.assertEqual(data.status_code, 200)

                #Тестируем удаление
                data = self.commodity_suite._delete_commodity(com.id)
                self.assertEqual(data.status_code, 200)
                self.assertIsNone(Commodity.query.get(com.id))
Beispiel #3
0
    def __init__(self, client, application):
        self.client = client
        self.application = application

        self.commodity_suite = CommodityTestSuite(self.client, self.application)
        self.good_suite = GoodTestSuite(self.client, self.application)
Beispiel #4
0
 def set_up(self):
     self.commodity_suite = CommodityTestSuite(
         self.client, self.application)
     self.good_suite = GoodTestSuite(self.client, self.application)
Beispiel #5
0
class GoodTest(BaseTestCase):

    def set_up(self):
        self.commodity_suite = CommodityTestSuite(
            self.client, self.application)
        self.good_suite = GoodTestSuite(self.client, self.application)

    def testGoodRestCRUD(self):
        """
        Проверяем CRUB товара.
        """
        self.good()

    def good(self):
        """
        Тестируем создание/редактирование/получение/удаление товаров.
        """
        COMS = (
            (u"ЛТД", True, ""),
            (u"Вечерние челны", True, ""),
            (u"Машинка", False, "")
        )

        GOODS = (
            # товары
            # id номенклатуры, номер локальный, номера глобальный, цена
            # розницы, цена опта
            (
                (-1, u"1", u"2", 4, 5, False),
                ()
            ),
            (
                (1, u"1", u"1", 1, 1, True),  # SUCCESS
                (1, u"1", u"1", 1, 3, True)  # меняем только цену
            ),
            (
                (1, u"1", u"123123", 145, 120, True),  # SUCCESS
                (2, u"1", u"123123", 120, 100, True)  # меняем цену и
                # номенклатуру
            ),
            (
                (2, u"234", u"674", 90, 100, True),  # SUCCESS
                (3, u"234", u"674", 90, 100, False)  # попытка поменять
                # номенклатуру на безномерную, но с номерами
            ),
            (
                (3, u"12", u"15", 4, 5, False),  # пытаемся создать для
                # безномерной номенклатуры товар с номером
                ()
            ),
            (
                (1, None, None, 1, 1, False),  # пытаемся создать для номерной
                # номенклатуры товар без номера
                ()
            ),
            (
                (1, u"1", u"1", 2, 1, False),  # пытаемся создать товар с уже
                # существующими номерами
                ()
            ),
            (
                (3, None, None, 66, 77, True),  # SUCCESS
                (2, None, None, 66, 77, False)  # попытка изменить тип
                # номенклатуры на номерную и сохранить без номера
            )
        )

        with self.application.app_context():
            for com in COMS:
                name, numeric, thematic = com
                self.commodity_suite._create_commodity(name, numeric, thematic)

            good_count = 0
            price_count = 0
            commodity_count = len(COMS)
            for good in GOODS:
                id_comm, number_l, number_g, price_ret, price_gr, result_test = good[0]

                resp = self.good_suite._create_good(
                    id_comm, number_l, number_g, price_ret, price_gr)
                if result_test:
                    self.assertEqual(resp.status_code, 200)
                    good_count += 1
                    price_count += 1
                    data = self._deserialize(resp.data)
                    id = data['id']
                    good = Good.query.get(id)
                    self.assertEqual(good.commodity_id, id_comm)
                    self.assertEqual(good.number_local, number_l)
                    self.assertEqual(good.number_global, number_g)
                    self.assertEqual(float(good.price.price_retail),
                                     float(price_ret))
                    self.assertEqual(float(good.price.price_gross),
                                     float(price_gr))
                else:
                    self.assertEqual(resp.status_code, 400, good)

                self.assertEqual(Good.query.count(), good_count)
                self.assertEqual(Price.query.count(), price_count)
                self.assertEqual(Commodity.query.count(), commodity_count)

            for good in GOODS:
                id_comm_old, number_l_old, number_g_old, price_ret_old, price_gr_old, res_old = good[0]
                try:
                    id_comm, number_l, number_g, price_ret, price_gr, result_test = good[1]
                except ValueError:
                    continue
                good = Good.query.filter(Good.commodity_id == id_comm_old)
                if number_l_old and number_g_old:
                    good = good.filter(
                        Good.number_local == number_l_old,
                        Good.number_global == number_g_old)
                good = good.one()
                price = good.price
                resp = self.good_suite._get_good(good.id)
                self.assertEqual(resp.status_code, 200)
                data = self._deserialize(resp.data)
                # тестируем получение
                self.assertEqual(data['id'], good.id)
                self.assertEqual(data['commodity_id'], good.commodity_id)
                self.assertEqual(data['full_name'], good.full_name)
                self.assertEqual(data['number_global'], good.number_global)
                self.assertEqual(data['number_local'], good.number_local)
                self.assertEqual(float(data['price.price_gross']),
                                 float(good.price.price_gross))
                self.assertEqual(float(data['price.price_retail']),
                                 float(good.price.price_retail))
                self.assertEqual(data['price_id'], good.price_id)

                # тестируем обновление
                resp = self.good_suite._update_good(
                    good.id, id_comm, number_l, number_g, price_ret, price_gr)
                if result_test:
                    good = Good.query.get(good.id)
                    self.assertEqual(resp.status_code, 200)
                    self.assertEqual(good.commodity_id, id_comm)
                    self.assertEqual(good.number_global, number_g)
                    self.assertEqual(good.number_local, number_l)
                    self.assertEqual(float(good.price.price_gross),
                                     float(price_gr))
                    self.assertEqual(float(good.price.price_retail),
                                     float(price_ret))
                else:
                    self.assertEqual(resp.status_code, 400)
                    good_new = Good.query.get(good.id)
                    self.assertEqual(good_new.commodity_id, good.commodity_id)
                    self.assertEqual(good_new.number_local, good.number_local)
                    self.assertEqual(good_new.number_global,
                                     good.number_global)
                    self.assertEqual(float(good_new.price.price_gross),
                                     float(price.price_gross))
                    self.assertEqual(float(good_new.price.price_retail),
                                     float(price.price_retail))
                    self.assertEqual(good_new.price_id, good.price_id)

                self.assertEqual(Good.query.count(), good_count)
                self.assertEqual(Price.query.count(), price_count)
                self.assertEqual(Commodity.query.count(), commodity_count)

            for good in Good.query.all():
                good_count -= 1
                self.good_suite._delete_good(good.id)

                self.assertEqual(Good.query.count(), good_count)
                self.assertEqual(Price.query.count(), price_count)
                self.assertEqual(Commodity.query.count(), commodity_count)