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_common_name_renders_page(self, app, db): """Render page with common name info given valid slugs.""" cn = CommonName() idx = Index() db.session.add_all([cn, idx]) cn.name = "Foxglove" cn.description = "Do foxes really wear these?" idx.name = "Perennial Flower" cn.index = idx db.session.commit() with app.test_client() as tc: rv = tc.get(url_for("seeds.common_name", idx_slug=idx.slug, cn_slug=cn.slug)) assert "Do foxes really wear these?" in str(rv.data)
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_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)