# 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
# -*- encoding: utf-8 -*-





class SplinterLoginMixin:
    def login(self, username="admin", password="password"):
        url = self.browser.url
        with wait_for_page_load(self.browser):
            self.browser.visit(self.live_server_url + reverse("admin:login"))

        self.browser.fill('username', username)
        self.browser.fill('password', password)
        with wait_for_page_load(self.browser):
            self.browser.find_by_css("input[type=submit]").click()

        with wait_for_page_load(self.browser):
            self.browser.visit(url)



# 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

# -*- encoding: utf-8 -*-





class SplinterLoginMixin:
    def login(self, username="admin", password="password"):
        url = self.browser.url
        with wait_for_page_load(self.browser):
            self.browser.visit(self.live_server_url + reverse("admin:login"))

        self.browser.fill('username', username)
        self.browser.fill('password', password)
        with wait_for_page_load(self.browser):
            self.browser.find_by_css("input[type=submit]").click()

        with wait_for_page_load(self.browser):
            self.browser.visit(url)



class MultiseekWebPage(SplinterLoginMixin):