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_gw_from_dict_(self, db):
     """Set grows_with with a list of ids from a CommonName.dict_"""
     a = CommonName(name='a')
     b = CommonName(name='b')
     c = CommonName(name='c')
     db.session.add_all([a, b, c])
     db.session.flush()
     cn = CommonName(name='Test')
     cn.gw_common_names = [a, b, c]
     d = cn.dict_
     cn2 = CommonName(name='Test2')
     cn2.gw_from_dict_(d)
     assert cn.gw_common_names == cn2.gw_common_names
 def test_gw_from_dict_missing_cns(self, db):
     """Raise a RuntimeError if any needed CNs are missing."""
     a = CommonName(name='a')
     b = CommonName(name='b')
     c = CommonName(name='c')
     db.session.add_all([a, b, c])
     db.session.flush()
     cn = CommonName(name='Test')
     cn.gw_common_names = [a, b, c]
     d = cn.dict_
     d['gw_common_names'].append(42)
     cn2 = CommonName(name='Test2')
     with pytest.raises(RuntimeError):
         cn2.gw_from_dict_(d)