Store screenshots on project path.
This commit is contained in:
parent
a6f829e66c
commit
4536d651ec
|
@ -17,7 +17,7 @@ from .python import random_ascii
|
||||||
|
|
||||||
class AppDependencyMixin(object):
|
class AppDependencyMixin(object):
|
||||||
DEPENDENCIES = ()
|
DEPENDENCIES = ()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
current_app = cls.__module__.split('.tests.')[0]
|
current_app = cls.__module__.split('.tests.')[0]
|
||||||
|
@ -70,13 +70,13 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
|
||||||
cls.vdisplay.start()
|
cls.vdisplay.start()
|
||||||
cls.selenium = WebDriver()
|
cls.selenium = WebDriver()
|
||||||
super(BaseLiveServerTestCase, cls).setUpClass()
|
super(BaseLiveServerTestCase, cls).setUpClass()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
cls.selenium.quit()
|
cls.selenium.quit()
|
||||||
cls.vdisplay.stop()
|
cls.vdisplay.stop()
|
||||||
super(BaseLiveServerTestCase, cls).tearDownClass()
|
super(BaseLiveServerTestCase, cls).tearDownClass()
|
||||||
|
|
||||||
def create_account(self, username='', superuser=False):
|
def create_account(self, username='', superuser=False):
|
||||||
if not username:
|
if not username:
|
||||||
username = '%s_superaccount' % random_ascii(5)
|
username = '%s_superaccount' % random_ascii(5)
|
||||||
|
@ -85,14 +85,14 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
|
||||||
if superuser:
|
if superuser:
|
||||||
return Account.objects.create_superuser(username, password=password, email='orchestra@orchestra.org')
|
return Account.objects.create_superuser(username, password=password, email='orchestra@orchestra.org')
|
||||||
return Account.objects.create_user(username, password=password, email='orchestra@orchestra.org')
|
return Account.objects.create_user(username, password=password, email='orchestra@orchestra.org')
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
from orm.api import Api
|
from orm.api import Api
|
||||||
super(BaseLiveServerTestCase, self).setUp()
|
super(BaseLiveServerTestCase, self).setUp()
|
||||||
self.rest = Api(self.live_server_url + '/api/')
|
self.rest = Api(self.live_server_url + '/api/')
|
||||||
self.rest.enable_logging()
|
self.rest.enable_logging()
|
||||||
self.account = self.create_account(superuser=True)
|
self.account = self.create_account(superuser=True)
|
||||||
|
|
||||||
def admin_login(self):
|
def admin_login(self):
|
||||||
# Original option
|
# Original option
|
||||||
session = SessionStore()
|
session = SessionStore()
|
||||||
|
@ -112,16 +112,16 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
|
||||||
# self.selenium.find_element_by_id("id_username").send_keys(self.account.username)
|
# self.selenium.find_element_by_id("id_username").send_keys(self.account.username)
|
||||||
# self.selenium.find_element_by_id("id_password").send_keys(self.account_password)
|
# self.selenium.find_element_by_id("id_password").send_keys(self.account_password)
|
||||||
# self.selenium.find_element_by_css_selector("input[type='submit']").click()
|
# self.selenium.find_element_by_css_selector("input[type='submit']").click()
|
||||||
|
|
||||||
def rest_login(self):
|
def rest_login(self):
|
||||||
self.rest.login(username=self.account.username, password=self.account_password)
|
self.rest.login(username=self.account.username, password=self.account_password)
|
||||||
|
|
||||||
def take_screenshot(self):
|
def take_screenshot(self):
|
||||||
timestamp = datetime.datetime.now().isoformat().replace(':', '')
|
timestamp = datetime.datetime.now().isoformat().replace(':', '')
|
||||||
filename = 'screenshot_%s_%s.png' % (self.id(), timestamp)
|
filename = 'screenshot_%s_%s.png' % (self.id(), timestamp)
|
||||||
path = '/home/orchestra/snapshots'
|
path = settings.BASE_DIR
|
||||||
self.selenium.save_screenshot(os.path.join(path, filename))
|
self.selenium.save_screenshot(os.path.join(path, filename))
|
||||||
|
|
||||||
def admin_delete(self, obj):
|
def admin_delete(self, obj):
|
||||||
opts = obj._meta
|
opts = obj._meta
|
||||||
app_label, model_name = opts.app_label, opts.model_name
|
app_label, model_name = opts.app_label, opts.model_name
|
||||||
|
@ -131,7 +131,7 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
|
||||||
confirmation = self.selenium.find_element_by_name('post')
|
confirmation = self.selenium.find_element_by_name('post')
|
||||||
confirmation.submit()
|
confirmation.submit()
|
||||||
self.assertNotEqual(url, self.selenium.current_url)
|
self.assertNotEqual(url, self.selenium.current_url)
|
||||||
|
|
||||||
def admin_disable(self, obj):
|
def admin_disable(self, obj):
|
||||||
opts = obj._meta
|
opts = obj._meta
|
||||||
app_label, model_name = opts.app_label, opts.model_name
|
app_label, model_name = opts.app_label, opts.model_name
|
||||||
|
@ -143,20 +143,20 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
|
||||||
save = self.selenium.find_element_by_name('_save')
|
save = self.selenium.find_element_by_name('_save')
|
||||||
save.submit()
|
save.submit()
|
||||||
self.assertNotEqual(url, self.selenium.current_url)
|
self.assertNotEqual(url, self.selenium.current_url)
|
||||||
|
|
||||||
def admin_change_password(self, obj, password):
|
def admin_change_password(self, obj, password):
|
||||||
opts = obj._meta
|
opts = obj._meta
|
||||||
app_label, model_name = opts.app_label, opts.model_name
|
app_label, model_name = opts.app_label, opts.model_name
|
||||||
change_password = reverse('admin:%s_%s_change_password' % (app_label, model_name), args=(obj.pk,))
|
change_password = reverse('admin:%s_%s_change_password' % (app_label, model_name), args=(obj.pk,))
|
||||||
url = self.live_server_url + change_password
|
url = self.live_server_url + change_password
|
||||||
self.selenium.get(url)
|
self.selenium.get(url)
|
||||||
|
|
||||||
password_field = self.selenium.find_element_by_id('id_password1')
|
password_field = self.selenium.find_element_by_id('id_password1')
|
||||||
password_field.send_keys(password)
|
password_field.send_keys(password)
|
||||||
password_field = self.selenium.find_element_by_id('id_password2')
|
password_field = self.selenium.find_element_by_id('id_password2')
|
||||||
password_field.send_keys(password)
|
password_field.send_keys(password)
|
||||||
password_field.submit()
|
password_field.submit()
|
||||||
|
|
||||||
self.assertNotEqual(url, self.selenium.current_url)
|
self.assertNotEqual(url, self.selenium.current_url)
|
||||||
|
|
||||||
def snapshot_on_error(test):
|
def snapshot_on_error(test):
|
||||||
|
|
Loading…
Reference in New Issue