def test_no_duplicate(self): Flower.delete().execute() program.add_flower('Tulip') program.add_flower('Tulip') flower_count = Flower.select().where(Flower.name == 'Tulip').count() self.assertEqual(1, flower_count) flower = Flower.select().where(Flower.name == 'Tulip').get() self.assertEqual(flower.name, 'Tulip')
class TestBouquet(unittest.TestCase): def setUp(self) -> None: # объекты необходимые для проверки self.bouquet = Bouquet('Fantasy') self.flower1 = Flower('rose', 'red', 70) self.flower2 = Flower('alstroemeria', 'pink', 55) self.flower3 = Flower('eustoma', 'violet', 50) self.bouquet.add_flower(self.flower1) def test_adding_flower( self ): # при добавлении объектов другого класса будет AttributeError self.bouquet.add_flower(self.flower1) self.assertIn(self.flower1.get_name(), self.bouquet.get_flowers_names(), 'ok!!)) flower in') def test_delete_flower(self): # проверка удаления объектов self.bouquet.add_flower(self.flower1) self.bouquet.add_flower(self.flower2) self.bouquet.delete_flower(self.flower2) self.bouquet.add_flower(self.flower3) self.assertNotIn(self.flower2.get_name(), self.bouquet.get_flowers_names(), 'Цветок не должен быть в букете') self.assertIn(self.flower1.get_name(), self.bouquet.get_flowers_names(), 'Цветок должен быть в букете') self.assertIn(self.flower3.get_name(), self.bouquet.get_flowers_names(), 'Цветок должен быть в букете') def test_bouquet_change_price(self): # проверка изменения цены new_bouquet = Bouquet('Fantasy') bouquet_price = new_bouquet.get_price() price_for_change = 585 new_bouquet.set_price(price_for_change) res_price = new_bouquet.get_price() self.assertNotEqual(bouquet_price, res_price, '480 != 585') self.assertEqual(price_for_change, res_price, 'Цена должна быть 585') def test_bouquet_change_name(self): # проверка изменения названия new_name = 'Tenderness' new_bouquet = Bouquet(new_name) res_name = new_bouquet.get_name_b() self.assertEqual(new_name, res_name, 'Должно быть Tenderness') name_for_change = 'Fire' new_bouquet.set_name(name_for_change) res_name_2 = new_bouquet.get_name_b() self.assertNotEqual(res_name, res_name_2, 'Tenderness != Fire') self.assertEqual(name_for_change, res_name_2, 'Название должно быть Fire')
def add_flower(flower_name): """ Save flower to DB. Return flower object if saved, return None if duplicate """ flower = Flower(name=flower_name) try: flower.save() return flower except Exception as e: print(e) return None
def init_db(): # create all tables from models import User, Access, Flower, Base Base.metadata.drop_all(bind=engine) Base.metadata.create_all(bind=engine) session = session_factory() # add flowers for count, port in enumerate([3, 5, 6]): flower = Flower(port, True, count) session.add(flower) # commit all session.commit()
def test_flower_change_price(self): # тесирование изменения цены new_price = 80 new_flower = Flower('rose', 'red', new_price) res_price = new_flower.get_price() self.assertEqual(new_price, res_price, 'Должно быть 80') price_for_change = 85 new_flower.set_price(price_for_change) res_price_2 = new_flower.get_price() self.assertNotEqual(res_price, res_price_2, '80 != 85') self.assertEqual(price_for_change, res_price_2, 'Цена должна быть 85')
def addFlower(arrangement_id): """Routing to add a flower to an existing arrangment.""" if 'username' not in login_session: return redirect('/login') arrangement = session.query(Arrangement).filter_by(id=arrangement_id).one() if login_session['user_id'] != arrangement.user_id: return '''<script>function myFunction() {alert('You are not authorized to add menu items to this arrangement. Please create your own arrangement in order to add items.');}</script> <body onload='myFunction()'>''' if request.method == 'POST': newFlower = Flower(name=request.form['name'], description=request.form['description'], price=request.form['price'], arrangement_id=arrangement_id, user_id=arrangement.user_id) session.add(newFlower) session.commit() flash('New Flower %s Successfully Added!' % (newFlower.name)) return redirect( url_for('showArrangement', arrangement_id=arrangement_id)) else: return render_template('newFlower.html', arrangement=arrangement)
def test_flower_creation(self): # тесирование создания объекта new_name = 'Rose' new_color = 'red' new_price = 80 new_flower = Flower(new_name, new_color, new_price) self.assertIsInstance(new_flower, Flower, 'Должно быть Flower')
def setUp(self) -> None: # объекты необходимые для проверки self.bouquet = Bouquet('Fantasy') self.flower1 = Flower('rose', 'red', 70) self.flower2 = Flower('alstroemeria', 'pink', 55) self.flower3 = Flower('eustoma', 'violet', 50) self.bouquet.add_flower(self.flower1)
def test_add_flower(self): Flower.delete().execute() program.add_flower('Tulip') flower = Flower.select().where(Flower.name == 'Tulip').get() self.assertEqual(flower.name, 'Tulip')
def main(): Flower.delete().execute() rose = add_flower('Rose') poppy = add_flower('Poppy') poppy2 = add_flower('Poppy') # UNIQUE constraint failed: flower.name print(rose, poppy, poppy2) # Rose Poppy None