def test_validate_name(self, db):
        """Raise error if cultivar already exists.

        Cultivars are constrained to have a unique combination of name, common
            name, and section.
        """
        cv1 = Cultivar(name='Polkadot Petra')
        cv1.common_name = CommonName(name='Foxglove')
        cv1.common_name.index = Index(name='Perennial')
        cv1.section = Section(name='Polkadot')
        cv2 = Cultivar(name='Silky Gold')
        cv2.common_name = CommonName(name='Butterfly Weed')
        cv2.common_name.index = Index(name='Annual')
        cv3 = Cultivar(name='Tumbling Tom',
                       common_name=CommonName(name='Tomato'))
        db.session.add_all([cv1, cv2, cv3])
        db.session.commit()
        form1 = AddCultivarForm(cn=cv1.common_name)
        form1.name.data = 'Petra'
        form1.validate_name(form1.name)
        form2 = AddCultivarForm(cn=cv2.common_name)
        form2.name.data = 'Silky Gold'
        with pytest.raises(ValidationError):
            form2.validate_name(form2.name)
        form3 = AddCultivarForm(cn=cv3.common_name)
        form3.name.data = 'Tumbling Tom'
        with pytest.raises(ValidationError):
            form3.validate_name(form3.name)
 def test_edit_packet_submission_no_changes(self, app, db):
     """Flash a message if no changes are made in a form submission."""
     cultivar = Cultivar()
     packet = Packet()
     db.session.add(packet, cultivar)
     packet.price = Decimal("2.99")
     packet.quantity = Quantity(value=100, units="seeds")
     packet.sku = "8675309"
     cultivar.name = "Foxy"
     cultivar.common_name = CommonName(name="Foxglove")
     cultivar.packets.append(packet)
     db.session.commit()
     with app.test_client() as tc:
         rv = tc.post(
             url_for("seeds.edit_packet", pkt_id=packet.id),
             data=dict(
                 id=packet.id,
                 price=packet.price,
                 qty_val=str(packet.quantity.value),
                 units=packet.quantity.units,
                 sku=packet.sku,
             ),
             follow_redirects=True,
         )
     assert "No changes to" in str(rv.data)
Exemplo n.º 3
0
 def test_add_one_no_optionals(self):
     """Add a Cultivar to the Cultivars worksheet."""
     messages = StringIO()
     wb = Workbook()
     ws = wb.active
     cvws = CultivarsWorksheet(ws)
     cvws.setup()
     cv = Cultivar(name='Foxy')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     cvws.add_one(cv, stream=messages)
     assert cvws.cell(2, cvws.cols['Index']).value == 'Perennial'
     assert cvws.cell(2, cvws.cols['Common Name']).value == 'Foxglove'
     assert cvws.cell(2, cvws.cols['Cultivar Name']).value == 'Foxy'
     assert cvws.cell(2, cvws.cols['Section']).value is None
     assert cvws.cell(2, cvws.cols['Botanical Name']).value is None
     assert cvws.cell(2, cvws.cols['Thumbnail Filename']).value is None
     assert cvws.cell(2, cvws.cols['Description']).value is None
     assert cvws.cell(2, cvws.cols['Synonyms']).value is None
     assert cvws.cell(2, cvws.cols['New Until']).value is None
     assert cvws.cell(2, cvws.cols['In Stock']).value == 'False'
     assert cvws.cell(2, cvws.cols['Active']).value == 'False'
     messages.seek(0)
     msgs = messages.read()
     assert ('Adding data from <Cultivar "Foxy Foxglove"> to row #2 of '
             'cultivars worksheet.') in msgs
 def test_cultivar_bad_slugs(self, app, db):
     """Return 404 if any slug given does not correspond to a db entry."""
     app.config["SHOW_CULTIVAR_PAGES"] = True
     idx = Index()
     cn = CommonName()
     cultivar = Cultivar()
     db.session.add_all([idx, cn, cultivar])
     idx.name = "Perennial Flower"
     cn.name = "Foxglove"
     cultivar.name = "Foxy"
     cultivar.common_name = cn
     cultivar.description = "Like that Hendrix song."
     db.session.commit()
     with app.test_client() as tc:
         rv = tc.get(url_for("seeds.cultivar", idx_slug=idx.slug, cn_slug=cn.slug, cv_slug="no-biscuit"))
     assert rv.status_code == 404
     with app.test_client() as tc:
         rv = tc.get(url_for("seeds.cultivar", idx_slug="no_biscuit", cn_slug=cn.slug, cv_slug=cultivar.slug))
     assert rv.status_code == 404
     with app.test_client() as tc:
         rv = tc.get(url_for("seeds.cultivar", idx_slug=idx.slug, cn_slug="no-biscuit", cv_slug=cultivar.slug))
     assert rv.status_code == 404
     with app.test_client() as tc:
         rv = tc.get(url_for("seeds.cultivar", idx_slug="no-biscuit", cn_slug="no-biscuit", cv_slug="no-biscuit"))
     assert rv.status_code == 404
