示例#1
0
def get_category_by_id(id: int):
    with session_scope() as db:
        category = db.query(Category).filter(Category.id == id).first()
        return Category(id=category.id,
                        name=category.name,
                        description=category.description)
    pass
示例#2
0
文件: tests.py 项目: al016/coiner2
    def SetUp(self):
        """
		Запускается в начале каждого теста,
		создает пользователя для тестирования
		"""
        self.name, self.total_money = 'test Category', 1000000
        self.category = Category(self.name, self.total_money)
def hello_world():
    product = Product(name="product_1")
    category = Category(name="category_1", description='description')
    product.categories = [category]

    session.add(product)
    session.commit()

    return 'Hello, World!'
示例#4
0
文件: tests.py 项目: al016/coiner2
    def test_move_money_from_wal_to_cat(self):
        """
		Проверяет функцию пополнения баланса
		"""
        self.SetUp()
        test_cat = Category("category", 400)
        self.wallet.move_money(300000, test_cat)
        assert self.wallet.balance == 700000
        assert test_cat.balance == 300400
示例#5
0
def create_db():
    db.drop_all()
    db.create_all()
    source = Source('wikidich', 'https://wikidich.com/')
    category = Category('Tiên hiệp')
    author = Author('Ngô Thiên')
    book = Book('Ngã Thị Phong Thiên')
    chapter = Chapter(1, 'lời giới thiệu', 'this is content')
    # append relation
    book.chapters.append(chapter)
    book.categories.append(category)
    book.authors.append(author)
    source.books.append(book)

    db.session.add_all([book, chapter, category, author, source])
    db.session.commit()
示例#6
0
 def update(cls, _id: int, new_name: str, new_price: int, new_category: str,
            new_off: float) -> (bool, str):
     if new_category:
         if not Category().exist(new_category):
             return False, f"category [{new_category}] not found please first add new category"
     if _id:
         for product in cls.__db:
             if product.get("id") == int(_id):
                 if new_name:
                     product["name"] = new_name
                 if new_price:
                     product["price"] = int(new_price)
                 if new_category:
                     ca = Category.get_one_category(new_category)
                     product["category_id"] = ca.get("id")
                 if new_off:
                     product["off"] = float(new_off)
                 return True, ""
         return False, f"id: {_id} not found"
示例#7
0
    def save(cls,
             name: str = None,
             price: int = None,
             category_name: str = None,
             off: float = None) -> (bool, str):

        if not name or not price or not category_name or not off:
            return False, f"name: {name} or price: {price} or category: {category_name} or off: {off} not found"

        for category in Category().get_all_categories():
            if category.get("name") == name:
                cls.__table.append(
                    dict(id=str(next(Product.__id)),
                         name=name,
                         price=price,
                         category_id=category.get("id"),
                         off=off))
                return True, ""

        return False, "category not found"
示例#8
0
def createCategory():
    message = {
        "success": False,
    }
    if request.method == 'POST':

        form_data = json.loads(request.form.get('form'))
        # update or create new

        new_category = Category(
            name=form_data["name"],
            showname=form_data["showname"],
            user_id=current_user.id,
        )
        # add category id and restaurant id
        db.session.add(new_category)

        db.session.commit()
        message['success'] = True
        message['category'] = new_category.id

    return jsonify(message)
示例#9
0
文件: tests.py 项目: al016/coiner2
 def test_move_money_from_cat_to_cat(self):
     self.SetUp()
     test_category = Category("test Catogory 2", 500)
     self.category.move_money(300000, test_category)
     assert self.category.balance == 700000
     assert test_category.balance == 300500
 def create_instance(self):
     categories = Category("Mobile", "Wearable Device")
     return categories
示例#11
0
def insert_category(category):
    with session_scope() as db:
        cat = Category(name=category.name, description=category.description)
        db.add(cat)
示例#12
0
 def __init__(self, data, recipe):
     self.name = data.get("product_name")
     self.price_excluding_tax = data.get("price_excluding_tax")
     self.vat = Vat(data)
     self.category = Category(data)
     self.data = data
示例#13
0
 def test_name_none(self):
     with pytest.raises(TypeError):
         c = Category(None, 'Bebida')
示例#14
0
 def test_description_len(self):
     with pytest.raises(ValueError):
         c = Category('Bebida', 'Nacional' * 255)      
示例#15
0
 def test_description_type(self):
     with pytest.raises(TypeError):
         c = Category('Bebida', 10.6)       
示例#16
0
 def test_name_type(self):
     with pytest.raises(TypeError):
         c = Category(100, 'Nacional')                   
示例#17
0
 def test_name_len(self):
     with pytest.raises(ValueError):
         c = Category('Bebida' * 100, 'Nacional')     
示例#18
0
 def test_name_empty(self):
     with pytest.raises(ValueError):
         c = Category('', 'Bebida')