示例#1
0
class TestDuplicate(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()
        settings.Preferences().overrideKeyGeneration = True

    def tearDown(self):
        pass

    def testDuplicateExistingEntry(self):
        for entry in oracle.all_entries_all_fields:
            first_id = self.ui.addEntry(entry.getBibTeX())
            first_entry = self.ui.getEntry(first_id)
            for i in range(27):
                _id = self.ui.duplicateEntry(first_id)
                self.assertIsNotNone(_id, '%s not duplicated.' % entry)
                e = self.ui.getEntry(_id)
                self.assertEqual(
                    e[EntryListColumn.Entrykey],
                    first_entry[EntryListColumn.Entrykey] + chr(ord('a') + i),
                    'incorrect key in duplicate of %s.' % entry)

    def testDuplicateNonExistingEntry(self):
        _id = 0
        for entry in oracle.all_entries_all_fields:
            _id = self.ui.addEntry(entry.getBibTeX())
        _id = self.ui.duplicateEntry(_id + 1)
        self.assertIsNone(_id, 'non-existing entry wrongly duplicated.')
示例#2
0
class TestPreview(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()

    def tearDown(self):
        pass

    def testPreviewACMAllFields(self):
        Preferences().bibStyle = BibStyle.ACM
        for entry in oracle.all_entries_all_fields:
            _id = self.ui.addEntry(entry.getBibTeX())
            if _id:
                html = self.ui.previewEntry(_id)
                self.assertEqual(html, entry.getACM_HTML(),
                                 '%s was not previewed correctly.' % entry)

    def testPreviewACMMissingOptionalFields(self):
        Preferences().bibStyle = BibStyle.ACM
        for entry in oracle.all_entry_types:
            _id = self.ui.addEntry(entry.getBibTeX())
            if _id:
                html = self.ui.previewEntry(_id)
                self.assertEqual(html, entry.getACM_HTML(),
                                 '%s was not previewed correctly.' % entry)

    def testPreviewACMNonExistingEntry(self):
        Preferences().bibStyle = BibStyle.ACM
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        self.assertRaises(Exception, self.ui.previewEntry, _id + 1)

    def testPreviewACMAuthorVariants(self):
        Preferences().bibStyle = BibStyle.ACM
        for entry in oracle.valid_authors:
            _id = self.ui.addEntry(entry.getBibTeX())
            if _id:
                html = self.ui.previewEntry(_id)
                self.assertEqual(html, entry.getACM_HTML(),
                                 '%s was not previewed correctly.' % entry)
示例#3
0
class TestDelete(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()

    def tearDown(self):
        pass

    def testDeleteInSingletonDB(self):
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        result = self.ui.deleteEntry(_id)
        self.assertTrue(result, '%s not deleted.' % oracle.valid_entry_full)
        self.assertEqual(self.ui.getEntryCount(), 0,
                         '%s not deleted.' % oracle.valid_entry_full)

    def testDeleteInNonEmptyDB(self):
        for e in oracle.all_entry_types:
            self.ui.addEntry(e.getBibTeX())
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        result = self.ui.deleteEntry(_id)
        self.assertTrue(result, '%s not deleted.' % oracle.valid_entry_full)
        self.assertEqual(self.ui.getEntryCount(), len(oracle.all_entry_types),
                         '%s not deleted.' % oracle.valid_entry_full)

    def testDeleteInEmptyDB(self):
        result = self.ui.deleteEntry(0)
        self.assertFalse(result, 'non-existing entry wrongly deleted.')

    def testDeleteNonExistingEntry(self):
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        result = self.ui.deleteEntry(_id + 1)
        self.assertFalse(result, 'non-existing entry wrongly deleted.')

    def testDeleteAddSanity(self):
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        self.ui.deleteEntry(_id)
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        e = self.ui.getEntry(_id)
        self.assertEqual(
            self.ui.getEntryCount(), 1,
            'deleting an entry then adding it back did not undo the deletion.')
        self.assertTrue(
            e[EntryListColumn.Entrykey].endswith(e[EntryListColumn.Year]),
            'deleting an entry then adding it back generated an incorrect key.'
        )
示例#4
0
class TestSort(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()
        c = 'z'
        for e in oracle.all_entries:
            _id = self.ui.addEntry(e.getBibTeX())
            entry = self.ui.getEntry(_id)
            for field in EntryListColumn.list():
                entry[field] = c + str(entry[field])
            result = self.ui.updateEntry(_id, entry.toBibTeX())
            if not result:
                raise Exception(
                    'Something went wrong when setting up the test cases.')
            c = chr(ord(c) - 1)

    def tearDown(self):
        pass

    def testSortEveryColumn(self):
        for col in EntryListColumn.list():
            result = self.ui.sort(col)
            self.assertTrue(result, 'Sorting failed on column %s.' % col)
            self.assertEqual(self.ui.getEntryCount(), len(oracle.all_entries),
                             'The number of entries was not preserved.')

    def testSortInvalidColumn(self):
        result = self.ui.sort('xyz')
        self.assertTrue(result, 'Sorted an invalid column.')
        self.assertEqual(self.ui.getEntryCount(), len(oracle.all_entries),
                         'The number of entries was not preserved.')

    def testSortSanity(self):
        for col in EntryListColumn.list():
            result = self.ui.sort(col)
            result = result and self.ui.sort(col)
            self.assertTrue(result, 'Sorting failed on column %s.' % col)
            self.assertEqual(self.ui.getEntryCount(), len(oracle.all_entries),
                             'The number of entries was not preserved.')
示例#5
0
class TestUpdate(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()
        self._ids = []
        for e in oracle.all_entries_all_fields:
            self._ids.append(self.ui.addEntry(e.getBibTeX()))
        self.total = len(oracle.all_entries_all_fields)
        settings.Preferences().overrideKeyGeneration = True

    def tearDown(self):
        pass
    
    def testUpdateAllFields(self):
        for i in self._ids:
            expected_entry = self.ui.getEntry(i)
            for col in list(expected_entry.keys()):
                if col in [EntryListColumn.Entrytype, EntryListColumn.Entrykey, EntryListColumn.Id,
                           EntryListColumn.Valid, EntryListColumn.Message]:  # tested in other test cases
                    continue
                expected_entry[col] = 'Abc'
            if expected_entry[EntryListColumn.Entrytype].lower() == 'book':
                del expected_entry[EntryListColumn.Author]
                expected_entry['number'] = ''
            bib = expected_entry.toBibTeX()
            result = self.ui.updateEntry(i, bib)
            if not result:
                pass
            self.assertTrue(result, 'entry not updated.')
            self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
            observed_entry = self.ui.getEntry(i)
            for col in list(observed_entry.keys()):
                if col == 'message':
                    pass
                if col == EntryListColumn.Entrykey:
                    continue
                self.assertEqual(observed_entry[col], expected_entry[col], 'field %s not updated.' % col)
    
    def testUpdateAuthorYear(self):
        suffix = ''
        for ix in range(len(self._ids)):
            i = self._ids[ix]
            expected_entry = self.ui.getEntry(i)
            if oracle.all_entries_all_fields[ix] == oracle.valid_book_all_fields_editor:
                expected_entry['editor'] = 'Xyz'
            else:
                expected_entry[EntryListColumn.Author] = 'Xyz'
            expected_entry[EntryListColumn.Year] = '0000'
            bib = expected_entry.toBibTeX()
            result = self.ui.updateEntry(i, bib)
            self.assertTrue(result, 'entry not updated to %s.' % expected_entry)
            observed_entry = self.ui.getEntry(i)
            self.assertEqual(observed_entry[EntryListColumn.Entrykey], 'Xyz0000' + suffix, 'key not correctly updated.')
            self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
            if suffix == '':
                suffix = 'a'
            elif suffix == 'z':
                break
            else:
                suffix = chr(ord(suffix) + 1)
    
    def testUpdateType(self):
        for i in self._ids:
            expected_entry = oracle.valid_article_all_fields
            if self.ui.getEntry(i)[EntryListColumn.Entrytype].lower() == 'article':
                expected_entry = oracle.valid_inproceedings_all_fields
            result = self.ui.updateEntry(i, expected_entry.getBibTeX())
            self.assertTrue(result, 'entry not updated to %s.' % expected_entry)
            self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
 
    def testUpdateNonExistingEntry(self):
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        result = self.ui.updateEntry(_id + 10, oracle.valid_entry_full.getBibTeX())
        self.assertFalse(result, 'non-existing entry wrongly updated.')
 
    def testUpdateMissingRequiredFields(self):
        for i in self._ids:
            for e in oracle.all_invalid_entry_types_no_req:
                self.assertRaises(Exception, lambda: self.ui.updateEntry(i, e.getBibTeX()), 'entry updated to %s.' % e)
                self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
     
    def testUpdateUpdateSanity(self):
        for i in self._ids:
            old_entry = self.ui.getEntry(i)
            new_entry = oracle.valid_entry_full
            result1 = self.ui.updateEntry(i, new_entry.getBibTeX())
            result2 = self.ui.updateEntry(i, old_entry.toBibTeX())
            self.assertTrue(result1 and result2, 'modifying %s back to itself did not retain changes.' % old_entry)
            self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
示例#6
0
class TestAdd(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()
        settings.Preferences().allowInvalidEntries = False
        settings.Preferences().overrideKeyGeneration = True

    def tearDown(self):
        pass

    def testAddEmptyEntryFromNone(self):
        _id = self.ui.addEntry(None)
        self.assertIsNotNone(_id, 'empty entry not added.')
        self.assertEqual(self.ui.getEntryCount(), 1, 'empty entry not added.')

    def testAddEmptyEntryFromEmptyString(self):
        _id = self.ui.addEntry('')
        self.assertIsNotNone(_id, 'empty entry not added.')
        self.assertEqual(self.ui.getEntryCount(), 1, 'empty entry not added.')

    def testAddInEmptyEntryWithType(self):
        for t in EntryType.getAllEntryTypes():
            _id = self.ui.addEntry(None, t.lower())
            self.assertIsNotNone(_id, 'empty %s entry not added.' % t)

    def testAddInEmptyDB(self):
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        self.assertIsNotNone(_id, '%s not added.' % oracle.valid_entry_full)
        self.assertEqual(self.ui.getEntryCount(), 1,
                         '%s not added.' % oracle.valid_entry_full)

    def testAddValidBibTeX(self):
        for e in oracle.all_entries:
            _id = self.ui.addEntry(e.getBibTeX())
            self.assertIsNotNone(_id, '%s not added.' % e)

    def testAddValidBibTeXVariants(self):
        for e in oracle.valid_bibtex_variants:
            _id = self.ui.addEntry(e.getBibTeX())
            self.assertIsNotNone(_id, '%s not added.' % e)

    def testAddInNonEmptyDB(self):
        for e in oracle.all_entry_types:
            self.ui.addEntry(e.getBibTeX())
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        self.assertIsNotNone(_id, '%s not added.' % oracle.valid_entry_full)
        self.assertEqual(self.ui.getEntryCount(),
                         len(oracle.all_entry_types) + 1,
                         '%s not added.' % oracle.valid_entry_full)

    def testAddExistingEntry(self):
        entry = oracle.valid_entry_full
        self.ui.addEntry(entry.getBibTeX())
        _id = self.ui.addEntry(entry.getBibTeX())
        self.assertIsNotNone(_id, 'entry not added.')
        self.assertTrue(
            self.ui.getEntry(_id)[EntryListColumn.Entrykey].endswith('a'),
            'incorrect key in duplicate of %s.' % entry)
        self.assertEqual(self.ui.getEntryCount(), 2,
                         '%s not added.' % oracle.valid_entry_full)

    def testAddMissingRequiredField(self):
        for e in oracle.all_invalid_entry_types_no_req:
            _id = self.ui.addEntry(e.getBibTeX())
            self.assertIsNone(_id, '%s wrongly added.' % e)
            self.assertEqual(self.ui.getEntryCount(), 0,
                             '%s wrongly added.' % e)

    def testAddInvalidBibTeX(self):
        for e in oracle.all_invalid_entries:
            _id = self.ui.addEntry(e.getBibTeX())
            self.assertIsNone(_id, '%s was wrongly added.' % e)
            self.assertEqual(self.ui.getEntryCount(), 0,
                             '%s wrongly added.' % e)

    def testAddErroneousBibTeX(self):
        for e in oracle.all_erroneous_entries:
            self.assertRaises(Exception, self.ui.addEntry, e.getBibTeX())
            self.assertEqual(self.ui.getEntryCount(), 0,
                             '%s wrongly added.' % e)

    def testAddDeleteSanity(self):
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        self.ui.deleteEntry(_id)
        self.assertEqual(
            self.ui.getEntryCount(), 0,
            'adding an entry then deleting it did not undo the addition.')

    def testAddWithQuotes(self):
        settings.Preferences().overrideKeyGeneration = False
        _id = self.ui.addEntry(oracle.valid_entry_bracket.getBibTeX())
        bibtex_bracket = self.ui.getBibTeX(_id)
        _id = self.ui.addEntry(oracle.valid_entry_quote.getBibTeX())
        bibtex_quote = self.ui.getBibTeX(_id)
        self.assertEqual(bibtex_bracket, bibtex_quote,
                         'adding an entry in quotes does not parse correctly')
示例#7
0
class TestUpdate(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()

    def tearDown(self):
        pass
    
    def testUpdateAllFields(self):
        pass
    
    def testUpdateAuthorYear(self):
        suffix = ''
        for ix in range(len(self._ids)):
            i = self._ids[ix]
            expected_entry = self.ui.getEntry(i)
            if oracle.all_entries_all_fields[ix] == oracle.valid_book_all_fields_editor:
                expected_entry['editor'] = 'Xyz'
            else:
                expected_entry[EntryListColumn.Author] = 'Xyz'
            expected_entry[EntryListColumn.Year] = '0000'
            bib = expected_entry.toBibTeX()
            result = self.ui.updateEntry(i, bib)
            self.assertTrue(result, 'entry not updated to %s.' % expected_entry)
            observed_entry = self.ui.getEntry(i)
            self.assertEqual(observed_entry[EntryListColumn.Entrykey], 'Xyz0000' + suffix, 'key not correctly updated.')
            self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
            if suffix == '':
                suffix = 'a'
            elif suffix == 'z':
                break
            else:
                suffix = chr(ord(suffix) + 1)
    
    def testUpdateType(self):
        for i in self._ids:
            expected_entry = oracle.valid_article_all_fields
            if self.ui.getEntry(i)[EntryListColumn.Entrytype].lower() == 'article':
                expected_entry = oracle.valid_inproceedings_all_fields
            result = self.ui.updateEntry(i, expected_entry.getBibTeX())
            self.assertTrue(result, 'entry not updated to %s.' % expected_entry)
            self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
 
    def testUpdateNonExistingEntry(self):
        _id = self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        result = self.ui.updateEntry(_id + 10, oracle.valid_entry_full.getBibTeX())
        self.assertFalse(result, 'non-existing entry wrongly updated.')
 
    def testUpdateMissingRequiredFields(self):
        for i in self._ids:
            for e in oracle.all_invalid_entry_types_no_req:
                result = self.ui.updateEntry(i, e.getBibTeX())
                self.assertFalse(result, 'entry updated to %s.' % e)
                self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
     
    def testUpdateUpdateSanity(self):
        for i in self._ids:
            old_entry = self.ui.getEntry(i)
            new_entry = oracle.valid_entry_full
            result1 = self.ui.updateEntry(i, new_entry.getBibTeX())
            result2 = self.ui.updateEntry(i, old_entry.toBibTeX())
            self.assertTrue(result1 and result2, 'modifying %s back to itself did not retain changes.' % old_entry)
            self.assertEqual(self.ui.getEntryCount(), self.total, 'number of entries wrongly changed.')
示例#8
0
class TestSearch(unittest.TestCase):
    def setUp(self):
        self.ui = BiBlerApp()

    def tearDown(self):
        pass

    def testSearchRegexInEmptyDB(self):
        Preferences().searchRegex = True
        total = self.ui.search('syriani')
        self.assertTrue(total >= 0, 'search failed.')
        self.assertEqual(len(self.ui.getSearchResult()), 0, 'entries wrongly found.')

    def testSearchRegexInSingletonDB(self):
        Preferences().searchRegex = True
        query = 'landin'
        self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        total = self.ui.search(query)
        self.assertTrue(total >= 0, 'search failed.')
        self.assertEqual(len(self.ui.getSearchResult()), 1, 'entry not found.')

    def testSearchRegexMatchingQuery(self):
        Preferences().searchRegex = True
        for e in oracle.all_entries_all_fields:
            self.ui.addEntry(e.getBibTeX())
        searchResults = oracle.search_all_entries_all_fields
        for query in oracle.search_all_entries_all_fields:
            total = self.ui.search(query)
            self.assertTrue(total >= 0, 'search failed.')
            self.assertEqual(len(self.ui.getSearchResult()), searchResults[query], 'incorrect number of entries found.')

    def testSearchRegexAll(self):
        Preferences().searchRegex = True
        for e in oracle.all_entries_all_fields:
            self.ui.addEntry(e.getBibTeX())
        total = self.ui.search('')
        self.assertTrue(total >= 0, 'search failed.')
        self.assertEqual(len(self.ui.getSearchResult()), self.ui.getEntryCount(), 'incorrect number of entries found.')

    def testSearchExactInEmptyDB(self):
        Preferences().searchRegex = False
        total = self.ui.search('syriani')
        self.assertTrue(total >= 0, 'search failed.')
        self.assertEqual(len(self.ui.getSearchResult()), 0, 'entries wrongly found.')

    def testSearchExactInSingletonDB(self):
        Preferences().searchRegex = False
        query = 'landin'
        self.ui.addEntry(oracle.valid_entry_full.getBibTeX())
        total = self.ui.search(query)
        self.assertTrue(total >= 0, 'search failed.')
        self.assertEqual(len(self.ui.getSearchResult()), 1, 'entry not found.')

    def testSearchExactMatchingQuery(self):
        Preferences().searchRegex = False
        for e in oracle.all_entries_all_fields:
            self.ui.addEntry(e.getBibTeX())
        searchResults = oracle.search_all_entries_all_fields
        for query in oracle.search_all_entries_all_fields:
            total = self.ui.search(query)
            self.assertTrue(total >= 0, 'search failed.')
            self.assertEqual(len(self.ui.getSearchResult()), searchResults[query], 'incorrect number of entries found.')

    def testSearchExactAll(self):
        Preferences().searchRegex = False
        for e in oracle.all_entries_all_fields:
            self.ui.addEntry(e.getBibTeX())
        total = self.ui.search('')
        self.assertTrue(total >= 0, 'search failed.')
        self.assertEqual(len(self.ui.getSearchResult()), self.ui.getEntryCount(), 'incorrect number of entries found.')