Commit a296ad59 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: WIP tests for subscription with Invitation Token

parent 258aa0f7
......@@ -73,6 +73,8 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
@changeSkin('Hal')
def _requestSubscription(self, **kw):
if self.cloud_invitation_token is not None:
kw["token"] = self.cloud_invitation_token.getId()
if 'target_language' not in kw:
kw["target_language"] = "zh"
kw["subscription_reference"] = self.subscription_condition.getReference().replace("_zh", "")
......@@ -82,6 +84,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
try:
self.portal.portal_secure_payments.slapos_wechat_test.setWechatMode("UNITTEST")
self.logout()
self.changeSkin('Hal')
return self.web_site.hateoas.SubscriptionRequestModule_requestSubscription(**kw)
finally:
self._dropPaymentTransaction_getVADSUrlDict()
......
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (c) 2019 Nexedi SA and Contributors. All Rights Reserved.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from erp5.component.test.testSlapOSSubscriptionChineseScenario import TestSlapOSSubscriptionChineseScenarioMixin
class testSlapOSSubscriptionCloudInvitationTokenScenario(TestSlapOSSubscriptionChineseScenarioMixin):
def test_subscription_scenario_with_single_vm_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario(amount=1)
def test_subscription_with_3_vms_scenario_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario(amount=3)
def test_subscription_scenario_with_reversal_transaction_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario_with_reversal_transaction(amount=1)
def test_two_subscription_scenario_and_empty_invitation(self):
self._test_two_subscription_scenario(amount=1)
def test_subscription_scenario_with_existing_user_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario_with_existing_user(amount=1, language="zh")
def test_subscription_scenario_with_existing_english_user_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario_with_existing_user(amount=1, language="en")
def _init_test_with_valid_invitation(self):
self.expected_reservation_fee = 0.0
self.expected_reservation_quantity_tax = 0.0
self.expected_reservation_tax = 0.0
self.expected_free_reservation = 1
self.cloud_invitation_token = self.makeCloudInvitationToken(
max_invoice_delay=99,
max_invoice_credit_eur=900,
max_invoice_credit_cny=900)
def test_subscription_scenario_with_single_vm_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario(amount=1)
def test_subscription_with_3_vms_scenario_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario(amount=3)
def test_subscription_scenario_with_reversal_transaction_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario_with_reversal_transaction(amount=1)
def test_two_subscription_scenario_with_invitation(self):
self.expected_reservation_fee = 0.0
self.expected_reservation_quantity_tax = 0.0
self.expected_reservation_tax = 0.0
self.expected_free_reservation = 1
self._test_two_subscription_scenario(amount=1,
create_invitation=True,
max_invoice_delay=99,
max_invoice_credit_eur=900,
max_invoice_credit_cny=900
)
def test_subscription_scenario_with_existing_user_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario_with_existing_user(amount=1, language="zh")
def test_subscription_scenario_with_existing_english_user_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario_with_existing_user(amount=1, language="en")
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSSubscriptionInvitationTokenChineseScenario</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSSubscriptionInvitationTokenChineseScenario</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (c) 2019 Nexedi SA and Contributors. All Rights Reserved.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from erp5.component.test.testSlapOSSubscriptionScenario import TestSlapOSSubscriptionScenarioMixin
class testSlapOSSubscriptionCloudInvitationTokenScenario(TestSlapOSSubscriptionScenarioMixin):
def test_subscription_scenario_with_single_vm_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario(amount=1)
def test_subscription_with_3_vms_scenario_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario(amount=3)
def test_subscription_scenario_with_reversal_transaction_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario_with_reversal_transaction(amount=1)
def test_two_subscription_scenario_and_empty_invitation(self):
self._test_two_subscription_scenario(amount=1)
def test_subscription_scenario_with_existing_user_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario_with_existing_user(amount=1, language="zh")
def test_subscription_scenario_with_existing_english_user_and_empty_invitation(self):
self.cloud_invitation_token = self.makeCloudInvitationToken()
self._test_subscription_scenario_with_existing_user(amount=1, language="en")
def _init_test_with_valid_invitation(self):
self.expected_reservation_fee = 0.0
self.expected_reservation_quantity_tax = 0.0
self.expected_reservation_tax = 0.0
self.expected_free_reservation = 1
self.cloud_invitation_token = self.makeCloudInvitationToken(
max_invoice_delay=99,
max_invoice_credit_eur=900,
max_invoice_credit_cny=900)
def test_subscription_scenario_with_single_vm_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario(amount=1)
def test_subscription_with_3_vms_scenario_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario(amount=3)
def test_subscription_scenario_with_reversal_transaction_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario_with_reversal_transaction(amount=1)
def test_two_subscription_scenario_with_invitation(self):
self.expected_reservation_fee = 0.0
self.expected_reservation_quantity_tax = 0.0
self.expected_reservation_tax = 0.0
self.expected_free_reservation = 1
self._test_two_subscription_scenario(amount=1,
create_invitation=True,
max_invoice_delay=99,
max_invoice_credit_eur=900,
max_invoice_credit_cny=900
)
def test_subscription_scenario_with_existing_user_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario_with_existing_user(amount=1, language="zh")
def test_subscription_scenario_with_existing_english_user_with_invitation(self):
self._init_test_with_valid_invitation()
self._test_subscription_scenario_with_existing_user(amount=1, language="en")
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSSubscriptionInvitationTokenScenario</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSSubscriptionInvitationTokenScenario</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -37,12 +37,15 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.expected_notification_language = "en"
self.expected_source = "organisation_module/slapos"
self.expected_source_section = "organisation_module/slapos"
self.cloud_invitation_token = None
self.expected_free_reservation = 0
self.login()
self.portal.portal_alarms.slapos_subscription_request_process_draft.setEnabled(True)
self.portal.portal_alarms.slapos_subscription_request_process_ordered.setEnabled(True)
self.portal.portal_alarms.slapos_subscription_request_process_planned.setEnabled(True)
self.portal.portal_alarms.slapos_subscription_request_process_confirmed.setEnabled(True)
self.portal.portal_alarms.slapos_subscription_request_process_started.setEnabled(True)
DefaultScenarioMixin.afterSetUp(self)
......@@ -385,7 +388,10 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.assertEqual(invoice.getPriceCurrency(), self.expected_price_currency)
for line in invoice.objectValues():
if line.getResource() == "service_module/slapos_reservation_fee":
self.assertEqual(line.getQuantity(), quantity)
if self.expected_free_reservation:
self.assertEqual(line.getQuantity(), 0)
else:
self.assertEqual(line.getQuantity(), quantity)
self.assertEqual(round(line.getPrice(), 2), self.expected_reservation_fee_without_tax)
if line.getResource() == "service_module/slapos_tax":
self.assertEqual(round(line.getQuantity(), 2), round(self.expected_reservation_quantity_tax*quantity, 2))
......@@ -520,8 +526,33 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.assertEqual(sale_packing_list.getPriceCurrency(),
self.expected_price_currency)
def makeCloudInvitationToken(self, max_invoice_delay=0, max_invoice_credit_eur=0.0,
max_invoice_credit_cny=0.0):
self.login()
contract_invitation_token = self.portal.invitation_token_module.newContent(
portal_type="Contract Invitation Token",
maximum_invoice_delay=max_invoice_delay
)
if max_invoice_credit_eur > 0:
contract_invitation_token.newContent(
maximum_invoice_credit=max_invoice_credit_eur,
price_currency="currency_module/EUR")
if max_invoice_credit_cny > 0:
contract_invitation_token.newContent(
maximum_invoice_credit=max_invoice_credit_cny,
price_currency="currency_module/CNY")
contract_invitation_token.validate()
self.logout()
return contract_invitation_token
@changeSkin('Hal')
def _requestSubscription(self, **kw):
if self.cloud_invitation_token is not None:
kw["token"] = self.cloud_invitation_token.getId()
return self.web_site.hateoas.SubscriptionRequestModule_requestSubscription(**kw)
def getAggregatedSalePackingList(self, subscription_request, specialise):
......@@ -852,8 +883,6 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.checkStartedSubscriptionRequest(subscription_request,
default_email_text, self.subscription_condition)
def checkSubscriptionDeploymentAndSimulation(self, default_email_text, subscription_server):
subscription_request_list = self.getSubscriptionRequestList(
default_email_text, self.subscription_condition)
......@@ -934,7 +963,8 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
subscription_request.getDestinationSectionValue())
def _test_two_subscription_scenario(self, amount=1):
def _test_two_subscription_scenario(self, amount=1, create_invitation=False,
max_invoice_delay=0, max_invoice_credit_eur=0.0, max_invoice_credit_cny=0.0):
""" The admin creates an computer, user can request instances on it"""
subscription_server = self.createPublicServerForAdminUser()
......@@ -942,6 +972,13 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
# Call as anonymous... check response?
default_email_text = "abc%s@nexedi.com" % self.new_id
name="ABC %s" % self.new_id
if create_invitation:
self.login()
self.cloud_invitation_token = self.makeCloudInvitationToken(
max_invoice_delay=max_invoice_delay,
max_invoice_credit_eur=max_invoice_credit_eur,
max_invoice_credit_cny=max_invoice_credit_cny
)
self.logout()
self._requestSubscription(
......@@ -981,8 +1018,17 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self.checkOrderedSubscriptionRequest(first_subscription_request,
default_email_text, self.subscription_condition)
if create_invitation:
self.login()
self.cloud_invitation_token = self.makeCloudInvitationToken(
max_invoice_delay=max_invoice_delay,
max_invoice_credit_eur=max_invoice_credit_eur,
max_invoice_credit_cny=max_invoice_credit_cny
)
self.logout()
# Request a second one, without require confirmation and verifing the second subscription request
# Request a second one, without require confirmation and verifing
# the second subscription request
self._requestSubscription(
subscription_reference=self.subscription_condition.getReference(),
amount=amount,
......
......@@ -6,4 +6,6 @@ test.erp5.testSlapOSSubscriptionSkins
test.erp5.testSlapOSSubscriptionScenario
test.erp5.testSlapOSSubscriptionChineseScenario
test.erp5.testSlapOSSubscriptionNewTemplateScenario
test.erp5.testSlapOSSubscriptionNewTemplateChineseScenario
\ No newline at end of file
test.erp5.testSlapOSSubscriptionNewTemplateChineseScenario
test.erp5.testSlapOSSubscriptionInvitationTokenScenario
test.erp5.testSlapOSSubscriptionInvitationTokenChineseScenario
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment