Exemple #1
0
    def test_add_sale(self):
        upload = models.Upload(id=1, name='Xpto')

        sale1 = models.Sale(id=1, unit_price=1.25, count=2)
        upload.add_sale(sale1)

        sale2 = models.Sale(id=2, unit_price=1.25, count=2)
        upload.add_sale(sale2)

        self.assertEqual(upload.total, 5.0)
Exemple #2
0
 def test_create(self):
     merchant = models.Merchant(id=1)
     upload = models.Upload(id=1)
     sale = models.Sale(upload=upload,
                        merchant=merchant,
                        purchaser_name='Snake Plissken',
                        description='R$20 Sneakers for R$5',
                        unit_price=1.25,
                        count=1)
     self.assertIsNone(sale.id)
     sale = repositories.SaleRepository(self.conn).create(sale)
     self.assertIsNotNone(sale.id)
Exemple #3
0
 def addSale(self, req):
     sale_id = self.sales.insert_one(models.Sale(**req)).inserted_id
     return self.sales.find_one({"_id": sale_id})
Exemple #4
0
    def setData(self):
        womens = [
            "Myrtis Kahn  ", "Margery Hou  ", "Georgianne Teneyck  ",
            "Zora Dunsmore  ", "Misha Calcagni  ", "Coral Watson  ",
            "Destiny Millet  ", "Willodean Severt  ", "Nanci Nicol  ",
            "Maris Credle  ", "Brittney Hawes  ", "Maryrose Butterworth  ",
            "Catherin Dobson  ", "Marylin Torpey  ", "Myrtle Tracy  ",
            "Velda Coy  ", "Lolita Maglio  ", "Stephaine Ciulla  ",
            "Regina Quarterman  ", "Dorine Bucy  "
        ]
        mans = [
            "Lowell Wightman  ", "Avery Harriger  ", "Alonso Marcello  ",
            "Johnson Rego  ", "Wilfred Mackay  ", "Trent Dimick  ",
            "Edgar Holtkamp  ", "Nicholas Chaudhry  ", "Bernard Bourbeau  ",
            "Gabriel Sperling  ", "Rolf Cirillo  ", "Ruben Turberville  ",
            "Ethan Dresser  ", "Spencer Bourque  ", "Marcelo Draves  ",
            "Galen Maybee  ", "Malcom Mckee  ", "Felix Moreles  ",
            "Reuben Villalpando  ", "Archie Liao  "
        ]
        sellers = []
        products = []
        customers = []
        for p in womens:
            sellers.append(
                self.sellers.insert_one(
                    models.Seller(p.split(" ")[0],
                                  p.split(" ")[1])).inserted_id)
            customers.append(
                self.customers.insert_one(
                    models.Customer(p.split(" ")[0],
                                    p.split(" ")[1])).inserted_id)
        for p in mans:
            sellers.append(
                self.sellers.insert_one(
                    models.Seller(p.split(" ")[0],
                                  p.split(" ")[1])).inserted_id)
            customers.append(
                self.customers.insert_one(
                    models.Customer(p.split(" ")[0],
                                    p.split(" ")[1])).inserted_id)
        for i in range(0, 100):
            products.append(
                self.products.insert_one(
                    models.Product("Product " + str(randint(0, 1000)),
                                   randint(0, 10000))).inserted_id)

        for i in range(0, 75000):
            pr = self.products.find_one(
                {'_id': ObjectId(products[randint(0,
                                                  len(products) - 1)])})
            count = randint(0, 10)

            sell = self.sellers.find_one(
                {"_id": sellers[randint(0,
                                        len(sellers) - 1)]})
            cust = self.customers.find_one(
                {"_id": customers[randint(0,
                                          len(customers) - 1)]})

            self.sales.insert_one(
                models.Sale(sell, cust, pr, count, count * pr["price"]))
Exemple #5
0
 def updateSale(self, req):
     self.removeSale(req)
     sale_id = self.sales.insert_one(
         models.Sale(req["seller"], req["customer"], req["product"],
                     req["amount"], req["totalPrice"])).inserted_id
     return self.sales.find_one({"_id": sale_id})
Exemple #6
0
 def test_total(self):
     sale = models.Sale(id=1, unit_price=1.25, count=2)
     self.assertEqual(sale.total, 2.5)
Exemple #7
0
 def test_repr(self):
     sale = models.Sale(id=1, unit_price=1, count=1)
     self.assertEqual(str(sale), 'Sale 1: 1.0')