def test__eq__(self): """A `CommonName` is equal to another if relevant columns match.""" cn1 = CommonName() cn2 = CommonName() idx = Index() idx.id = 1 x = CommonName() y = CommonName() z = CommonName() x.id = 24 y.id = 25 z.id = 26 cv1, cv2, cv3 = Cultivar(), Cultivar(), Cultivar() cn1.id = 42 cn1.index = idx cn1.name = 'Annual' cn1.slug = 'annual' cn1.description = 'Not built to last.' cn1.instructions = 'Plant them.' cn1.gw_common_names = [x, y, z] cn1.gw_cultivars = [cv1, cv2, cv3] cn1.visible = True assert cn1 != cn2 cn2.id = 42 cn2.index = idx cn2.name = 'Annual' cn2.slug = 'annual' cn2.description = 'Not built to last.' cn2.instructions = 'Plant them.' cn2.gw_common_names = [x, y, z] cn2.gw_cultivars = [cv1, cv2, cv3] cn2.visible = True assert cn1 == cn2
def test_init(self, m_sfc): m_sfc.return_value = [(1, "One"), (2, "Two"), (3, "Three")] cn1 = CommonName(name="One") cn1.id = 1 cn2 = CommonName(name="Two") cn2.id = 2 obj = BotanicalName(name="Bot nam") obj.common_names = [cn1, cn2] ebnf = EditBotanicalNameForm(obj=obj) assert ebnf.common_names.data == [1, 2]
def test_validate_botanical_name_id(self, m_bnq): """Raise error if selected BN is not in selected CN.""" bn = BotanicalName("Digitalis über alles") cn1 = CommonName(name="Fauxglove") cn1.id = 1 cn2 = CommonName(name="Spuriousglove") cn2.id = 2 bn.common_names = [cn1, cn2] m_bnq.return_value = bn self = mock.MagicMock() self.common_name_id.data = 3 field = mock.MagicMock() with pytest.raises(ValidationError): EditCultivarForm.validate_botanical_name_id(self=self, field=field)
def test_dict__to_from_dict_existing_cn(self, m_q): """Do not create `CommonName` if id already exists in db.""" old_cn = CommonName() old_cn.id = 42 m_q.get.return_value = old_cn cn = CommonName() idx = Index() idx.id = 1 cn.id = 42 cn.index = idx cn.name = 'Annual' cn.slug = 'annual' cn.description = 'Not built to last.' cn.instructions = 'Plant them.' cn.visible = True d = cn.dict_ with pytest.raises(ValueError): CommonName.from_dict_(d)
def test_add_section_bad_cn_id(self, app, db): """Redirect to select_common_name if cn_id is invalid.""" with app.test_client() as tc: rv = tc.get(url_for("seeds.add_section")) assert rv.location == url_for("seeds.select_common_name", dest="seeds.add_section", _external=True) cn = CommonName(name="Foxglove") cn.id = 1 db.session.add(cn) db.session.commit() with app.test_client() as tc: rv = tc.get(url_for("seeds.add_section", cn_id=42)) assert rv.location == url_for("seeds.select_common_name", dest="seeds.add_section", _external=True)
def test_add_botanical_name_bad_cn_id(self, app, db): """Redirect to select common name if CommonName can't be loaded.""" with app.test_client() as tc: rv = tc.get(url_for("seeds.add_botanical_name")) assert rv.location == url_for("seeds.select_common_name", dest="seeds.add_botanical_name", _external=True) cn = CommonName() cn.id = 1 db.session.add(cn) db.session.commit() with app.test_client() as tc: rv = tc.get(url_for("seeds.add_botanical_name", cn_id=42)) assert rv.location == url_for("seeds.select_common_name", dest="seeds.add_botanical_name", _external=True)
def test_dict__to_from_dict_(self, m_iq, m_cq): """Create new CommonName equal to CN.dict_ Note: grows_with is excluded because that must be handled by a different function. """ m_cq.get.return_value = None cn = CommonName() idx = Index() m_iq.get.return_value = idx idx.id = 1 cn.id = 42 cn.index = idx cn.name = 'Annual' cn.slug = 'annual' cn.description = 'Not built to last.' cn.instructions = 'Plant them.' cn.visible = True d = cn.dict_ assert CommonName.from_dict_(d)