# Path: multiseek/logic.py
# DATE = "date"
# 
# AUTOCOMPLETE = "autocomplete"
# 
# RANGE = "range"
# 
# STRING = "string"
# 
# VALUE_LIST = "value-list"
# 
# def get_registry(registry):
#     """
#     :rtype: MultiseekRegistry
#     """
# 
#     if isinstance(registry, str):
#         if registry not in _cached_registry:
#             m = importlib.import_module(registry).registry
#             _cached_registry[registry] = m
#         return _cached_registry[registry]
# 
#     return registry
# 
# Path: test_project/test_app/models.py
# class Language(models.Model):
#     name = models.TextField()
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
# class Author(models.Model):
#     last_name = models.TextField()
#     first_name = models.TextField()
# 
#     def __str__(self):
#         return u"%s %s" % (self.first_name, self.last_name)
# 
# class Book(models.Model):
#     title = models.TextField()
#     year = models.IntegerField()
#     language = models.ForeignKey(Language, on_delete=models.CASCADE)
#     authors = models.ManyToManyField(Author)
#     no_editors = models.IntegerField()
#     last_updated = models.DateField(auto_now=True)
#     available = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return u"%s by %s" % (self.title, u", ".join(
#             [str(author) for author in self.authors.all()]))
# 
# Path: test_project/test_app/testutil.py
# class wait_for_page_load(object):
#     def __init__(self, browser):
#         self.browser = browser
# 
#     def __enter__(self):
#         self.old_page = self.browser.find_by_tag("html")[0]._element
# 
#     def __exit__(self, *_):
#         WebDriverWait(self.browser, 10).until(
#             lambda driver: staleness_of(self.old_page)
#         )


import json
import pytest
import datetime
from django.conf import settings
from django.urls import reverse
from model_bakery import baker
from selenium.webdriver.support.expected_conditions import staleness_of, \
    alert_is_present
from selenium.webdriver.support.ui import WebDriverWait
from splinter.exceptions import ElementDoesNotExist
from multiseek.logic import DATE, AUTOCOMPLETE, RANGE, STRING, VALUE_LIST, \
    get_registry
from .models import Language, Author, Book
from builtins import str as text
from django.utils.translation import gettext_lazy as _
from .testutil import wait_for_page_load

@pytest.fixture(scope='session')
def splinter_firefox_profile_preferences():
    return {
        "browser.startup.homepage": "about:blank",
        "startup.homepage_welcome_url": "about:blank",
        "startup.homepage_welcome_url.additional": "about:blank",
        "intl.accept_languages": "en-us"
    }


@pytest.fixture
def initial_data():
    eng = baker.make(Language, name=_("english"), description="English language")
    baker.make(Language, name=_("polish"), description="Polish language")
    a1 = baker.make(Author, last_name="Smith", first_name="John")
    a2 = baker.make(Author, last_name="Kovalsky", first_name="Ian")
    b1 = baker.make(Book, title="A book with a title", year=2013, language=eng,
                    no_editors=5, last_updated=datetime.date(2013, 10, 22),
                    available=True)
    b2 = baker.make(Book, title="Second book", year=2000, language=eng,
                    no_editors=5, last_updated=datetime.date(2013, 9, 22),
                    available=False)

    b1.authors.add(a1)
    b2.authors.add(a2)

    # Some more books by author 3 so we can test pagination...

    a3 = baker.make(Author, last_name="Novak", first_name="Stephan")

# Path: multiseek/logic.py
# DATE = "date"
# 
# AUTOCOMPLETE = "autocomplete"
# 
# RANGE = "range"
# 
# STRING = "string"
# 
# VALUE_LIST = "value-list"
# 
# def get_registry(registry):
#     """
#     :rtype: MultiseekRegistry
#     """
# 
#     if isinstance(registry, str):
#         if registry not in _cached_registry:
#             m = importlib.import_module(registry).registry
#             _cached_registry[registry] = m
#         return _cached_registry[registry]
# 
#     return registry
# 
# Path: test_project/test_app/models.py
# class Language(models.Model):
#     name = models.TextField()
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
# class Author(models.Model):
#     last_name = models.TextField()
#     first_name = models.TextField()
# 
#     def __str__(self):
#         return u"%s %s" % (self.first_name, self.last_name)
# 
# class Book(models.Model):
#     title = models.TextField()
#     year = models.IntegerField()
#     language = models.ForeignKey(Language, on_delete=models.CASCADE)
#     authors = models.ManyToManyField(Author)
#     no_editors = models.IntegerField()
#     last_updated = models.DateField(auto_now=True)
#     available = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return u"%s by %s" % (self.title, u", ".join(
#             [str(author) for author in self.authors.all()]))
# 
# Path: test_project/test_app/testutil.py
# class wait_for_page_load(object):
#     def __init__(self, browser):
#         self.browser = browser
# 
#     def __enter__(self):
#         self.old_page = self.browser.find_by_tag("html")[0]._element
# 
#     def __exit__(self, *_):
#         WebDriverWait(self.browser, 10).until(
#             lambda driver: staleness_of(self.old_page)
#         )


# Path: test_project/test_app/conftest.py
import json
import pytest
import datetime
from django.conf import settings
from django.urls import reverse
from model_bakery import baker
from selenium.webdriver.support.expected_conditions import staleness_of, \
    alert_is_present
from selenium.webdriver.support.ui import WebDriverWait
from splinter.exceptions import ElementDoesNotExist
from multiseek.logic import DATE, AUTOCOMPLETE, RANGE, STRING, VALUE_LIST, \
    get_registry
from .models import Language, Author, Book
from builtins import str as text
from django.utils.translation import gettext_lazy as _
from .testutil import wait_for_page_load


@pytest.fixture(scope='session')
def splinter_firefox_profile_preferences():
    return {
        "browser.startup.homepage": "about:blank",
        "startup.homepage_welcome_url": "about:blank",
        "startup.homepage_welcome_url.additional": "about:blank",
        "intl.accept_languages": "en-us"
    }


@pytest.fixture
def initial_data():
    eng = baker.make(Language, name=_("english"), description="English language")
    baker.make(Language, name=_("polish"), description="Polish language")
    a1 = baker.make(Author, last_name="Smith", first_name="John")
    a2 = baker.make(Author, last_name="Kovalsky", first_name="Ian")
    b1 = baker.make(Book, title="A book with a title", year=2013, language=eng,
                    no_editors=5, last_updated=datetime.date(2013, 10, 22),
                    available=True)
    b2 = baker.make(Book, title="Second book", year=2000, language=eng,
                    no_editors=5, last_updated=datetime.date(2013, 9, 22),
                    available=False)

    b1.authors.add(a1)
    b2.authors.add(a2)

    # Some more books by author 3 so we can test pagination...

    a3 = baker.make(Author, last_name="Novak", first_name="Stephan")

    fr = baker.make(Language, name="french", description="French language")