Exemplo n.º 5
0
 def test_add_one(self):
     """Add a Packet to the Packets worksheet."""
     messages = StringIO()
     wb = Workbook()
     ws = wb.active
     pws = PacketsWorksheet(ws)
     pws.setup()
     pkt = Packet(sku='8675309', price='3.50')
     pkt.quantity = Quantity(value=100, units='seeds')
     cv = Cultivar(name='Foxy')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     pkt.cultivar = cv
     pws.add_one(pkt, stream=messages)
     assert pws.cell(
         2, pws.cols['Cultivar (JSON)']
     ).value == json.dumps(cv.queryable_dict)
     assert pws.cell(2, pws.cols['SKU']).value == '8675309'
     assert pws.cell(2, pws.cols['Price']).value == '3.50'
     assert pws.cell(2, pws.cols['Quantity']).value == '100'
     assert pws.cell(2, pws.cols['Units']).value == 'seeds'
     messages.seek(0)
     msgs = messages.read()
     assert ('Adding data from <Packet SKU #8675309> to row #2 of packets '
             'worksheet.') in msgs
Exemplo n.º 6
0
 def test_add_one_active(self):
     """Add an active Cultivar to worksheet."""
     wb = Workbook()
     ws = wb.active
     cvws = CultivarsWorksheet(ws)
     cvws.setup()
     cv = Cultivar(name='Foxy')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     cv.active = True
     cvws.add_one(cv)
     assert cvws.cell(2, cvws.cols['Active']).value == 'True'
     cv2 = Cultivar(name='Soulmate')
     cv2.common_name = CommonName(name='Butterfly Weed')
     cv2.common_name.index = Index(name='Perennial')
     cv2.active = False
     cvws.add_one(cv2)
     assert cvws.cell(3, cvws.cols['Active']).value == 'False'
 def test_select_cultivar_successful_submission(self, app, db):
     """Redirect to dest on valid form submission."""
     cultivar = Cultivar(name="Foxy")
     cultivar.common_name = CommonName(name="Foxglove")
     cultivar.common_name.index = Index(name="Perennial")
     db.session.add(cultivar)
     db.session.commit()
     dest = "seeds.add_packet"
     with app.test_client() as tc:
         rv = tc.post(url_for("seeds.select_cultivar", dest=dest), data=dict(cultivar=cultivar.id))
     print(rv.data)
     assert rv.location == url_for(dest, cv_id=str(cultivar.id), _external=True)
Exemplo n.º 8
0
 def test_add_one_with_section(self):
     """Add a Cultivar with Section to worksheet."""
     wb = Workbook()
     ws = wb.active
     cvws = CultivarsWorksheet(ws)
     cvws.setup()
     cv = Cultivar(name='Petra')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     cv.section = Section(name='Polkadot')
     cvws.add_one(cv)
     assert cvws.cell(2, cvws.cols['Section']).value == 'Polkadot'
