示例#1
0
    def test_bulk_create_invalid_authors(self):
        invalid_authors_names = [
            self.existing_author.name, '', ' ', '\t', None
        ]

        for author_name in invalid_authors_names:
            with self.subTest(author_name=author_name):
                with self.assertRaises(ValidationError):
                    Author.bulk_create([author_name])

        self.assertEqual(self.authors.count(), self.authors_count_before)
示例#2
0
    def import_authors_from_file_and_save_to_database(
            self, filepath: str) -> List[Author]:
        names = self.get_authors_names_from_file(filepath)

        try:
            return Author.bulk_create(names)
        except ValidationError as e:
            raise CommandError(e.messages)
示例#3
0
    def test_bulk_create_valid_authors(self):
        new_authors_names = [
            'William Shakespeare', 'William Faulkner', 'Henry James',
            'Jane Austen'
        ]
        new_authors = Author.bulk_create(new_authors_names)

        self.assertEqual(self.authors.count(),
                         self.authors_count_before + len(new_authors))