Example #1
0
    def test_model_add_some(self):
        with self.app.app_context():
            self.basic_setup()
            book2 = BooksModel(2, 1, 1, "book2")
            book2.save_to_db()

            expected = TransactionsModel.save_transaction(
                self.user.id, [self.book.isbn, book2.isbn],
                [self.book.precio, book2.precio], [1, 1])
            self.assertEqual(
                expected[0],
                TransactionsModel.find_by_id_and_isbn(1,
                                                      self.book.isbn).json())
            self.assertEqual(expected[1],
                             TransactionsModel.find_by_id_and_isbn(
                                 1, book2.isbn).json())  # same id
Example #2
0
    def test_order_mail(self):
        with self.app.app_context():
            self.basic_setup()
            book2 = BooksModel(2, 2, 13.1, "book2")
            book2.save_to_db()

            isbns = [self.book.isbn, book2.isbn]
            prices = [self.book.precio, book2.precio]
            quantities = [1, 1]
            dataTransaction = {
                "isbns": isbns,
                'prices': prices,
                'quantities': quantities,
                "email": self.user.email,
            }
            res = self.client.post(
                "/api/transaction",
                data=dataTransaction,
                headers={
                    "Authorization":
                    'Basic ' + base64.b64encode(
                        (self.token + ":").encode('ascii')).decode('ascii')
                })
            self.assertEqual(201, res.status_code)
            # hi ha dues transaccions amb id 1
            transactions = TransactionsModel.find_by_id(1)
            self.assertEqual(len(transactions), 2)

            # les dues transaccions equivalen als llibres que acabem de posar
            for i, isbn in enumerate(isbns):
                self.assertEqual(
                    TransactionsModel.find_by_id_and_isbn(1, isbn).json(),
                    json.loads(res.data)['transactions'][i])