Fixes on tests0
This commit is contained in:
parent
9534e6e571
commit
d5cc1b7d7c
|
@ -26,7 +26,7 @@ class AccountViewSet(SetPasswordApiMixin, viewsets.ModelViewSet):
|
||||||
# TODO reimplement in permissions
|
# TODO reimplement in permissions
|
||||||
if not request.user.is_superuser:
|
if not request.user.is_superuser:
|
||||||
raise exceptions.PermissionDenied(_("Accounts can not be deleted."))
|
raise exceptions.PermissionDenied(_("Accounts can not be deleted."))
|
||||||
super(AccountViewSet, self).destroy(request, pk=pk)
|
return super(AccountViewSet, self).destroy(request, pk=pk)
|
||||||
|
|
||||||
|
|
||||||
router.register(r'accounts', AccountViewSet)
|
router.register(r'accounts', AccountViewSet)
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Bind9MasterDomainBackend(ServiceController):
|
||||||
'zone_path': settings.DOMAINS_ZONE_PATH % {'name': domain.name},
|
'zone_path': settings.DOMAINS_ZONE_PATH % {'name': domain.name},
|
||||||
'subdomains': domain.subdomains.all(),
|
'subdomains': domain.subdomains.all(),
|
||||||
'banner': self.get_banner(),
|
'banner': self.get_banner(),
|
||||||
'slaves': '; '.join(self.get_slaves(domain)) or '',
|
'slaves': '; '.join(self.get_slaves(domain)) or 'none',
|
||||||
}
|
}
|
||||||
context.update({
|
context.update({
|
||||||
'conf_path': settings.DOMAINS_MASTERS_PATH,
|
'conf_path': settings.DOMAINS_MASTERS_PATH,
|
||||||
|
@ -101,7 +101,7 @@ class Bind9MasterDomainBackend(ServiceController):
|
||||||
type master;
|
type master;
|
||||||
file "%(zone_path)s";
|
file "%(zone_path)s";
|
||||||
allow-transfer { %(slaves)s; };
|
allow-transfer { %(slaves)s; };
|
||||||
also-notify { %(slaves)s; };
|
notify yes;
|
||||||
};""" % context)
|
};""" % context)
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
@ -133,7 +133,7 @@ class Bind9SlaveDomainBackend(Bind9MasterDomainBackend):
|
||||||
'name': domain.name,
|
'name': domain.name,
|
||||||
'banner': self.get_banner(),
|
'banner': self.get_banner(),
|
||||||
'subdomains': domain.subdomains.all(),
|
'subdomains': domain.subdomains.all(),
|
||||||
'masters': '; '.join(self.get_masters(domain)) or '',
|
'masters': '; '.join(self.get_masters(domain)) or 'none',
|
||||||
}
|
}
|
||||||
context.update({
|
context.update({
|
||||||
'conf_path': settings.DOMAINS_SLAVES_PATH,
|
'conf_path': settings.DOMAINS_SLAVES_PATH,
|
||||||
|
|
|
@ -125,7 +125,7 @@ class MailmanBackend(ServiceController):
|
||||||
'name': mail_list.name,
|
'name': mail_list.name,
|
||||||
'password': mail_list.password,
|
'password': mail_list.password,
|
||||||
'domain': mail_list.address_domain or settings.LISTS_DEFAULT_DOMAIN,
|
'domain': mail_list.address_domain or settings.LISTS_DEFAULT_DOMAIN,
|
||||||
'address_name': mail_list.get_address_name,
|
'address_name': mail_list.get_address_name(),
|
||||||
'address_domain': mail_list.address_domain,
|
'address_domain': mail_list.address_domain,
|
||||||
'admin': mail_list.admin_email,
|
'admin': mail_list.admin_email,
|
||||||
'mailman_root': settings.LISTS_MAILMAN_ROOT_PATH,
|
'mailman_root': settings.LISTS_MAILMAN_ROOT_PATH,
|
||||||
|
|
|
@ -217,9 +217,9 @@ class MaildirDisk(ServiceMonitor):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_context(self, mailbox):
|
def get_context(self, mailbox):
|
||||||
context = MailSystemUserBackend().get_context(mailbox)
|
home = mailbox.get_home()
|
||||||
context.update({
|
context = {
|
||||||
'rr_path': os.path.join(context['home'], 'Maildir/maildirsize'),
|
'maildir_path': os.path.join(home, 'Maildir/maildirsize'),
|
||||||
'object_id': mailbox.pk
|
'object_id': mailbox.pk
|
||||||
})
|
}
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -128,6 +128,10 @@ class BackendOperation(models.Model):
|
||||||
# instance should maintain any dynamic attribute until backend execution
|
# instance should maintain any dynamic attribute until backend execution
|
||||||
# deep copy is prefered over copy otherwise objects will share same atributes (queryset cache)
|
# deep copy is prefered over copy otherwise objects will share same atributes (queryset cache)
|
||||||
op.instance = copy.deepcopy(instance)
|
op.instance = copy.deepcopy(instance)
|
||||||
|
if action == cls.DELETE:
|
||||||
|
# Heuristic, running get_context will prevent most of related objects do not exist errors
|
||||||
|
if hasattr(backend, 'get_context'):
|
||||||
|
backend().get_context(op.instance)
|
||||||
return op
|
return op
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -50,7 +50,7 @@ class MailboxBillingTest(BaseBillingTest):
|
||||||
tax=0,
|
tax=0,
|
||||||
nominal_price=10
|
nominal_price=10
|
||||||
)
|
)
|
||||||
plan = Plan.objects.create(is_default=True, name='Default')
|
plan, __ = Plan.objects.get_or_create(is_default=True, name='Default')
|
||||||
service.rates.create(plan=plan, quantity=1, price=10)
|
service.rates.create(plan=plan, quantity=1, price=10)
|
||||||
return service
|
return service
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class MailboxBillingTest(BaseBillingTest):
|
||||||
return self.resource
|
return self.resource
|
||||||
|
|
||||||
def allocate_disk(self, mailbox, value):
|
def allocate_disk(self, mailbox, value):
|
||||||
|
# TODO get_or_Create return created
|
||||||
data = ResourceData.get_or_create(mailbox, self.resource)
|
data = ResourceData.get_or_create(mailbox, self.resource)
|
||||||
data.allocated = value
|
data.allocated = value
|
||||||
data.save()
|
data.save()
|
||||||
|
|
|
@ -17,7 +17,7 @@ class SystemUserViewSet(AccountApiMixin, SetPasswordApiMixin, viewsets.ModelView
|
||||||
user = self.get_object()
|
user = self.get_object()
|
||||||
if user.is_main:
|
if user.is_main:
|
||||||
raise exceptions.PermissionDenied(_("Main system user can not be deleted."))
|
raise exceptions.PermissionDenied(_("Main system user can not be deleted."))
|
||||||
super(SystemUserViewSet, self).destroy(request, pk=pk)
|
return super(SystemUserViewSet, self).destroy(request, pk=pk)
|
||||||
|
|
||||||
|
|
||||||
router.register(r'systemusers', SystemUserViewSet)
|
router.register(r'systemusers', SystemUserViewSet)
|
||||||
|
|
|
@ -53,8 +53,9 @@ class SystemUser(models.Model):
|
||||||
except type(self).account.field.rel.to.DoesNotExist:
|
except type(self).account.field.rel.to.DoesNotExist:
|
||||||
return self.is_active
|
return self.is_active
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_main(self):
|
def is_main(self):
|
||||||
|
# TODO on account delete
|
||||||
# On account creation main_systemuser_id is still None
|
# On account creation main_systemuser_id is still None
|
||||||
if self.account.main_systemuser_id:
|
if self.account.main_systemuser_id:
|
||||||
return self.account.main_systemuser_id == self.pk
|
return self.account.main_systemuser_id == self.pk
|
||||||
|
|
|
@ -223,6 +223,9 @@ class RESTSystemUserMixin(SystemUserMixin):
|
||||||
def change_password(self, username, password):
|
def change_password(self, username, password):
|
||||||
user = self.rest.systemusers.retrieve(username=username).get()
|
user = self.rest.systemusers.retrieve(username=username).get()
|
||||||
user.set_password(password)
|
user.set_password(password)
|
||||||
|
|
||||||
|
def delete_account(self, username):
|
||||||
|
self.rest.account.delete()
|
||||||
|
|
||||||
|
|
||||||
class AdminSystemUserMixin(SystemUserMixin):
|
class AdminSystemUserMixin(SystemUserMixin):
|
||||||
|
@ -328,22 +331,14 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase):
|
||||||
self.assertNotEqual(url, self.selenium.current_url)
|
self.assertNotEqual(url, self.selenium.current_url)
|
||||||
|
|
||||||
account = Account.objects.get(username=account_username)
|
account = Account.objects.get(username=account_username)
|
||||||
self.addCleanup(self.delete, 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):
|
||||||
home = self.account.main_systemuser.get_home()
|
home = self.account.main_systemuser.get_home()
|
||||||
|
self.admin_delete(self.account)
|
||||||
delete = reverse('admin:accounts_account_delete', args=(self.account.pk,))
|
|
||||||
url = self.live_server_url + delete
|
|
||||||
self.selenium.get(url)
|
|
||||||
confirmation = self.selenium.find_element_by_name('post')
|
|
||||||
confirmation.submit()
|
|
||||||
self.assertNotEqual(url, self.selenium.current_url)
|
|
||||||
|
|
||||||
self.assertRaises(CommandError, run, 'ls %s' % home, display=False)
|
self.assertRaises(CommandError, run, 'ls %s' % home, display=False)
|
||||||
|
|
||||||
# Recreate a fucking fake account for test cleanup
|
# Recreate a fucking fake account for test cleanup
|
||||||
self.account = self.create_account(username=self.account.username, superuser=True)
|
self.account = self.create_account(username=self.account.username, superuser=True)
|
||||||
self.selenium.delete_all_cookies()
|
self.selenium.delete_all_cookies()
|
||||||
|
|
|
@ -76,7 +76,7 @@ class StaticWebAppMixin(object):
|
||||||
|
|
||||||
class PHPFcidWebAppMixin(StaticWebAppMixin):
|
class PHPFcidWebAppMixin(StaticWebAppMixin):
|
||||||
backend = backends.phpfcgid.PHPFcgidBackend
|
backend = backends.phpfcgid.PHPFcgidBackend
|
||||||
type_value = 'php5'
|
type_value = 'php5.2'
|
||||||
token = random_ascii(100)
|
token = random_ascii(100)
|
||||||
page = (
|
page = (
|
||||||
'index.php',
|
'index.php',
|
||||||
|
|
|
@ -76,5 +76,5 @@ def validate_password(value):
|
||||||
|
|
||||||
|
|
||||||
def validate_url_path(value):
|
def validate_url_path(value):
|
||||||
if not re.match(r'^\/[/.a-zA-Z0-9-]*$', value):
|
if not re.match(r'^\/[/.a-zA-Z0-9-_]*$', value):
|
||||||
raise ValidationError(_('"%s" is not a valid URL path.') % value)
|
raise ValidationError(_('"%s" is not a valid URL path.') % value)
|
||||||
|
|
|
@ -44,4 +44,4 @@ def running_syncdb():
|
||||||
|
|
||||||
|
|
||||||
def database_ready():
|
def database_ready():
|
||||||
return not running_syncdb() and 'setuppostgres' not in sys.argv
|
return not running_syncdb() and 'setuppostgres' not in sys.argv and 'test' not in sys.argv
|
||||||
|
|
Loading…
Reference in New Issue