django-select2/tests/conftest.py

65 lines
1.5 KiB
Python
Raw Permalink Normal View History

2015-12-02 18:59:36 +00:00
import random
import string
2015-03-03 09:01:51 +00:00
import pytest
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
2015-12-02 18:59:36 +00:00
def random_string(n):
return ''.join(
random.choice(string.ascii_uppercase + string.digits)
for _ in range(n)
)
2017-04-11 11:28:39 +00:00
def random_name(n):
words = ''.join(random.choice(string.ascii_lowercase + ' ') for _ in range(n)).strip().split(' ')
return '-'.join([x.capitalize() for x in words])
@pytest.yield_fixture(scope='session')
def driver():
chrome_options = webdriver.ChromeOptions()
chrome_options.headless = True
2015-03-03 09:01:51 +00:00
try:
b = webdriver.Chrome(options=chrome_options)
2015-03-03 09:01:51 +00:00
except WebDriverException as e:
pytest.skip(str(e))
2015-03-03 09:01:51 +00:00
else:
yield b
b.quit()
2015-08-06 09:58:27 +00:00
@pytest.fixture
def genres(db):
2015-12-02 18:59:36 +00:00
from .testapp.models import Genre
return Genre.objects.bulk_create(
[Genre(pk=pk, title=random_string(50)) for pk in range(100)]
)
2015-08-06 09:58:27 +00:00
@pytest.fixture
def artists(db):
2015-12-02 18:59:36 +00:00
from .testapp.models import Artist
return Artist.objects.bulk_create(
[Artist(pk=pk, title=random_string(50)) for pk in range(100)]
)
2017-04-11 11:28:39 +00:00
@pytest.fixture
def countries(db):
from .testapp.models import Country
return Country.objects.bulk_create(
[Country(pk=pk, name=random_name(random.randint(10, 20))) for pk in range(10)]
)
@pytest.fixture
def cities(db, countries):
from .testapp.models import City
return City.objects.bulk_create(
[City(pk=pk, name=random_name(random.randint(5, 15)), country=random.choice(countries)) for pk in range(100)]
)