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])
|
|
|
|
|
|
|
|
|
|
|
2017-07-16 08:03:49 +00:00
|
|
|
@pytest.yield_fixture(scope='session')
|
|
|
|
|
def driver():
|
|
|
|
|
chrome_options = webdriver.ChromeOptions()
|
2019-08-26 15:02:43 +00:00
|
|
|
chrome_options.headless = True
|
2015-03-03 09:01:51 +00:00
|
|
|
try:
|
2019-03-10 11:13:43 +00:00
|
|
|
b = webdriver.Chrome(options=chrome_options)
|
2015-03-03 09:01:51 +00:00
|
|
|
except WebDriverException as e:
|
2019-06-10 15:09:04 +00:00
|
|
|
pytest.skip(str(e))
|
2015-03-03 09:01:51 +00:00
|
|
|
else:
|
2016-12-28 18:43:59 +00:00
|
|
|
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)]
|
|
|
|
|
)
|