Пример #1
0
    def test_export(self):
        xls = TempXLS()

        directory = self.add_directory()
        directory.title = u'test'
        directory.cat1 = u'Testkategorie 1'
        directory.cat2 = u'Testkategorie 2'

        item = self.add_item(directory, 'item1')
        item.description = u'description1'

        categorized = IDirectoryCategorized(item)
        categorized.cat1 = [u'Eins']
        categorized.cat2 = [u'Zwei']

        item = self.add_item(directory, 'item2')
        categorized = IDirectoryCategorized(item)
        categorized.cat1 = [u'One']
        categorized.cat2 = [u'Two']

        export_xls(directory, xls.file, 'de', False)

        wb = xls.load()
        ws = wb.sheet_by_index(0)

        self.assertEqual(ws.nrows, 3)

        self.assertEqual(ws.cell(1, 0).value, u'item1')
        self.assertEqual(ws.cell(1, 1).value, u'description1')
        self.assertEqual(ws.cell(1, 2).value, u'Eins')
        self.assertEqual(ws.cell(1, 3).value, u'Zwei')

        self.assertEqual(ws.cell(2, 0).value, u'item2')
        self.assertEqual(ws.cell(2, 1).value, u'')
        self.assertEqual(ws.cell(2, 2).value, u'One')
        self.assertEqual(ws.cell(2, 3).value, u'Two')
Пример #2
0
    def test_export(self):
        xls = TempXLS()

        directory = self.add_directory()
        directory.title = u'test'
        directory.cat1 = u'Testkategorie 1'
        directory.cat2 = u'Testkategorie 2'

        item = self.add_item(directory, 'item1')
        item.description = u'description1'

        categorized = IDirectoryCategorized(item)
        categorized.cat1 = [u'Eins']
        categorized.cat2 = [u'Zwei']

        item = self.add_item(directory, 'item2')
        categorized = IDirectoryCategorized(item)
        categorized.cat1 = [u'One']
        categorized.cat2 = [u'Two']

        export_xls(directory, xls.file, 'de', False)

        wb = xls.load()
        ws = wb.sheet_by_index(0)

        self.assertEqual(ws.nrows, 3)

        self.assertEqual(ws.cell(1, 0).value, u'item1')
        self.assertEqual(ws.cell(1, 1).value, u'description1')
        self.assertEqual(ws.cell(1, 2).value, u'Eins')
        self.assertEqual(ws.cell(1, 3).value, u'Zwei')

        self.assertEqual(ws.cell(2, 0).value, u'item2')
        self.assertEqual(ws.cell(2, 1).value, u'')
        self.assertEqual(ws.cell(2, 2).value, u'One')
        self.assertEqual(ws.cell(2, 3).value, u'Two')
Пример #3
0
    def test_categories(self):
        directory = self.add_directory()
        directory.cat1 = 'One'
        directory.cat2 = 'Two'
        directory.cat3 = 'Three'

        item = self.add_item(directory)

        # only present after setting them on the behavior
        self.assertFalse(hasattr(aq_base(item), 'cat1'))
        self.assertFalse(hasattr(aq_base(item), 'cat2'))
        self.assertFalse(hasattr(aq_base(item), 'cat3'))
        self.assertFalse(hasattr(aq_base(item), 'cat4'))

        categorized = IDirectoryCategorized(item)
        self.assertTrue(hasattr(categorized, 'cat1'))
        self.assertTrue(hasattr(categorized, 'cat2'))
        self.assertTrue(hasattr(categorized, 'cat3'))
        self.assertTrue(hasattr(categorized, 'cat4'))

        categorized.cat1 = '1'
        categorized.cat2 = '2'
        categorized.cat3 = '3'
        categorized.cat4 = '4'  # Will be ignored

        self.assertTrue(hasattr(aq_base(item), 'cat1'))
        self.assertTrue(hasattr(aq_base(item), 'cat2'))
        self.assertTrue(hasattr(aq_base(item), 'cat3'))
        self.assertTrue(hasattr(aq_base(item), 'cat4'))

        categories = categorized.categories()
        self.assertEqual(len(categories), 3)

        item_used = [c[0] for c in categories]
        dir_used = directory.used_categories()
        self.assertEqual(item_used, dir_used)

        item_labels = [c[1] for c in categories]
        dir_labels = directory.labels().values()
        self.assertEqual(item_labels, dir_labels)

        values = [c[2] for c in categories]
        self.assertEqual(values, ['1', '2', '3'])

        # Set the category to contain multiple keywords and use only
        # one category
        categorized.cat1 = ['tag one', 'tag two']
        directory.cat2 = None
        directory.cat3 = None

        categories = categorized.categories()

        self.assertEqual(len(categories), 1)
        self.assertEqual(categories[0][2], ['tag one', 'tag two'])

        # Set more categories and see if the keywords function correctly
        # returns all keywords flattened, even if invisible

        categorized.cat1 = ['Ready', 'Or']
        categorized.cat2 = 'Not'
        categorized.cat3 = ['Here', 'I']
        categorized.cat4 = 'Come'

        keywords = categorized.keywords()
        self.assertEqual(keywords, ['Ready', 'Or', 'Not', 'Here', 'I', 'Come'])
Пример #4
0
    def test_categories(self):
        directory = self.add_directory()
        directory.cat1 = 'One'
        directory.cat2 = 'Two'
        directory.cat3 = 'Three'

        item = self.add_item(directory)

        # only present after setting them on the behavior
        self.assertFalse(hasattr(aq_base(item), 'cat1'))
        self.assertFalse(hasattr(aq_base(item), 'cat2'))
        self.assertFalse(hasattr(aq_base(item), 'cat3'))
        self.assertFalse(hasattr(aq_base(item), 'cat4'))

        categorized = IDirectoryCategorized(item)
        self.assertTrue(hasattr(categorized, 'cat1'))
        self.assertTrue(hasattr(categorized, 'cat2'))
        self.assertTrue(hasattr(categorized, 'cat3'))
        self.assertTrue(hasattr(categorized, 'cat4'))

        categorized.cat1 = '1'
        categorized.cat2 = '2'
        categorized.cat3 = '3'
        categorized.cat4 = '4'  # Will be ignored

        self.assertTrue(hasattr(aq_base(item), 'cat1'))
        self.assertTrue(hasattr(aq_base(item), 'cat2'))
        self.assertTrue(hasattr(aq_base(item), 'cat3'))
        self.assertTrue(hasattr(aq_base(item), 'cat4'))

        categories = categorized.categories()
        self.assertEqual(len(categories), 3)

        item_used = [c[0] for c in categories]
        dir_used = directory.used_categories()
        self.assertEqual(item_used, dir_used)

        item_labels = [c[1] for c in categories]
        dir_labels = directory.labels().values()
        self.assertEqual(item_labels, dir_labels)

        values = [c[2] for c in categories]
        self.assertEqual(values, ['1', '2', '3'])

        # Set the category to contain multiple keywords and use only
        # one category
        categorized.cat1 = ['tag one', 'tag two']
        directory.cat2 = None
        directory.cat3 = None

        categories = categorized.categories()

        self.assertEqual(len(categories), 1)
        self.assertEqual(categories[0][2], ['tag one', 'tag two'])

        # Set more categories and see if the keywords function correctly
        # returns all keywords flattened, even if invisible

        categorized.cat1 = ['Ready', 'Or']
        categorized.cat2 = 'Not'
        categorized.cat3 = ['Here', 'I']
        categorized.cat4 = 'Come'

        keywords = categorized.keywords()
        self.assertEqual(keywords, ['Ready', 'Or', 'Not', 'Here', 'I', 'Come'])