From d5cc1b7d7cf5423ee488c6aa06dc25745640bc80 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 23 Oct 2014 21:25:44 +0000 Subject: [PATCH] Fixes on tests0 --- orchestra/apps/accounts/api.py | 2 +- orchestra/apps/domains/backends.py | 6 +++--- orchestra/apps/lists/backends.py | 2 +- orchestra/apps/mailboxes/backends.py | 8 ++++---- orchestra/apps/orchestration/models.py | 4 ++++ .../tests/functional_tests/test_mailbox.py | 3 ++- orchestra/apps/systemusers/api.py | 2 +- orchestra/apps/systemusers/models.py | 3 ++- .../systemusers/tests/functional_tests/tests.py | 15 +++++---------- .../apps/webapps/tests/functional_tests/tests.py | 2 +- orchestra/core/validators.py | 2 +- orchestra/utils/options.py | 2 +- 12 files changed, 26 insertions(+), 25 deletions(-) diff --git a/orchestra/apps/accounts/api.py b/orchestra/apps/accounts/api.py index 24b82db7..b7c20e50 100644 --- a/orchestra/apps/accounts/api.py +++ b/orchestra/apps/accounts/api.py @@ -26,7 +26,7 @@ class AccountViewSet(SetPasswordApiMixin, viewsets.ModelViewSet): # TODO reimplement in permissions if not request.user.is_superuser: 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) diff --git a/orchestra/apps/domains/backends.py b/orchestra/apps/domains/backends.py index 156fe05b..c1b71568 100644 --- a/orchestra/apps/domains/backends.py +++ b/orchestra/apps/domains/backends.py @@ -91,7 +91,7 @@ class Bind9MasterDomainBackend(ServiceController): 'zone_path': settings.DOMAINS_ZONE_PATH % {'name': domain.name}, 'subdomains': domain.subdomains.all(), 'banner': self.get_banner(), - 'slaves': '; '.join(self.get_slaves(domain)) or '', + 'slaves': '; '.join(self.get_slaves(domain)) or 'none', } context.update({ 'conf_path': settings.DOMAINS_MASTERS_PATH, @@ -101,7 +101,7 @@ class Bind9MasterDomainBackend(ServiceController): type master; file "%(zone_path)s"; allow-transfer { %(slaves)s; }; - also-notify { %(slaves)s; }; + notify yes; };""" % context) }) return context @@ -133,7 +133,7 @@ class Bind9SlaveDomainBackend(Bind9MasterDomainBackend): 'name': domain.name, 'banner': self.get_banner(), 'subdomains': domain.subdomains.all(), - 'masters': '; '.join(self.get_masters(domain)) or '', + 'masters': '; '.join(self.get_masters(domain)) or 'none', } context.update({ 'conf_path': settings.DOMAINS_SLAVES_PATH, diff --git a/orchestra/apps/lists/backends.py b/orchestra/apps/lists/backends.py index e94b87ec..3a6c8fed 100644 --- a/orchestra/apps/lists/backends.py +++ b/orchestra/apps/lists/backends.py @@ -125,7 +125,7 @@ class MailmanBackend(ServiceController): 'name': mail_list.name, 'password': mail_list.password, '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, 'admin': mail_list.admin_email, 'mailman_root': settings.LISTS_MAILMAN_ROOT_PATH, diff --git a/orchestra/apps/mailboxes/backends.py b/orchestra/apps/mailboxes/backends.py index 40bbb8e3..73e4436d 100644 --- a/orchestra/apps/mailboxes/backends.py +++ b/orchestra/apps/mailboxes/backends.py @@ -217,9 +217,9 @@ class MaildirDisk(ServiceMonitor): ) def get_context(self, mailbox): - context = MailSystemUserBackend().get_context(mailbox) - context.update({ - 'rr_path': os.path.join(context['home'], 'Maildir/maildirsize'), + home = mailbox.get_home() + context = { + 'maildir_path': os.path.join(home, 'Maildir/maildirsize'), 'object_id': mailbox.pk - }) + } return context diff --git a/orchestra/apps/orchestration/models.py b/orchestra/apps/orchestration/models.py index c04f721f..171eb4a0 100644 --- a/orchestra/apps/orchestration/models.py +++ b/orchestra/apps/orchestration/models.py @@ -128,6 +128,10 @@ class BackendOperation(models.Model): # instance should maintain any dynamic attribute until backend execution # deep copy is prefered over copy otherwise objects will share same atributes (queryset cache) 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 @classmethod diff --git a/orchestra/apps/services/tests/functional_tests/test_mailbox.py b/orchestra/apps/services/tests/functional_tests/test_mailbox.py index 852fdabc..70504726 100644 --- a/orchestra/apps/services/tests/functional_tests/test_mailbox.py +++ b/orchestra/apps/services/tests/functional_tests/test_mailbox.py @@ -50,7 +50,7 @@ class MailboxBillingTest(BaseBillingTest): tax=0, 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) return service @@ -68,6 +68,7 @@ class MailboxBillingTest(BaseBillingTest): return self.resource def allocate_disk(self, mailbox, value): + # TODO get_or_Create return created data = ResourceData.get_or_create(mailbox, self.resource) data.allocated = value data.save() diff --git a/orchestra/apps/systemusers/api.py b/orchestra/apps/systemusers/api.py index 7e423f9b..68c0fce6 100644 --- a/orchestra/apps/systemusers/api.py +++ b/orchestra/apps/systemusers/api.py @@ -17,7 +17,7 @@ class SystemUserViewSet(AccountApiMixin, SetPasswordApiMixin, viewsets.ModelView user = self.get_object() if user.is_main: 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) diff --git a/orchestra/apps/systemusers/models.py b/orchestra/apps/systemusers/models.py index c4e71b0c..aa4f4bd7 100644 --- a/orchestra/apps/systemusers/models.py +++ b/orchestra/apps/systemusers/models.py @@ -53,8 +53,9 @@ class SystemUser(models.Model): except type(self).account.field.rel.to.DoesNotExist: return self.is_active - @property + @cached_property def is_main(self): + # TODO on account delete # On account creation main_systemuser_id is still None if self.account.main_systemuser_id: return self.account.main_systemuser_id == self.pk diff --git a/orchestra/apps/systemusers/tests/functional_tests/tests.py b/orchestra/apps/systemusers/tests/functional_tests/tests.py index b96db807..40ac949f 100644 --- a/orchestra/apps/systemusers/tests/functional_tests/tests.py +++ b/orchestra/apps/systemusers/tests/functional_tests/tests.py @@ -223,6 +223,9 @@ class RESTSystemUserMixin(SystemUserMixin): def change_password(self, username, password): user = self.rest.systemusers.retrieve(username=username).get() user.set_password(password) + + def delete_account(self, username): + self.rest.account.delete() class AdminSystemUserMixin(SystemUserMixin): @@ -328,22 +331,14 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase): self.assertNotEqual(url, self.selenium.current_url) 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) @snapshot_on_error def test_delete_account(self): home = self.account.main_systemuser.get_home() - - 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.admin_delete(self.account) self.assertRaises(CommandError, run, 'ls %s' % home, display=False) - # Recreate a fucking fake account for test cleanup self.account = self.create_account(username=self.account.username, superuser=True) self.selenium.delete_all_cookies() diff --git a/orchestra/apps/webapps/tests/functional_tests/tests.py b/orchestra/apps/webapps/tests/functional_tests/tests.py index f3dd45e6..2d991379 100644 --- a/orchestra/apps/webapps/tests/functional_tests/tests.py +++ b/orchestra/apps/webapps/tests/functional_tests/tests.py @@ -76,7 +76,7 @@ class StaticWebAppMixin(object): class PHPFcidWebAppMixin(StaticWebAppMixin): backend = backends.phpfcgid.PHPFcgidBackend - type_value = 'php5' + type_value = 'php5.2' token = random_ascii(100) page = ( 'index.php', diff --git a/orchestra/core/validators.py b/orchestra/core/validators.py index 9848c8f6..15977cc8 100644 --- a/orchestra/core/validators.py +++ b/orchestra/core/validators.py @@ -76,5 +76,5 @@ def validate_password(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) diff --git a/orchestra/utils/options.py b/orchestra/utils/options.py index 3df7f990..02deedde 100644 --- a/orchestra/utils/options.py +++ b/orchestra/utils/options.py @@ -44,4 +44,4 @@ def running_syncdb(): 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