示例#1
0
 def test_create_stock_no_duplicate(self):
     """Makes sure stock don't have the same stock_id when creating."""
     Category.create(category_id='001', description='Testing Stock')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     from peewee import IntegrityError
     with self.assertRaises(IntegrityError):
         create_stock('001', 'Testing stock', 1, '001', 9.99)
     q = Stock.delete().where(Stock.stock_id == '001')
     q.execute()
     t = Category.delete().where(Category.category_id == '001')
     t.execute()
示例#2
0
def create_stock():
    form = CreateStockForm()
    if form.validate_on_submit():
        stock.create_stock(
            stock_id=form.stock_id.data,
            description=form.description.data,
            quantity=form.quantity.data,
            category=form.category.data,
            price=form.price.data
        )
        flash("Stock created successfully")
        return redirect(url_for('create_stock'))
    return render_template('stock/create_stock.html', form=form)
示例#3
0
 def test_create_stock(self):
     """Make sure it create a stock."""
     Category.create(category_id='001', description='Testing Stock')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     s = Stock.select().where(Stock.stock_id == '001')
     t = Stock.delete().where(Stock.stock_id == '001')
     t.execute()
     t = Category.delete().where(Category.category_id == '001')
     t.execute()
     self.assertEqual(str(s), ("<class 'models.Stock'> SELECT `t1`.`id`,"
                               " `t1`.`stock_id`, `t1`.`description`,"
                               " `t1`.`quantity`, `t1`.`category_id`,"
                               " `t1`.`price` FROM `stock` AS t1"
                               " WHERE (`t1`.`stock_id` = %s) ['001']"))
示例#4
0
 def test_create_outgoing(self):
     """Create an outgoing record."""
     Category.create(category_id='001', description='Testing Stock')
     Project.create(project_id='001', project_description="Testing")
     Role.create(role_name='Admin')
     User.create(first_name='Jay', second_name='Palm', phone='9783978223', role='Admin', username='******',
                 password='******', email='*****@*****.**')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     create_outgoing_stock(stock='001', project_id='001', date="2015-07-22", quantity='7', username='******')
     OutgoingStock.get(OutgoingStock.stock == '001').delete_instance()
     Stock.get(Stock.category == '001').delete_instance()
     User.get(User.username == 'JayPalm').delete_instance()
     Role.get(Role.role_name == 'Admin').delete_instance()
     Project.get(Project.project_id == '001').delete_instance()
     Category.get(Category.category_id == '001').delete_instance()
示例#5
0
    def test_create_incoming(self):
        """Create an incoming record."""
        Category.create(category_id='001', description='Testing Stock')
        create_stock('001', 'Testing stock', 1, '001', 9.99)
        create_incoming_stock(stock="001", date="2015-07-22", quantity=13, price=13.99)
        p = IncomingStock.select().where(IncomingStock.stock == '001')
        q = IncomingStock.delete().where(IncomingStock.stock == '001')
        q.execute()
        s = Stock.select().where(Stock.stock_id == '001')
        t = Stock.delete().where(Stock.stock_id == '001')
        t.execute()
        t = Category.delete().where(Category.category_id == '001')
        t.execute()

        self.assertEqual(str(p), ("<class 'models.IncomingStock'> SELECT `t1`.`id`, `t1`.`stock_id`, "
                                  "`t1`.`date`, `t1`.`price`, `t1`.`cost` FROM `incomingstock` AS t1 WHERE "
                                  "(`t1`.`stock_id` = %s) ['001']"))
示例#6
0
 def test_create_stock_no_arguments(self):
     """Attempt to create a stock, but fail if not nullable arguments are missing."""
     with self.assertRaises(TypeError):
         create_stock()