Fixes on tests0

This commit is contained in:
Marc 2014-10-28 09:51:27 +00:00
parent 277f3cf760
commit d0c7c760af
8 changed files with 31 additions and 17 deletions

View File

@ -51,6 +51,7 @@ class PasswdVirtualUserBackend(ServiceController):
filtering = mailbox.get_filtering() filtering = mailbox.get_filtering()
if filtering: if filtering:
context['filtering'] = '# %(banner)s\n' + filtering context['filtering'] = '# %(banner)s\n' + filtering
self.append("mkdir -p $(dirname '%(filtering_path)s')" % context)
self.append("echo '%(filtering)s' > %(filtering_path)s" % context) self.append("echo '%(filtering)s' > %(filtering_path)s" % context)
else: else:
self.append("rm -f %(filtering_path)s" % context) self.append("rm -f %(filtering_path)s" % context)
@ -159,10 +160,10 @@ class PostfixAddressBackend(ServiceController):
def exclude_virtual_alias_maps(self, context): def exclude_virtual_alias_maps(self, context):
self.append(textwrap.dedent(""" self.append(textwrap.dedent("""
if [[ $(grep "^%(email)s\s") ]]; then if [[ $(grep "^%(email)s\s" %(virtual_alias_maps)s) ]]; then
sed -i "/^%(email)s\s.*$/d" %(virtual_alias_maps)s sed -i "/^%(email)s\s.*$/d" %(virtual_alias_maps)s
UPDATED_VIRTUAL_ALIAS_MAPS=1 UPDATED_VIRTUAL_ALIAS_MAPS=1
fi""" fi""" % context
)) ))
def save(self, address): def save(self, address):

View File

@ -33,6 +33,7 @@ def close_connection(execute):
try: try:
log = execute(*args, **kwargs) log = execute(*args, **kwargs)
except: except:
logger.error('EXCEPTION executing backend %s %s' % (str(args), str(kwargs)))
raise raise
else: else:
# Using the wrapper function as threader messenger for the execute output # Using the wrapper function as threader messenger for the execute output

View File

@ -1,3 +1,5 @@
from django.core.exceptions import ObjectDoesNotExist
from orchestra.apps.accounts.models import Account from orchestra.apps.accounts.models import Account
from orchestra.core import services from orchestra.core import services
@ -16,7 +18,10 @@ def get_related_objects(origin, max_depth=2):
yield getattr(node, field.name) yield getattr(node, field.name)
for field in node._meta.fields: for field in node._meta.fields:
if field.rel: if field.rel:
try:
yield getattr(node, field.name) yield getattr(node, field.name)
except ObjectDoesNotExist:
pass
# BFS model relation transversal # BFS model relation transversal
queue = [[origin]] queue = [[origin]]

View File

@ -61,10 +61,10 @@ class ServiceHandler(plugins.Plugin):
return None return None
value, unit = self.ignore_period.split('_') value, unit = self.ignore_period.split('_')
value = text2int(value) value = text2int(value)
if unit.lowe().startswith('day'): if unit.lower().startswith('day'):
return timedelta(days=value) return datetime.timedelta(days=value)
if unit.lowe().startswith('month'): if unit.lower().startswith('month'):
return timedelta(months=value) return datetime.timedelta(months=value)
else: else:
raise ValueError("Unknown unit %s" % unit) raise ValueError("Unknown unit %s" % unit)

View File

@ -22,11 +22,15 @@ class SystemUserBackend(ServiceController):
usermod %(username)s --password '%(password)s' --shell %(shell)s %(groups_arg)s usermod %(username)s --password '%(password)s' --shell %(shell)s %(groups_arg)s
else else
useradd %(username)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s useradd %(username)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s
usermod -a -G %(username)s %(mainusername)s
fi fi
mkdir -p %(home)s mkdir -p %(home)s
chown %(username)s.%(username)s %(home)s""" % context chown %(username)s.%(username)s %(home)s""" % context
)) ))
for member in settings.SYSTEMUSERS_DEFAULT_GROUP_MEMBERS:
context['member'] = member
self.append('usermod -a -G %(username)s %(member)s' % context)
if not user.is_main:
self.append('usermod -a -G %(username)s %(mainusername)s' % context)
def delete(self, user): def delete(self, user):
context = self.get_context(user) context = self.get_context(user)
@ -45,9 +49,7 @@ class SystemUserBackend(ServiceController):
def get_groups(self, user): def get_groups(self, user):
if user.is_main: if user.is_main:
return user.account.systemusers.exclude(username=user.username).values_list('username', flat=True) return user.account.systemusers.exclude(username=user.username).values_list('username', flat=True)
groups = list(user.groups.values_list('username', flat=True)) return list(user.groups.values_list('username', flat=True))
groups += list(settings.SYSTEMUSERS_DEFAULT_GROUP_MEMBERS)
return groups
def get_context(self, user): def get_context(self, user):
context = { context = {

View File

@ -263,7 +263,8 @@ class AdminSystemUserMixin(SystemUserMixin):
@snapshot_on_error @snapshot_on_error
def delete_account(self, username): def delete_account(self, username):
self.admin_delete(self.account) account = Account.objects.get(username=username)
self.admin_delete(account)
@snapshot_on_error @snapshot_on_error
def disable(self, username): def disable(self, username):
@ -317,6 +318,10 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase):
password = self.selenium.find_element_by_id('id_password2') password = self.selenium.find_element_by_id('id_password2')
password.send_keys(account_password) password.send_keys(account_password)
full_name = random_ascii(10)
full_name_field = self.selenium.find_element_by_id('id_full_name')
full_name_field.send_keys(full_name)
account_email = 'orchestra@orchestra.lan' account_email = 'orchestra@orchestra.lan'
email = self.selenium.find_element_by_id('id_email') email = self.selenium.find_element_by_id('id_email')
email.send_keys(account_email) email.send_keys(account_email)
@ -330,9 +335,8 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase):
email.submit() email.submit()
self.assertNotEqual(url, self.selenium.current_url) self.assertNotEqual(url, self.selenium.current_url)
account = Account.objects.get(username=account_username)
self.addCleanup(self.delete_account, account_username) self.addCleanup(self.delete_account, account_username)
self.assertEqual(0, sshr(self.MASTER_SERVER, "id %s" % account.username).return_code) self.assertEqual(0, sshr(self.MASTER_SERVER, "id %s" % account_username).return_code)
@snapshot_on_error @snapshot_on_error
def test_delete_account(self): def test_delete_account(self):
@ -368,4 +372,4 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase):
# Reenable for test cleanup # Reenable for test cleanup
self.account.is_active = True self.account.is_active = True
self.account.save() self.account.save()
# self.admin_login() self.admin_login()

View File

@ -30,7 +30,7 @@ class PHPFPMBackend(WebAppServiceMixin, ServiceController):
def delete(self, webapp): def delete(self, webapp):
context = self.get_context(webapp) context = self.get_context(webapp)
self.append("rm '%(fpm_config)s'" % context) self.append("rm '%(fpm_path)s'" % context)
self.delete_webapp_dir(context) self.delete_webapp_dir(context)
def commit(self): def commit(self):

View File

@ -99,7 +99,8 @@ class RESTWebAppMixin(object):
@save_response_on_error @save_response_on_error
def save_systemuser(self): def save_systemuser(self):
self.rest.systemusers.retrieve().get().save() systemuser = self.rest.systemusers.retrieve().get()
systemuser.update(is_active=True)
@save_response_on_error @save_response_on_error
def add_webapp(self, name, options=[]): def add_webapp(self, name, options=[]):