def setUp(self): super(AttachedToTests, self).setUp() obj1 = Tag(tag=u'medicinal') obj2 = Tag(tag=u'maderable') obj3 = Tag(tag=u'frutal') fam = Family(family=u'Solanaceae') self.session.add_all([obj1, obj2, obj3, fam]) self.session.commit()
def test_str(self): """ Test Tag.__str__ method """ name = u'test' tag = Tag(tag=name) self.assert_(str(tag) == name)
def test_when_user_edits_name_name_is_memorized(self): model = Tag() view = MockTagView() presenter = TagEditorPresenter(model, view) view.widget_set_value('tag_name_entry', u'1234') presenter.on_text_entry_changed('tag_name_entry') self.assertEquals(model.tag, u'1234')
def test_widget_names_and_field_names(self): model = Tag() view = MockTagView() presenter = TagEditorPresenter(model, view) for widget, field in presenter.widget_to_field_map.items(): self.assertTrue(hasattr(model, field), field) presenter.view.widget_get_value(widget)
def test_when_user_edits_fields_ok_active(self): model = Tag() view = MockTagView() presenter = TagEditorPresenter(model, view) self.assertTrue(not view.sensitive) # not changed presenter.on_text_entry_changed('tag_name_entry', u'1234') self.assertEquals(model.tag, u'1234') self.assertTrue(view.sensitive) # changed
def test_if_asked_presenter_initializes_view(self): session = db.Session() # prepare data in database obj = Tag(tag=u'1234') session.add(obj) view = MockTagView() TagEditorPresenter(obj, view, refresh_view=True) self.assertEquals(view.widget_get_value("tag_name_entry"), u'1234')
def test_presenter_does_not_initialize_view(self): session = db.Session() # prepare data in database obj = Tag(tag=u'1234') session.add(obj) view = MockTagView() presenter = TagEditorPresenter(obj, view) self.assertFalse(view.widget_get_value("tag_name_entry")) presenter.refresh_view() self.assertEquals(view.widget_get_value("tag_name_entry"), u'1234')
def test_when_user_inserts_existing_name_warning_ok_deactivated(self): session = db.Session() # prepare data in database obj = Tag(tag=u'1234') session.add(obj) session.commit() session.close() ## ok. thing is already there now. session = db.Session() view = MockTagView() obj = Tag() # new scratch object session.add(obj) # is in session presenter = TagEditorPresenter(obj, view) self.assertTrue(not view.sensitive) # not changed presenter.on_unique_text_entry_changed('tag_name_entry', u'1234') self.assertEquals(obj.tag, u'1234') self.assertTrue(view.is_dirty()) self.assertTrue(not view.sensitive) # unacceptable change self.assertTrue(presenter.has_problems())
def test_attached_tags_many(self): fam = self.session.query(Family).one() tags = self.session.query(Tag).all() for t in tags: tag_plugin.tag_objects(t, [fam]) self.assertEquals(Tag.attached_to(fam), tags)
def test_attached_tags_singleton(self): fam = self.session.query(Family).one() obj2 = self.session.query(Tag).filter(Tag.tag == u'maderable').one() tag_plugin.tag_objects(obj2, [fam]) self.assertEquals(Tag.attached_to(fam), [obj2])
def test_attached_tags_empty(self): fam = self.session.query(Family).one() self.assertEquals(Tag.attached_to(fam), [])