コード例 #1
0
 def test_from_dict__index_exists(self, m_q):
     """Do not allow from_dict_ to create an Index w/ id already in use."""
     old_idx = Index()
     old_idx.id = 42
     m_q.get.return_value = old_idx
     idx = Index()
     idx.id = 42
     idx.position = 3
     idx.name = 'Annual'
     idx.slug = 'annual'
     idx.description = 'Not built to last.'
     d = idx.dict_
     with pytest.raises(ValueError):
         Index.from_dict_(d)
コード例 #2
0
 def test_select_field_choices_with_model_by_name(self, db):
     """Generate tuple list from queried items ordered by name."""
     idx1 = Index(name='Perennial')
     idx2 = Index(name='Annual')
     idx3 = Index(name='Rock')
     idx1.id = 1
     idx2.id = 2
     idx3.id = 3
     db.session.add_all([idx1, idx2, idx3])
     db.session.flush()
     stls = select_field_choices(model=Index,
                                 title_attribute='name',
                                 order_by='name')
     assert stls == [(2, 'Annual'), (1, 'Perennial'), (3, 'Rock')]
コード例 #3
0
 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
コード例 #4
0
 def test__eq__(self):
     """Return True if all columns are the same value."""
     idx1 = Index()
     idx2 = Index()
     idx1.id = 42
     assert idx1 != idx2
     idx2.id = 42
     assert idx1 == idx2
     idx1.position = 3
     idx1.name = 'Annual'
     idx1.slug = 'annual'
     idx1.description = 'Not built to last.'
     assert idx1 != idx2
     idx2.position = 3
     idx2.name = 'Annual'
     idx2.slug = 'annual'
     idx2.description = 'Not built to last.'
     assert idx1 == idx2
コード例 #5
0
 def test_dict__to_from_dict__(self, m_q):
     """An Index.dict_ fed to Index.from_dict_ creates identical Index."""
     m_q.get.return_value = None
     idx1 = Index()
     idx1.id = 42
     idx1.position = 3
     idx1.name = 'Annual'
     idx1.slug = 'annual'
     idx1.description = 'Not built to last.'
     d = idx1.dict_
     assert Index.from_dict_(d) == idx1
コード例 #6
0
 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)
コード例 #7
0
    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)