testSlapOSAccountingSkins.py 4.64 KB
Newer Older
1 2 3 4 5 6 7 8 9
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
#
##############################################################################

from Products.SlapOS.tests.testSlapOSMixin import \
  testSlapOSMixin, withAbort
10 11
from zExceptions import Unauthorized
from DateTime import DateTime
12 13

class TestSlapOSAccounting(testSlapOSMixin):
14 15 16 17 18 19 20 21 22

  def createHostingSubscription(self):
    new_id = self.generateNewId()
    return self.portal.hosting_subscription_module.newContent(
      portal_type='Hosting Subscription',
      title="Subscription %s" % new_id,
      reference="TESTHS-%s" % new_id,
      )

23 24 25 26 27
  @withAbort
  def test_Service_getPriceCalculationOperandDict(self):
    service = self.portal.service_module.newContent(portal_type='Service')
    self.assertEqual({'price': 0.0},
        service.Service_getPriceCalculationOperandDict())
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

  @withAbort
  def test_HS_calculateSubscriptionStartDate_REQUEST_disallowed(self):
    item = self.createHostingSubscription()
    self.assertRaises(
      Unauthorized,
      item.HostingSubscription_calculateSubscriptionStartDate,
      REQUEST={})

  @withAbort
  def test_HS_calculateSubscriptionStartDate_noWorkflow(self):
    item = self.createHostingSubscription()
    item.workflow_history['instance_slap_interface_workflow'] = []
    date = item.HostingSubscription_calculateSubscriptionStartDate()
    self.assertEqual(date, item.getCreationDate().earliestTime())

  @withAbort
  def test_HS_calculateSubscriptionStartDate_withRequest(self):
    item = self.createHostingSubscription()
    item.workflow_history['instance_slap_interface_workflow'] = [{
        'comment':'Directly request the instance',
        'error_message': '',
        'actor': 'ERP5TypeTestCase',
        'slap_state': 'draft',
        'time': DateTime('2012/11/15 11:11'),
        'action': 'request_instance'
        }]
    date = item.HostingSubscription_calculateSubscriptionStartDate()
    self.assertEqual(date, DateTime('2012/11/15'))

  @withAbort
  def test_HS_calculateSubscriptionStartDate_withRequestEndOfMonth(self):
    item = self.createHostingSubscription()
    item.workflow_history['instance_slap_interface_workflow'] = [{
        'comment':'Directly request the instance',
        'error_message': '',
        'actor': 'ERP5TypeTestCase',
        'slap_state': 'draft',
        'time': DateTime('2012/11/30 11:11'),
        'action': 'request_instance'
    }]
    date = item.HostingSubscription_calculateSubscriptionStartDate()
    self.assertEqual(date, DateTime('2012/11/30'))

  @withAbort
  def test_HS_calculateSubscriptionStartDate_withRequestAfterDestroy(self):
    item = self.createHostingSubscription()
    destroy_date = DateTime('2012/10/30 11:11')
    request_date = DateTime('2012/11/30 11:11')
    item.workflow_history['instance_slap_interface_workflow'] = []
    item.workflow_history['instance_slap_interface_workflow'].append({
        'comment':'Directly destroy',
        'error_message': '',
        'actor': 'ERP5TypeTestCase',
        'slap_state': 'destroy_requested',
        'time': destroy_date,
        'action': 'request_destroy'
    })
    item.workflow_history['instance_slap_interface_workflow'].append({
        'comment':'Directly request the instance',
        'error_message': '',
        'actor': 'ERP5TypeTestCase',
        'slap_state': 'draft',
        'time': request_date,
        'action': 'request_instance'
    })
    date = item.HostingSubscription_calculateSubscriptionStartDate()
    self.assertEqual(date, DateTime('2012/10/30'))

  @withAbort
  def test_HS_calculateSubscriptionStopDate_REQUEST_disallowed(self):
    item = self.createHostingSubscription()
    self.assertRaises(
      Unauthorized,
      item.HostingSubscription_calculateSubscriptionStopDate,
      REQUEST={})

  @withAbort
  def test_HS_calculateSubscriptionStopDate_withDestroy(self):
    item = self.createHostingSubscription()
    destroy_date = DateTime('2012/10/30')
    item.workflow_history['instance_slap_interface_workflow'].append({
        'comment':'Directly destroy',
        'error_message': '',
        'actor': 'ERP5TypeTestCase',
        'slap_state': 'destroy_requested',
        'time': destroy_date,
        'action': 'request_destroy'
    })
    date = item.HostingSubscription_calculateSubscriptionStopDate()
    self.assertEqual(date, DateTime('2012/10/31'))

  @withAbort
  def test_HS_calculateSubscriptionStopDate_noDestroy(self):
    item = self.createHostingSubscription()
    item.workflow_history['instance_slap_interface_workflow'] = []
    date = item.HostingSubscription_calculateSubscriptionStopDate()
    self.assertEqual(date, None)