# -*- coding: utf-8 -*-

import json
import os

from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase, Client, mock
from django.shortcuts import reverse

from ...models import Category, Language, Author, TheUser, Book, AddedBook
from ...views.add_book_views import add_book, generate_authors, generate_books, add_book_successful

TEST_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DATA_DIR = os.path.join(TEST_DIR, '../fixtures')


# ----------------------------------------------------------------------------------------------------------------------
class AddBookViewsTest(TestCase):

    # ------------------------------------------------------------------------------------------------------------------
    @classmethod
    def setUpTestData(cls):
        cls.xhr = 'XMLHttpRequest'
        cls.user = User.objects.create(username='test_user1')
        cls.the_user = TheUser.objects.get(id_user=cls.user)
        cls.user.set_password('Dummy#password')
        cls.user.save()

        cls.category1 = Category.objects.create(category_name='last category')
        cls.category2 = Category.objects.create(category_name='a first category')
        cls.language_en = Language.objects.create(language='English')
        cls.language_ru = Language.objects.create(language='Russian')

        cls.author1 = Author.objects.create(author_name='New Author Name')
        cls.author2 = Author.objects.create(author_name='A best one')
        cls.author3 = Author.objects.create(author_name='The new author')
        cls.author4 = Author.objects.create(author_name='<AuthorSpecialSymbols>&"')

        cls.anonymous_client = Client()
        cls.logged_client = Client()
        cls.logged_client.login(username='test_user1', password='Dummy#password')

        cls.generate_books()