Python3 requires to open explicitly on binary mode to write bytes

This commit is contained in:
Santiago L 2021-03-30 17:46:42 +02:00
parent fa8a895299
commit e7aabf4799
1 changed files with 13 additions and 13 deletions

View File

@ -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):
session = SessionStore() session = SessionStore()
session[SESSION_KEY] = self.account.id session[SESSION_KEY] = self.account.id
@ -105,16 +105,16 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
value=session.session_key, # value=session.session_key, #
path='/', path='/',
)) ))
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 = '/home/orchestra/snapshots'
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
@ -124,7 +124,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
@ -136,20 +136,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):
@ -174,7 +174,7 @@ def save_response_on_error(test):
timestamp = datetime.datetime.now().isoformat().replace(':', '') timestamp = datetime.datetime.now().isoformat().replace(':', '')
filename = '%s_%s.html' % (self.id(), timestamp) filename = '%s_%s.html' % (self.id(), timestamp)
path = '/home/orchestra/snapshots' path = '/home/orchestra/snapshots'
with open(os.path.join(path, filename), 'w') as dumpfile: with open(os.path.join(path, filename), 'wb') as dumpfile:
dumpfile.write(self.rest.last_response.content) dumpfile.write(self.rest.last_response.content)
raise raise
return inner return inner