示例#1
0
 def test_setup_new(self, m_s):
     """Run _setup with the titles for the Section worksheet."""
     wb = Workbook()
     ws = wb.active
     srws = SectionsWorksheet(ws)
     srws.setup()
     titles = ('Common Name (JSON)', 'Section', 'Description')
     m_s.assert_called_with(titles)
示例#2
0
 def test_setup_existing(self, m_s):
     """Run _setup with no arguments if titles apready present."""
     wb = Workbook()
     ws = wb.active
     sws = SeedsWorksheet(ws)
     sws.set_column_titles(('One', 'Two', 'Three'))
     srws = SectionsWorksheet(sws._ws)
     srws.setup()
     assert m_s.call_args_list == [mock.call()]
示例#3
0
 def test_add_one_not_section(self):
     """Raise a TypeError if passed argument is not a Section object."""
     wb = Workbook()
     ws = wb.active
     srws = SectionsWorksheet(ws)
     srws.setup()
     with pytest.raises(TypeError):
         srws.add_one(42)
     with pytest.raises(TypeError):
         srws.add_one(Index(name='Perennial'))
示例#4
0
 def test_add_one_with_description(self):
     """Set Description column's cell with Section desc."""
     wb = Workbook()
     ws = wb.active
     srws = SectionsWorksheet(ws)
     srws.setup()
     sr = Section(name='Polkadot', description='A bit spotty.')
     sr.common_name = CommonName(name='Foxglove')
     sr.common_name.index = Index(name='Perennial')
     srws.add_one(sr)
     assert srws.cell(
         2, srws.cols['Description']
     ).value == 'A bit spotty.'
示例#5
0
 def test_add_one_no_optionals(self):
     """Add a Section object to the Section worksheet."""
     messages = StringIO()
     wb = Workbook()
     ws = wb.active
     srws = SectionsWorksheet(ws)
     srws.setup()
     sr = Section(name='Polkadot')
     sr.common_name = CommonName(name='Foxglove')
     sr.common_name.index = Index(name='Perennial')
     srws.add_one(sr, stream=messages)
     assert srws.cell(
         2, srws.cols['Common Name (JSON)']
     ).value == json.dumps(sr.common_name.queryable_dict)
     assert srws.cell(2, srws.cols['Section']).value == 'Polkadot'
     assert srws.cell(2, srws.cols['Description']).value is None
     messages.seek(0)
     msgs = messages.read()
     assert ('Adding data from <Section "Polkadot Foxglove"> to row #2 '
             'of sections worksheet') in msgs