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_setup_new(self, m_s): """Run _setup with titles on setup of new worksheet.""" wb = Workbook() ws = wb.active pws = PacketsWorksheet(ws) pws.setup() titles = ('Cultivar (JSON)', 'SKU', 'Price', 'Quantity', 'Units') m_s.assert_called_with(titles)
def test_setup_existing(self, m_s): """Run _setup with no args on setup of sheet with titles.""" wb = Workbook() ws = wb.active sws = SeedsWorksheet(ws) sws.set_column_titles(('One', 'Two', 'Three')) pws = PacketsWorksheet(sws._ws) pws.setup() assert m_s.call_args_list == [mock.call()]
def test_add_one_not_packet(self): """Raise TypeError given non-Packet data.""" wb = Workbook() ws = wb.active pws = PacketsWorksheet(ws) pws.setup() with pytest.raises(TypeError): pws.add_one(42) with pytest.raises(TypeError): pws.add_one(Cultivar(name='Foxy'))