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_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
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)
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
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_from_queryable_dict(self, m_fqv): """Call Cultivar.from_queryable_values with dict values.""" d = {'Cultivar Name': 'Foxy', 'Common Name': 'Foxglove', 'Index': 'Perennial'} Cultivar.from_queryable_dict(d) m_fqv.assert_called_with(name='Foxy', common_name='Foxglove', index='Perennial')
def test_add_packet_renders_page(self, app, db): """Render form page given a valid cv_id.""" cultivar = Cultivar() db.session.add(cultivar) cultivar.name = "Foxy" db.session.commit() with app.test_client() as tc: rv = tc.get(url_for("seeds.add_packet", cv_id=cultivar.id)) assert "Add a Packet" in str(rv.data)
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'
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)
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'
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'
def test_validate_sku(self, db): """Raise ValidationError if SKU already exists in db.""" packet = Packet() cultivar = Cultivar() db.session.add_all([packet, cultivar]) packet.sku = '8675309' cultivar.name = 'Jenny' packet.cultivar = cultivar db.session.commit() form = AddPacketForm(cultivar=cultivar) form.sku.data = '8675309' with pytest.raises(ValidationError): form.validate_sku(form.sku)
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'
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!'
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 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 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
def generate_cultivars(cn, l): for d in l: cv = Cultivar.get_or_create(d['name'], cn) db.session.add(cv) cv.visible = True cv.active = True cv.subtitle = d['subtitle'] cv.botanical_name = d['botanical_names'] cv.description = d['description'] if d['veg_info']: if d['veg_info']['open_pollinated']: cv.open_pollinated = True if d['veg_info']['maturation']: cv.maturation = d['veg_info']['maturation'] try: cv.new_for = int(d['new_for']) except ValueError: pass cv.featured = d['favorite'] cv.favorite = d['favorite'] cv.in_stock = d['packets'][0]['in_stock'] if 'organic' in cv.description.lower(): cv.organic = True cv.taxable = d['packets'][0]['taxable'] cv.images = [download_image(i) for i in d['images']] cv.thumbnail = cv.images[0] cv.packets = list(generate_packets(d['packets'])) yield cv
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_from_queryable_values(self, db): """Return the correct Cultivar based on values given.""" cn = CommonName(name='Foxglove', index=Index(name='Perennial')) cv = Cultivar(name='Polkadot Petra', common_name=cn) db.session.add(cv) db.session.commit() assert Cultivar.from_queryable_values(name='Polkadot Petra', common_name='Foxglove', index='Perennial') is cv
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
def set_related_links(): with open('/tmp/related_links.json', 'r', encoding='utf-8') as ifile: dicts = json.loads(ifile.read()) print('Setting related links/grows with...') for d in dicts: cn = CommonName.from_slugs( d['source']['idx_slug'], d['source']['cn_slug'] ) if d['target']['anchor']: t = Cultivar.from_slugs( d['target']['idx_slug'], d['target']['cn_slug'], d['target']['anchor'] ) if t: cn.gw_cultivars.append(t) else: t = Section.from_slugs( d['target']['idx_slug'], d['target']['cn_slug'], d['target']['anchor'] ) if t: cn.gw_sections.append(t) else: print( 'Could not find a Section or Cultivar with the ' 'slug: "{}"'.format(d['target']['anchor']) ) t = CommonName.from_slugs( d['target']['idx_slug'], d['target']['cn_slug'] ) cn.gw_common_names.append(t) else: t = CommonName.from_slugs( d['target']['idx_slug'], d['target']['cn_slug'] ) if t: cn.gw_common_names.append(t) else: print('Could not find gw for {}'.format(d)) if t: print( '"{}" grows with the {} "{}"' .format(cn.name, t.__class__.__name__, t.name) ) db.session.commit()
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_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 save_row_to_db(self, row, stream=sys.stdout): """Save a row from the Packets sheet to the database. Args: row: The number of the row to save. stream: Optional IO stream to print messages to. Returns: bool: `True` if changes have been made, `False` if not. """ cultivar_json = self.cell(row, self.cols['Cultivar (JSON)']).value cv_dict = json.loads(cultivar_json) sku = self.cell(row, self.cols['SKU']).value price = self.cell(row, self.cols['Price']).value quantity = self.cell(row, self.cols['Quantity']).value units = self.cell(row, self.cols['Units']).value print('-- BEGIN editing/creating Packet with the SKU \'{0}\' from row ' '#{1}. --'.format(sku, row), file=stream) edited = False pkt = Packet.query.filter(Packet.sku == sku).one_or_none() if pkt: print('The Packet with SKU \'{0}\' has been loaded from the ' 'database.'.format(pkt.sku), file=stream) else: edited = True qty = Quantity.from_queryable_values(value=quantity, units=units) if not qty: qty = Quantity(value=quantity, units=units) pkt = Packet(sku=sku, price=price, quantity=qty) db.session.add(pkt) pkt.cultivar = Cultivar.get_or_create( name=dbify(cv_dict['Cultivar Name']), common_name=dbify(cv_dict['Common Name']), index=dbify(cv_dict['Index']), stream=stream ) print('The Packet with SKU \'{0}\' does not yet exist, so it has ' 'been created.'.format(pkt.sku), file=stream) if price != str(pkt.price): edited = True pkt.price = price print('The price for Packet SKU \'{0}\' has been set to: ${1}.' .format(pkt.sku, pkt.price), file=stream) qty = Quantity.from_queryable_values(value=quantity, units=units) if not qty: qty = Quantity(value=quantity, units=units) if qty is not pkt.quantity: edited = True pkt.quantity = qty print('The quantity for the Packet SKU \'{0}\' has been set to: ' '{1} {2}'.format(pkt.sku, qty.value, qty.units), file=stream) if edited: db.session.flush() print('Changes to the Packet \'{0}\' have been flushed to ' 'the database.'.format(pkt.info), file=stream) else: print('No changes were made to the Packet \'{0}\'.' .format(pkt.info), file=stream) print('-- END editing/creating Packet with SKU \'{0}\' from row #{1}. ' '--'.format(pkt.sku, row), file=stream) return edited
def save_row_to_db(self, row, stream=sys.stdout): """Save a row from the Cultivars sheet to the database. Args: row: The number of the row to save. stream: Optional IO stream to print messages to. Returns: bool: `True` if changes have been made, `False` if not. """ index = dbify(self.cell(row, self.cols['Index']).value) common_name = dbify(self.cell(row, self.cols['Common Name']).value) cultivar = dbify(self.cell(row, self.cols['Cultivar Name']).value) section = dbify(self.cell(row, self.cols['Section']).value) if not section: section = None botanical_name = self.cell(row, self.cols['Botanical Name']).value thumbnail = self.cell(row, self.cols['Thumbnail Filename']).value description = self.cell(row, self.cols['Description']).value synonyms = self.cell(row, self.cols['Synonyms']).value if not synonyms: synonyms = '' nus = self.cell(row, self.cols['New Until']).value if nus: new_until = datetime.datetime.strptime(nus, '%m/%d/%Y').date() else: new_until = None n_stk = self.cell(row, self.cols['In Stock']).value if n_stk and 'true' in n_stk.lower(): in_stock = True else: in_stock = False act = self.cell(row, self.cols['Active']).value if act and 'true' in act.lower(): active = True else: active = False vis = self.cell(row, self.cols['Visible']).value if vis and 'true' in vis.lower(): visible = True else: visible = False print('-- BEGIN editing/creating Cultivar \'{0}\' from row #{1}. ' '--'.format(cultivar + ' ' + common_name, row), file=stream) edited = False cv = Cultivar.get_or_create(name=cultivar, index=index, common_name=common_name, stream=stream) if cv.created: edited = True db.session.add(cv) if section: # Section already exists if cv was not created. sec = Section.query\ .join(CommonName, CommonName.id == Section.common_name_id)\ .join(Index, Index.id == CommonName.index_id)\ .filter(Section.name == section, CommonName.name == common_name, Index.name == index)\ .one_or_none() if sec: print('The Section \'{0}\' has been loaded from the ' 'database.'.format(sec.name), file=stream) else: sec = Section(name=section) sec.common_name = cv.common_name print('The Section \'{0}\' does not yet exist, so it has ' 'been created.'.format(sec.name), file=stream) cv.section = sec print('Section for the Cultivar \'{0}\' set to: {1}' .format(cv.fullname, sec.name), file=stream) if botanical_name: if not BotanicalName.validate(botanical_name): obn = botanical_name words = botanical_name.strip().split(' ') words[0] = words[0].capitalize() botanical_name = ' '.join(words) print('The BotanicalName \'{0}\' does not appear to be a ' 'validly formatted botanical name. In an attempt to fix ' 'it, it has been changed to: \'{1}\'' .format(obn, botanical_name), file=stream) bn = BotanicalName.query\ .filter(BotanicalName.name == botanical_name)\ .one_or_none() if bn and bn is not cv.botanical_name: print('The BotanicalName \'{0}\' has been loaded from the ' 'database.'.format(bn.name), file=stream) elif not bn: bn = BotanicalName(name=botanical_name) bn.common_names.append(cv.common_name) print('The BotanicalName \'{0}\' does not yet exist, so it ' 'has been created.'.format(bn.name), file=stream) if bn is not cv.botanical_name: edited = True cv.botanical_name = bn print('BotanicalName for the Cultivar \'{0}\' set to: {1}' .format(cv.fullname, bn.name), file=stream) if thumbnail: if not cv.thumbnail or cv.thumbnail.filename != thumbnail: edited = True tn = Image.query\ .filter(Image.filename == thumbnail)\ .one_or_none() if tn: print('The Image with the filename \'{0}\' has been ' 'loaded from the database.'.format(tn.filename), file=stream) else: tn = Image(filename=thumbnail) print('The Image with the filename \'{0}\' does not yet ' 'exist in the database, so it has been created.' .format(tn.filename), file=stream) cv.thumbnail = tn print('The Image with the filename \'{0}\' has been set as ' 'the thumbnail for the Cultivar \'{1}\'.' .format(tn.filename, cv.fullname), file=stream) if not tn.exists(): print('WARNING: The image file \'{0}\' set as the ' 'thumbnail for the Cultivar \'{1}\' does not exist! ' 'Please make sure you add the image file to the ' 'images directory.'.format(tn.filename, cv.fullname), file=stream) if description != cv.description: edited = True if description: cv.description = description print('Description for the Cultivar \'{0}\' set to: {1}' .format(cv.fullname, cv.description), file=stream) else: cv.description = None print('Description for the Cultivar \'{0}\' has been cleared.' .format(cv.fullname), file=stream) if synonyms != cv.synonyms_string: edited = True cv.synonyms_string = synonyms if synonyms: print('Synonyms for the Cultivar \'{0}\' set to: {1}' .format(cv.fullname, cv.synonyms_string), file=stream) else: print('Synonyms for the Cultivar \'{0}\' have been cleared.' .format(cv.fullname), file=stream) if new_until != cv.new_until: edited = True if new_until: cv.new_until = new_until print('The Cultivar \'{0}\' has been set as new until {1}.' .format(cv.fullname, cv.new_until.strftime('%m/%d/%Y')), file=stream) else: cv.new_until = None print('The Cultivar \'{0}\' is no longer set as new.' .format(cv.fullname), file=stream) if in_stock != cv.in_stock: edited = True cv.in_stock = in_stock if cv.in_stock: print('The Cultivar \'{0}\' is in stock.'.format(cv.fullname), file=stream) else: print('The Cultivar \'{0}\' is out of stock.' .format(cv.fullname), file=stream) if active != cv.active: edited = True cv.active = active if cv.active: print('The Cultivar \'{0}\' is active.'.format(cv.fullname), file=stream) else: print('The Cultivar \'{0}\' is inactive.'.format(cv.fullname), file=stream) if visible != cv.visible: edited = True cv.visible = visible if cv.visible: print('The Cultivar \'{0}\' will be shown on auto-generated ' 'pages.'.format(cv.fullname), file=stream) else: print('The Cultivar \'{0}\' will not be shown on ' 'auto-generated pages.'.format(cv.fullname), file=stream) if edited: db.session.flush() print('Changes to the Cultivar \'{0}\' have been flushed to ' 'the database.'.format(cv.fullname), file=stream) else: print('No changes were made to the Cultivar \'{0}\'.' .format(cv.fullname), file=stream) print('-- END editing/creating Cultivar \'{0}\' from row #{1}. ' '--'.format(cv.fullname, row), file=stream) return edited
def test_repr(self, m_fn): """Return a string formatted <Cultivar '<fullname>'>""" m_fn.return_value = 'Full Cultivar Name' cv = Cultivar() assert cv.__repr__() == '<Cultivar "Full Cultivar Name">'
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'