Exemplo n.º 9
0
 def test_add_one_with_synonyms(self):
     """Add a Cultivar with synonyms to worksheet."""
     wb = Workbook()
     ws = wb.active
     cvws = CultivarsWorksheet(ws)
     cvws.setup()
     cv = Cultivar(name='Foxy')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     cv.synonyms_string = 'Vulpine'
     cvws.add_one(cv)
     assert cvws.cell(2, cvws.cols['Synonyms']).value == 'Vulpine'
Exemplo n.º 10
0
 def test_add_one_with_thumbnail_filename(self):
     """Add a Cultivar with a Thumbnail Filename to worksheet."""
     wb = Workbook()
     ws = wb.active
     cvws = CultivarsWorksheet(ws)
     cvws.setup()
     cv = Cultivar(name='Foxy')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     cv.thumbnail = Image(filename='foo.jpg')
     cvws.add_one(cv)
     assert cvws.cell(2, cvws.cols['Thumbnail Filename']).value == 'foo.jpg'
Exemplo n.º 11
0
 def test_add_one_with_description(self):
     """Add a Cultivar with a description to worksheet."""
     wb = Workbook()
     ws = wb.active
     cvws = CultivarsWorksheet(ws)
     cvws.setup()
     cv = Cultivar(name='Foxy')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     cv.description = 'Like a lady!'
     cvws.add_one(cv)
     assert cvws.cell(
         2, cvws.cols['Description']
     ).value == 'Like a lady!'
Exemplo n.º 12
0
 def test_add_one_with_botanical_name(self):
     """Add a Cultivar with a Botanical Name to worksheet."""
     wb = Workbook()
     ws = wb.active
     cvws = CultivarsWorksheet(ws)
     cvws.setup()
     cv = Cultivar(name='Foxy')
     cv.common_name = CommonName(name='Foxglove')
     cv.common_name.index = Index(name='Perennial')
     cv.botanical_name = BotanicalName(name='Digitalis purpurea')
     cvws.add_one(cv)
     assert cvws.cell(
         2, cvws.cols['Botanical Name']
     ).value == 'Digitalis purpurea'
Exemplo n.º 13
0
    def test_queryable_dicts_to_json(self):
        """Generate a JSON string for looking up Grows With cns/cvs.

        It can take either, as both have the queryable_dict method.
        """
        gwcn1 = CommonName(name='Foxglove')
        gwcn1.index = Index(name='Perennial')
        assert queryable_dicts_to_json([gwcn1]) == \
            json.dumps((gwcn1.queryable_dict,))
        gwcn2 = CommonName(name='Butterfly Weed')
        gwcn2.index = Index(name='Perennial')
        assert queryable_dicts_to_json([gwcn1, gwcn2]) == \
            json.dumps((gwcn1.queryable_dict, gwcn2.queryable_dict))
        gwcv1 = Cultivar(name='Soulmate')
        gwcv1.common_name = CommonName(name='Butterfly Weed')
        gwcv1.common_name.index = Index(name='Perennial')
        assert queryable_dicts_to_json([gwcv1]) == \
            json.dumps((gwcv1.queryable_dict,))
        gwcv2 = Cultivar(name='Petra')
        gwcv2.common_name = CommonName(name='Foxglove')
        gwcv2.common_name.index = Index(name='Perennial')
        gwcv2.section = Section(name='Polkadot')
        assert queryable_dicts_to_json([gwcv1, gwcv2]) == \
            json.dumps((gwcv1.queryable_dict, gwcv2.queryable_dict))
 def test_edit_packet_renders_page(self, app, db):
     """Render form page with valid pkt_id and no post data."""
     cultivar = Cultivar()
     packet = Packet()
     db.session.add_all([packet, cultivar])
     packet.price = Decimal("2.99")
     packet.quantity = Quantity(value=100, units="seeds")
     packet.sku = "8675309"
     cultivar.name = "Foxy"
     cultivar.common_name = CommonName(name="Foxglove")
     cultivar.packets.append(packet)
     db.session.commit()
     with app.test_client() as tc:
         rv = tc.get(url_for("seeds.edit_packet", pkt_id=packet.id))
     assert "Edit Packet" in str(rv.data)
 def test_select_packet_valid_submission(self, app, db):
     """Redirect to dest given valid selection."""
     cultivar = Cultivar()
     packet = Packet()
     db.session.add_all([cultivar, packet])
     cultivar.name = "Foxy"
     cultivar.common_name = CommonName(name="Foxglove")
     cultivar.packets.append(packet)
     packet.price = Decimal("1.99")
     packet.quantity = Quantity(value=100, units="seeds")
     packet.sku = "8675309"
     db.session.commit()
     with app.test_client() as tc:
         rv = tc.post(url_for("seeds.select_packet", dest="seeds.edit_packet"), data=dict(packet=packet.id))
     assert rv.location == url_for("seeds.edit_packet", pkt_id=packet.id, _external=True)
