def test_parse_author(self): author_name = 'David Beath' authorparser.parse_author(author_name) author = Author.query.filter_by(name=author_name).first() self.assertIsNotNone(author) self.assertEqual(author.name, author_name)
def add_authors(self, entry, author_name): """Adds authors to the entry""" if author_name is not None: authors = authorparser.parse_author(author_name) entry.authors.extend(authors) for author in authors: if author not in self.authors: self.authors.append(author) entry.create_author_string()
def test_individual_author(self): test = AuthorTest('<*****@*****.**> {[ David Brin )', [Author('David', 'Brin', email='*****@*****.**')]) result = authorparser.parse_author(test.namestring) self.assertEqual(len(test.expected), len(result)) for i, item in enumerate(result): self.assertEqual(test.expected[i].givenname, result[i].givenname) self.assertEqual(test.expected[i].familyname, result[i].familyname) self.assertEqual(test.expected[i].email, result[i].email) self.assertEqual(test.expected[i].name, result[i].name) db.session.rollback()
def test_parse_author_multiple_names(self): names = "Joe Blogs, Jane Smith" out = authorparser.parse_author(names) self.assertEqual(len(out), 2) self.assertIsInstance(out[0], Author) self.assertEqual(out[0].name, 'Joe Blogs') self.assertEqual(out[1].name, 'Jane Smith') a1 = Author.query.filter_by(name='Joe Blogs').first() self.assertIsNotNone(a1) self.assertEqual(a1.givenname, 'Joe') self.assertEqual(a1.familyname, 'Blogs') a2 = Author.query.filter_by(name='Jane Smith').first() self.assertIsNotNone(a2) self.assertEqual(a2.givenname, 'Jane') self.assertEqual(a2.familyname, 'Smith')
def test_individual_author2(self): test = AuthorTest('Neelima Choahan, with Adam Cooper and Nick Miller', [Author('Neelima', 'Choahan'), Author('Adam', 'Cooper'), Author('Nick', 'Miller')]) print(test.namestring) result = authorparser.parse_author(test.namestring) print(result) self.assertEqual(len(test.expected), len(result)) for i, item in enumerate(result): self.assertEqual(test.expected[i].givenname, result[i].givenname) self.assertEqual(test.expected[i].familyname, result[i].familyname) self.assertEqual(test.expected[i].email, result[i].email) self.assertEqual(test.expected[i].name, result[i].name) db.session.rollback()
def test_authors(self): for test in self.tests: if test.skip: continue print('Testing: ' + test.namestring) result = authorparser.parse_author(test.namestring) print('Result: {0}\n'.format(result)) self.assertEqual(len(test.expected), len(result)) for i, item in enumerate(result): self.assertEqual(test.expected[i].givenname, result[i].givenname) self.assertEqual(test.expected[i].familyname, result[i].familyname) self.assertEqual(test.expected[i].middlename, result[i].middlename) self.assertEqual(test.expected[i].email, result[i].email) self.assertEqual(test.expected[i].name, result[i].name) db.session.rollback()
def add_authors(self, entry, author_name): """ Parses the author name to find Authors for the entry. :param entry: Entry object :type entry: Entry :param author_name: Raw author name string :type author_name: str :return: None """ if author_name is not None: authors = authorparser.parse_author(author_name) entry.add_authors(authors) for author in authors: if author not in self.authors: self.authors.append(author) entry.create_author_string()