Fixed services tests

This commit is contained in:
Marc Aymerich 2015-05-13 17:22:54 +00:00
parent a0ccb5c420
commit a78c7e2769
10 changed files with 55 additions and 36 deletions

View File

@ -361,9 +361,10 @@ resorce monitoring more efficient, less mem an better queries for calc current d
# autoresponses on mailboxes, not addresses or remove them # autoresponses on mailboxes, not addresses or remove them
# Async particular actions? # Async specific backend actions? systemusers.set_permission
# gevent for python3
apt-get install cython3 apt-get install cython3
export CYTHON='cython3' export CYTHON='cython3'
pip3 install https://github.com/fantix/gevent/archive/master.zip pip3 install https://github.com/fantix/gevent/archive/master.zip

View File

@ -11,5 +11,4 @@ class OrdersConfig(AppConfig):
def ready(self): def ready(self):
from .models import Order from .models import Order
accounts.register(Order, icon='basket.png') accounts.register(Order, icon='basket.png')
if database_ready():
from . import signals from . import signals

View File

@ -18,7 +18,7 @@ class DomainBillingTest(BaseTestCase):
is_fee=False, is_fee=False,
metric='', metric='',
pricing_period=Service.BILLING_PERIOD, pricing_period=Service.BILLING_PERIOD,
rate_algorithm='STEP_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.NOTHING, on_cancel=Service.NOTHING,
payment_style=Service.PREPAY, payment_style=Service.PREPAY,
tax=0, tax=0,

View File

@ -13,6 +13,12 @@ from ...models import Service
class FTPBillingTest(BaseTestCase): class FTPBillingTest(BaseTestCase):
DEPENDENCIES = (
'orchestra.contrib.orders',
'orchestra.contrib.plans',
'orchestra.contrib.systemusers',
)
def create_ftp_service(self): def create_ftp_service(self):
return Service.objects.create( return Service.objects.create(
description="FTP Account", description="FTP Account",
@ -23,7 +29,7 @@ class FTPBillingTest(BaseTestCase):
is_fee=False, is_fee=False,
metric='', metric='',
pricing_period=Service.NEVER, pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.COMPENSATE, on_cancel=Service.COMPENSATE,
payment_style=Service.PREPAY, payment_style=Service.PREPAY,
tax=0, tax=0,
@ -39,6 +45,7 @@ class FTPBillingTest(BaseTestCase):
def test_ftp_account_1_year_fiexed(self): def test_ftp_account_1_year_fiexed(self):
service = self.create_ftp_service() service = self.create_ftp_service()
self.create_ftp() self.create_ftp()
self.assertEqual(1, service.orders.count())
bp = timezone.now().date() + relativedelta(years=1) bp = timezone.now().date() + relativedelta(years=1)
bills = service.orders.bill(billing_point=bp, fixed_point=True) bills = service.orders.bill(billing_point=bp, fixed_point=True)
self.assertEqual(10, bills[0].get_total()) self.assertEqual(10, bills[0].get_total())

View File

@ -18,7 +18,7 @@ class JobBillingTest(BaseTestCase):
is_fee=False, is_fee=False,
metric='miscellaneous.amount', metric='miscellaneous.amount',
pricing_period=Service.BILLING_PERIOD, pricing_period=Service.BILLING_PERIOD,
rate_algorithm='MATCH_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.match_price',
on_cancel=Service.NOTHING, on_cancel=Service.NOTHING,
payment_style=Service.POSTPAY, payment_style=Service.POSTPAY,
tax=0, tax=0,

View File

@ -22,7 +22,7 @@ class MailboxBillingTest(BaseTestCase):
is_fee=False, is_fee=False,
metric='', metric='',
pricing_period=Service.NEVER, pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.COMPENSATE, on_cancel=Service.COMPENSATE,
payment_style=Service.PREPAY, payment_style=Service.PREPAY,
tax=0, tax=0,
@ -43,7 +43,7 @@ class MailboxBillingTest(BaseTestCase):
is_fee=False, is_fee=False,
metric='max((mailbox.resources.disk.allocated or 0) -1, 0)', metric='max((mailbox.resources.disk.allocated or 0) -1, 0)',
pricing_period=Service.NEVER, pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.DISCOUNT, on_cancel=Service.DISCOUNT,
payment_style=Service.PREPAY, payment_style=Service.PREPAY,
tax=0, tax=0,

View File

@ -17,7 +17,7 @@ class PlanBillingTest(BaseTestCase):
is_fee=True, is_fee=True,
metric='', metric='',
pricing_period=Service.BILLING_PERIOD, pricing_period=Service.BILLING_PERIOD,
rate_algorithm='STEP_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.DISCOUNT, on_cancel=Service.DISCOUNT,
payment_style=Service.PREPAY, payment_style=Service.PREPAY,
tax=0, tax=0,

View File

@ -7,11 +7,16 @@ from orchestra.contrib.accounts.models import Account
from orchestra.contrib.miscellaneous.models import MiscService, Miscellaneous from orchestra.contrib.miscellaneous.models import MiscService, Miscellaneous
from orchestra.contrib.plans.models import Plan from orchestra.contrib.plans.models import Plan
from orchestra.contrib.resources.models import Resource, ResourceData, MonitorData from orchestra.contrib.resources.models import Resource, ResourceData, MonitorData
from orchestra.contrib.resources.backends import ServiceMonitor
from orchestra.utils.tests import BaseTestCase from orchestra.utils.tests import BaseTestCase
from ...models import Service from ...models import Service
class FTPTrafficMonitor(ServiceMonitor):
model = 'systemusers.SystemUser'
class BaseTrafficBillingTest(BaseTestCase): class BaseTrafficBillingTest(BaseTestCase):
TRAFFIC_METRIC = 'account.resources.traffic.used' TRAFFIC_METRIC = 'account.resources.traffic.used'
@ -25,7 +30,7 @@ class BaseTrafficBillingTest(BaseTestCase):
is_fee=False, is_fee=False,
metric=self.TRAFFIC_METRIC, metric=self.TRAFFIC_METRIC,
pricing_period=Service.BILLING_PERIOD, pricing_period=Service.BILLING_PERIOD,
rate_algorithm='STEP_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.NOTHING, on_cancel=Service.NOTHING,
payment_style=Service.POSTPAY, payment_style=Service.POSTPAY,
tax=0, tax=0,
@ -45,12 +50,13 @@ class BaseTrafficBillingTest(BaseTestCase):
unit='GB', unit='GB',
scale='10**9', scale='10**9',
on_demand=True, on_demand=True,
monitors='FTPTraffic', # TODO
monitors=FTPTrafficMonitor.get_name(),
) )
return self.resource return self.resource
def report_traffic(self, account, value): def report_traffic(self, account, value):
MonitorData.objects.create(monitor='FTPTraffic', content_object=account.systemusers.get(), value=value) MonitorData.objects.create(monitor=FTPTrafficMonitor.get_name(), content_object=account.systemusers.get(), value=value)
data, __ = ResourceData.get_or_create(account, self.resource) data, __ = ResourceData.get_or_create(account, self.resource)
data.update() data.update()
@ -107,7 +113,7 @@ class TrafficPrepayBillingTest(BaseTrafficBillingTest):
is_fee=False, is_fee=False,
metric="miscellaneous.amount", metric="miscellaneous.amount",
pricing_period=Service.NEVER, pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE', rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.NOTHING, on_cancel=Service.NOTHING,
payment_style=Service.PREPAY, payment_style=Service.PREPAY,
tax=0, tax=0,
@ -139,7 +145,6 @@ class TrafficPrepayBillingTest(BaseTrafficBillingTest):
bill = account.orders.bill(proforma=True, new_open=True)[0] bill = account.orders.bill(proforma=True, new_open=True)[0]
self.assertEqual(2*10*50 + 0*10, bill.get_total()) self.assertEqual(2*10*50 + 0*10, bill.get_total())
# TODO dateutils.relativedelta is buggy with fakedatetime
# TODO RuntimeWarning: DateTimeField MetricStorage.updated_on received a naive # TODO RuntimeWarning: DateTimeField MetricStorage.updated_on received a naive
self.report_traffic(account, 10**10) self.report_traffic(account, 10**10)
with freeze_time(now+relativedelta(months=1)): with freeze_time(now+relativedelta(months=1)):

