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)