# Path: quotes/tests/utils.py
# def create_multiple_test_authors(ammount=100):
#     authors = []
#     for i in xrange(ammount):
#         name = "Author %d" % i
#         author = Author.objects.create(name=name)
#         authors.append(author)
#     now = datetime.now()
#     for i in xrange(10):
#         body = 'Test quote %d' % i
#         quote = Quote.objects.create(body=body, publish_date=now)
#         quote.authors.add(authors[0])
#     return authors


from lxml import html
from django.test import TestCase
from django.test.client import Client
from quotes.tests.utils import create_multiple_test_authors




class AuthorsPageTestCase(TestCase):

    def setUp(self):
        self.client = Client()
        self.dom = ''
        self.authors = []

    def tearDown(self):
        self.dom = ''
        self.authors = []

    def __load_dom(self):
        response = self.client.get('/authors/')
        self.dom = html.fromstring(response.content)

    def testAuthorsPageResponse(self):
        response = self.client.get('/authors/')
        self.failUnlessEqual(response.status_code, 200)

    def testAuthorsPageShouldShowAuthors(self):
        self.authors = create_multiple_test_authors()
        self.__load_dom()
        authors_list = self.dom.cssselect('#authors-list li')
        assert len(authors_list), 100

    def testAuthorNameShouldHaveQuotesCount(self):

# Path: quotes/tests/utils.py
# def create_multiple_test_authors(ammount=100):
#     authors = []
#     for i in xrange(ammount):
#         name = "Author %d" % i
#         author = Author.objects.create(name=name)
#         authors.append(author)
#     now = datetime.now()
#     for i in xrange(10):
#         body = 'Test quote %d' % i
#         quote = Quote.objects.create(body=body, publish_date=now)
#         quote.authors.add(authors[0])
#     return authors


# Path: quotes/tests/requests/test_authors_page.py
from lxml import html
from django.test import TestCase
from django.test.client import Client
from quotes.tests.utils import create_multiple_test_authors





class AuthorsPageTestCase(TestCase):

    def setUp(self):
        self.client = Client()
        self.dom = ''
        self.authors = []

    def tearDown(self):
        self.dom = ''
        self.authors = []

    def __load_dom(self):
        response = self.client.get('/authors/')
        self.dom = html.fromstring(response.content)

    def testAuthorsPageResponse(self):
        response = self.client.get('/authors/')
        self.failUnlessEqual(response.status_code, 200)

    def testAuthorsPageShouldShowAuthors(self):
        self.authors = create_multiple_test_authors()
        self.__load_dom()
        authors_list = self.dom.cssselect('#authors-list li')
        assert len(authors_list), 100

    def testAuthorNameShouldHaveQuotesCount(self):

        self.authors = create_multiple_test_authors()