View File

@ -32,15 +32,21 @@ class UNIXUserBackend(ServiceController):
# TODO userd add will fail if %(user)s group already exists # TODO userd add will fail if %(user)s group already exists
self.append(textwrap.dedent(""" self.append(textwrap.dedent("""
if [[ $( id %(user)s ) ]]; then if [[ $( id %(user)s ) ]]; then
usermod %(user)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s usermod %(user)s --home %(home)s \\
--password '%(password)s' \\
--shell %(shell)s %(groups_arg)s
else else
useradd %(user)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s || { useradd %(user)s --home %(home)s \\
--password '%(password)s' \\
--shell %(shell)s %(groups_arg)s || {
useradd_code=$? useradd_code=$?
# User is logged in, kill and retry # User is logged in, kill and retry
if [[ $useradd_code -eq 8 ]]; then if [[ $useradd_code -eq 8 ]]; then
pkill -u %(user)s; sleep 2 pkill -u %(user)s; sleep 2
pkill -9 -u %(user)s; sleep 1 pkill -9 -u %(user)s; sleep 1
useradd %(user)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s useradd %(user)s --home %(home)s \\
--password '%(password)s' \\
--shell %(shell)s %(groups_arg)s
else else
exit $useradd_code exit $useradd_code
fi fi

View File

@ -82,6 +82,7 @@ class PHPApp(AppType):
options += list(webapp.options.all()) options += list(webapp.options.all())
init_vars = OrderedDict((opt.name, opt.value) for opt in options) init_vars = OrderedDict((opt.name, opt.value) for opt in options)
# Enable functions # Enable functions
if self.PHP_DISABLED_FUNCTIONS:
enable_functions = init_vars.pop('enable_functions', '') enable_functions = init_vars.pop('enable_functions', '')
if enable_functions or self.is_fpm: if enable_functions or self.is_fpm:
# FPM: Defining 'disable_functions' or 'disable_classes' will not overwrite previously # FPM: Defining 'disable_functions' or 'disable_classes' will not overwrite previously