コード例 #1
0
 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)
コード例 #2
0
 def test_edit_packet_submission_change_inputs(self, app, db):
     """Change packet and flash message if new values present in inputs."""
     packet = Packet()
     db.session.add(packet)
     packet.price = Decimal("1.99")
     packet.quantity = Quantity(value=100, units="seeds")
     packet.sku = "8675309"
     packet.cultivar = Cultivar(name="Foxy")
     db.session.commit()
     with app.test_client() as tc:
         tc.post(
             url_for("seeds.edit_packet", pkt_id=packet.id),
             data=dict(
                 id=packet.id,
                 cultivar_id=packet.cultivar.id,
                 price="2.99",
                 qty_val="2.5",
                 units="grams",
                 sku="BOUT350",
             ),
             follow_redirects=True,
         )
     assert packet.price == Decimal("2.99")
     assert packet.quantity.value == Decimal("2.5")
     assert packet.quantity.units == "grams"
     assert packet.sku == "BOUT350"
コード例 #3
0
 def test_info_getter(self):
     """Return a string containing onformation on the packet."""
     pk = Packet()
     pk.sku = '8675309'
     pk.price = '3.50'
     assert pk.info == 'SKU #8675309: $3.50 for None None'
     pk.quantity = Quantity(100, 'seeds')
     assert pk.info == 'SKU #8675309: $3.50 for 100 seeds'
コード例 #4
0
 def test_remove_packet_renders_page(self, app, db):
     """Render form page given a valid packet id."""
     packet = Packet()
     db.session.add(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.get(url_for("seeds.remove_packet", pkt_id=packet.id))
     assert "Remove Packet" in str(rv.data)
コード例 #5
0
 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)
コード例 #6
0
 def test_remove_packet_submission_verified(self, app, db):
     """Delete packet and flash a message if verify_removal is checked."""
     packet = Packet()
     db.session.add(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:
         tc.post(
             url_for("seeds.remove_packet", pkt_id=packet.id), data=dict(verify_removal=True), follow_redirects=True
         )
     assert Packet.query.count() == 0
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
0
 def test_remove_packet_submission_no_changes(self, app, db):
     """Redirect and flash a message if verify_removal unchecked."""
     packet = Packet()
     db.session.add(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.remove_packet", pkt_id=packet.id), data=dict(verify_removal=None))
     assert rv.location in url_for("seeds.remove_packet", pkt_id=packet.id, _external=True)
     with app.test_client() as tc:
         rv = tc.post(
             url_for("seeds.remove_packet", pkt_id=packet.id), data=dict(verify_removal=None), follow_redirects=True
         )
     assert "Packet was not removed" in str(rv.data)
コード例 #10
0
 def test_repr(self):
     """Return a string representing a packet."""
     pk = Packet()
     pk.sku = '8675309'
     assert pk.__repr__() == '<Packet SKU #8675309>'