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

View file

@ -17,7 +17,7 @@ from .python import random_ascii
class AppDependencyMixin(object):
DEPENDENCIES = ()
@classmethod
def setUpClass(cls):
current_app = cls.__module__.split('.tests.')[0]
@ -70,13 +70,13 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
cls.vdisplay.start()
cls.selenium = WebDriver()
super(BaseLiveServerTestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
cls.vdisplay.stop()
super(BaseLiveServerTestCase, cls).tearDownClass()
def create_account(self, username='', superuser=False):
if not username:
username = '%s_superaccount' % random_ascii(5)
@ -85,14 +85,14 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
if superuser:
return Account.objects.create_superuser(username, password=password, email='orchestra@orchestra.org')
return Account.objects.create_user(username, password=password, email='orchestra@orchestra.org')
def setUp(self):
from orm.api import Api
super(BaseLiveServerTestCase, self).setUp()
self.rest = Api(self.live_server_url + '/api/')
self.rest.enable_logging()
self.account = self.create_account(superuser=True)
def admin_login(self):
session = SessionStore()
session[SESSION_KEY] = self.account.id
@ -105,16 +105,16 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase):
value=session.session_key, #
path='/',
))
def rest_login(self):
self.rest.login(username=self.account.username, password=self.account_password)
def take_screenshot(self):
timestamp = datetime.datetime.now().isoformat().replace(':', '')
filename = 'screenshot_%s_%s.png' % (self.id(), timestamp)
path = '/home/orchestra/snapshots'
self.selenium.save_screenshot(os.path.join(path, filename))
def admin_delete(self, obj):
opts = obj._meta
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.submit()
self.assertNotEqual(url, self.selenium.current_url)
def admin_disable(self, obj):
opts = obj._meta
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.submit()
self.assertNotEqual(url, self.selenium.current_url)
def admin_change_password(self, obj, password):
opts = obj._meta
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,))
url = self.live_server_url + change_password
self.selenium.get(url)
password_field = self.selenium.find_element_by_id('id_password1')
password_field.send_keys(password)
password_field = self.selenium.find_element_by_id('id_password2')
password_field.send_keys(password)
password_field.submit()
self.assertNotEqual(url, self.selenium.current_url)
def snapshot_on_error(test):
@ -174,7 +174,7 @@ def save_response_on_error(test):
timestamp = datetime.datetime.now().isoformat().replace(':', '')
filename = '%s_%s.html' % (self.id(), timestamp)
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)
raise
return inner