def load_some_tags(): t1 = Tag(u'pâtes') t2 = Tag(u'tomate') r1 = Recipe(u'carbonara') r1.tags = [t1] r2 = Recipe(u'bolognaise') r2.tags = [t1, t2] r3 = Recipe(u'tomates farcies') r3.tags = [t2] r4 = Recipe(u'saucisses-purée') tags = [t1, t2] recipes = [r1, r2, r3, r4] Session.add_all(tags) Session.add_all(recipes) Session.flush() return tags, recipes
def test_cant_add_twice_the_same_even_after_reload(self): tw = TagsWidget() QTest.keyClicks(tw.lineEdit, 'lourd') tw.addTag() Session.add(Tag(u'Another tag')) tw.reload() QTest.keyClicks(tw.lineEdit, 'lourd') tw.addTag() self.assertEqual(tw.listWidget.count(), 1)
def test_create_recipe(self): fut = RecipeEditionDialog() self.assertEqual(fut.name.text(), '') self.assertEqual(fut.description.toPlainText(), '') self.assertEqual(fut.tags.text(), '') fut.name.setText(u'Endive') fut.description.setPlainText(u'desc') fut.tags.setText(u'légume') tag = Tag(u'légume') Session.add(tag) fut.accept() r = fut.recipe self.assertEqual(r.name, u'Endive') self.assertEqual(r.description, u'desc') self.assertEqual(r.tags, [tag])
def test_edit_recipe(self): r = self.recipes[1] fut = RecipeEditionDialog(r) self.assertEqual(fut.name.text(), r.name) self.assertEqual(fut.description.toPlainText(), r.description) self.assertIn(fut.tags.text(), [u'pâtes;tomate', u'tomate;pâtes']) fut.name.setText(u'Endive') fut.description.setPlainText(u'desc') fut.tags.setText(u'légume') tag = Tag(u'légume') Session.add(tag) fut.accept() r = fut.recipe self.assertEqual(r.name, u'Endive') self.assertEqual(r.description, u'desc') self.assertEqual(r.tags, [tag])
def test_get_existing_tag(self): t = Tag('yay') Session.add(t) self.assertEqual(t, Tag.get('yay'))
def test_new_tag(self): t = Tag.get('yay') self.assertEqual(t.name, 'yay')
def setUp(self): super(TagsWidgetTestCase, self).setUp() Session.add_all(Tag(t) for t in [u'lourd', u'pâtes', u'hiver']) self.app = get_app()
def save_recipe(self): self.recipe.name = self.name.text() self.recipe.description = self.description.toPlainText() self.recipe.tags = [Tag.get(t) for t in self.tags.text().split(';')] if self.tags.text() else [] Session.add(self.recipe)
def save_recipe(self): self.recipe.name = self.name.text() self.recipe.description = self.description.toPlainText() self.recipe.tags = [Tag.get(t) for t in self.tags.text().split(';') ] if self.tags.text() else [] Session.add(self.recipe)