def foxy_cultivar():
    """Generate a Cultivar object based on Foxy Foxglove."""
    cultivar = Cultivar()
    cultivar.name = "Foxy"
    cultivar.description = "Not to be confused with that Hendrix song."
    bn = BotanicalName()
    bn.name = "Digitalis purpurea"
    cultivar.botanical_name = bn
    idx = Index()
    idx.name = "Perennial Flower"
    cn = CommonName()
    cn.name = "Foxglove"
    cn.index = idx
    cultivar.common_name = cn
    return cultivar
Exemplo n.º 17
0
    def test_add_one_with_new_until(self):
        """Add a Cultivar with New Until to worksheet.

        New Until values should be dates formatted MM/DD/YYYY because 'murica.
        """
        dt = datetime.date(2012, 12, 21)
        wb = Workbook()
        ws = wb.active
        cvws = CultivarsWorksheet(ws)
        cvws.setup()
        cv = Cultivar(name='Foxy')
        cv.common_name = CommonName(name='Foxglove')
        cv.common_name.index = Index(name='Perennial')
        cv.new_until = dt
        cvws.add_one(cv)
        assert cvws.cell(
            2, cvws.cols['New Until']
        ).value == dt.strftime('%m/%d/%Y')
 def test_cv_slugs_not_in_cultivar(self, app, db):
     """Return 404 if slugs return db entries, but entry not in cultivar."""
     app.config["SHOW_CULTIVAR_PAGES"] = True
     idx1 = Index()
     idx2 = Index()
     cn1 = CommonName()
     cn2 = CommonName()
     cultivar = Cultivar()
     db.session.add_all([idx1, idx2, cn1, cn2, cultivar])
     idx1.name = "Perennial Flower"
     idx2.name = "Long Hair"
     cn1.name = "Foxglove"
     cn2.name = "Persian"
     cultivar.name = "Foxy"
     cultivar.common_name = cn1
     db.session.commit()
     with app.test_client() as tc:
         rv = tc.get(url_for("seeds.cultivar", idx_slug=idx1.slug, cn_slug=cn2.slug, cv_slug=cultivar.slug))
     assert rv.status_code == 404
     with app.test_client() as tc:
         rv = tc.get(url_for("seeds.cultivar", idx_slug=idx2.slug, cn_slug=cn1.slug, cv_slug=cultivar.slug))
     assert rv.status_code == 404
Exemplo n.º 19
0
 def test_fullname_getter(self):
     """Return string with name and common_name."""
     cv = Cultivar(name='Polkadot Petra')
     cv.common_name = CommonName(name='Foxglove')
     assert cv.fullname == 'Polkadot Petra Foxglove'