Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Roque
slapos.core
Commits
ec20995b
Commit
ec20995b
authored
Jun 23, 2020
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_subscription_request: Attempt to make chinese tests more realistic
Use Wechat payment rather them payzen
parent
a5b7c244
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
144 additions
and
15 deletions
+144
-15
master/bt5/slapos_subscription_request/TestTemplateItem/portal_components/test.erp5.testSlapOSSubscriptionChineseScenario.py
...onents/test.erp5.testSlapOSSubscriptionChineseScenario.py
+111
-2
master/bt5/slapos_subscription_request/TestTemplateItem/portal_components/test.erp5.testSlapOSSubscriptionScenario.py
...al_components/test.erp5.testSlapOSSubscriptionScenario.py
+33
-13
No files found.
master/bt5/slapos_subscription_request/TestTemplateItem/portal_components/test.erp5.testSlapOSSubscriptionChineseScenario.py
View file @
ec20995b
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
##############################################################################
##############################################################################
from
erp5.component.test.testSlapOSSubscriptionScenario
import
TestSlapOSSubscriptionScenarioMixin
from
erp5.component.test.testSlapOSSubscriptionScenario
import
TestSlapOSSubscriptionScenarioMixin
from
erp5.component.test.SlapOSTestCaseMixin
import
changeSkin
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
class
TestSlapOSSubscriptionChineseScenario
(
TestSlapOSSubscriptionScenarioMixin
):
class
TestSlapOSSubscriptionChineseScenario
(
TestSlapOSSubscriptionScenarioMixin
):
...
@@ -27,6 +29,50 @@ class TestSlapOSSubscriptionChineseScenario(TestSlapOSSubscriptionScenarioMixin)
...
@@ -27,6 +29,50 @@ class TestSlapOSSubscriptionChineseScenario(TestSlapOSSubscriptionScenarioMixin)
TestSlapOSSubscriptionScenarioMixin
.
afterSetUp
(
self
)
TestSlapOSSubscriptionScenarioMixin
.
afterSetUp
(
self
)
self
.
expected_individual_price_without_tax
=
1573.3333333333335
self
.
expected_individual_price_without_tax
=
1573.3333333333335
self
.
expected_individual_price_with_tax
=
1888.00
self
.
expected_individual_price_with_tax
=
1888.00
self
.
expected_reservation_fee
=
188.00
self
.
expected_reservation_fee_without_tax
=
188
self
.
expected_reservation_quantity_tax
=
0
self
.
expected_reservation_tax
=
0
self
.
expected_price_currency
=
"currency_module/CNY"
def
_simulatePaymentTransaction_getVADSUrlDict
(
self
):
script_name
=
'PaymentTransaction_getVADSUrlDict'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
raise
ValueError
(
'Precondition failed: %s exists in custom'
%
script_name
)
createZODBPythonScript
(
self
.
portal
.
portal_skins
.
custom
,
script_name
,
'*args, **kwargs'
,
'# Script body
\
n
'
"""payment_transaction_url = context.getRelativeUrl()
return dict(vads_url_already_registered="%s/already_registered" % (payment_transaction_url),
vads_url_cancel="%s/cancel" % (payment_transaction_url),
vads_url_error="%s/error" % (payment_transaction_url),
vads_url_referral="%s/referral" % (payment_transaction_url),
vads_url_refused="%s/refused" % (payment_transaction_url),
vads_url_success="%s/success" % (payment_transaction_url),
vads_url_return="%s/return" % (payment_transaction_url),
)"""
)
def
_dropPaymentTransaction_getVADSUrlDict
(
self
):
script_name
=
'PaymentTransaction_getVADSUrlDict'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
@
changeSkin
(
'Hal'
)
def
_requestSubscription
(
self
,
**
kw
):
if
'target_language'
not
in
kw
:
kw
[
"target_language"
]
=
"zh"
kw
[
"subscription_reference"
]
=
self
.
subscription_condition
.
getReference
().
replace
(
"_zh"
,
""
)
original_mode
=
self
.
portal
.
portal_secure_payments
.
slapos_wechat_test
.
getWechatMode
()
self
.
_simulatePaymentTransaction_getVADSUrlDict
()
try
:
self
.
portal
.
portal_secure_payments
.
slapos_wechat_test
.
setWechatMode
(
"UNITTEST"
)
return
self
.
web_site
.
hateoas
.
SubscriptionRequestModule_requestSubscription
(
**
kw
)
finally
:
self
.
_dropPaymentTransaction_getVADSUrlDict
()
self
.
portal
.
portal_secure_payments
.
slapos_wechat_test
.
setWechatMode
(
original_mode
)
def
createSubscriptionCondition
(
self
,
slave
=
False
):
def
createSubscriptionCondition
(
self
,
slave
=
False
):
self
.
subscription_condition
=
self
.
portal
.
subscription_condition_module
.
newContent
(
self
.
subscription_condition
=
self
.
portal
.
subscription_condition_module
.
newContent
(
...
@@ -37,9 +83,9 @@ class TestSlapOSSubscriptionChineseScenario(TestSlapOSSubscriptionScenarioMixin)
...
@@ -37,9 +83,9 @@ class TestSlapOSSubscriptionChineseScenario(TestSlapOSSubscriptionScenarioMixin)
url_string
=
self
.
generateNewSoftwareReleaseUrl
(),
url_string
=
self
.
generateNewSoftwareReleaseUrl
(),
root_slave
=
slave
,
root_slave
=
slave
,
price
=
1888.00
,
price
=
1888.00
,
resource
=
"currency_module/CNY"
,
price_currency
=
"currency_module/CNY"
,
default_source_reference
=
"default"
,
default_source_reference
=
"default"
,
reference
=
"rapidvm%s"
%
self
.
new_id
,
reference
=
"rapidvm%s
_zh
"
%
self
.
new_id
,
# Aggregate and Follow up to web pages for product description and
# Aggregate and Follow up to web pages for product description and
# Terms of service
# Terms of service
sla_xml
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
<instance>
\
n
</instance>'
,
sla_xml
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
<instance>
\
n
</instance>'
,
...
@@ -50,6 +96,69 @@ class TestSlapOSSubscriptionChineseScenario(TestSlapOSSubscriptionScenarioMixin)
...
@@ -50,6 +96,69 @@ class TestSlapOSSubscriptionChineseScenario(TestSlapOSSubscriptionScenarioMixin)
self
.
subscription_condition
.
updateLocalRolesOnSecurityGroups
()
self
.
subscription_condition
.
updateLocalRolesOnSecurityGroups
()
self
.
tic
()
self
.
tic
()
def
_payPayment
(
self
,
subscription_request
):
quantity
=
subscription_request
.
getQuantity
()
# Check Payment
payment
=
self
.
_getRelatedPaymentValue
(
subscription_request
)
self
.
assertEqual
(
self
.
expected_price_currency
,
payment
.
getPriceCurrency
())
self
.
assertEqual
(
-
self
.
expected_reservation_fee
*
quantity
,
payment
.
PaymentTransaction_getTotalPayablePrice
())
self
.
assertEqual
(
payment
.
getSimulationState
(),
"started"
)
# Pay 188 CNY per VM
data_kw
=
{
'result_code'
:
'SUCCESS'
,
'trade_state'
:
'SUCCESS'
,
'total_fee'
:
self
.
expected_reservation_fee
*
100
*
quantity
,
'fee_type'
:
'CNY'
,
}
# Wechat_processUpdate will mark payment as payed by stopping it.
payment
.
PaymentTransaction_createWechatEvent
().
WechatEvent_processUpdate
(
data_kw
)
return
payment
def
checkAndPayFirstMonth
(
self
,
subscription_request
):
self
.
login
()
original_mode
=
self
.
portal
.
portal_secure_payments
.
slapos_wechat_test
.
getWechatMode
()
self
.
_simulatePaymentTransaction_getVADSUrlDict
()
try
:
person
=
subscription_request
.
getDestinationSectionValue
()
quantity
=
subscription_request
.
getQuantity
()
self
.
portal
.
portal_secure_payments
.
slapos_wechat_test
.
setWechatMode
(
"UNITTEST"
)
self
.
login
(
person
.
getUserId
())
self
.
useWechatManually
(
self
.
web_site
,
person
.
getUserId
())
payment
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
"Payment Transaction"
,
simulation_state
=
"started"
)
authAmount
=
(
int
(
self
.
expected_individual_price_with_tax
*
100
)
*
1
-
int
(
self
.
expected_reservation_fee
*
100
))
*
quantity
self
.
assertEqual
(
int
(
payment
.
PaymentTransaction_getTotalPayablePrice
()
*
100
),
-
authAmount
)
self
.
assertEqual
(
payment
.
getPriceCurrency
(),
self
.
expected_price_currency
)
self
.
logout
()
self
.
login
()
data_kw
=
{
'result_code'
:
'SUCCESS'
,
'trade_state'
:
'SUCCESS'
,
'total_fee'
:
authAmount
,
'fee_type'
:
'CNY'
,
}
# Wechat_processUpdate will mark payment as payed by stopping it.
payment
.
PaymentTransaction_createWechatEvent
().
WechatEvent_processUpdate
(
data_kw
)
finally
:
self
.
_dropPaymentTransaction_getVADSUrlDict
()
self
.
portal
.
portal_secure_payments
.
slapos_wechat_test
.
setWechatMode
(
original_mode
)
def
test_subscription_scenario_with_single_vm
(
self
):
def
test_subscription_scenario_with_single_vm
(
self
):
self
.
_test_subscription_scenario
(
amount
=
1
)
self
.
_test_subscription_scenario
(
amount
=
1
)
...
...
master/bt5/slapos_subscription_request/TestTemplateItem/portal_components/test.erp5.testSlapOSSubscriptionScenario.py
View file @
ec20995b
...
@@ -29,6 +29,9 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
...
@@ -29,6 +29,9 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
self
.
expected_individual_price_without_tax
=
162.50
self
.
expected_individual_price_without_tax
=
162.50
self
.
expected_individual_price_with_tax
=
195.00
self
.
expected_individual_price_with_tax
=
195.00
self
.
expected_reservation_fee
=
25.00
self
.
expected_reservation_fee
=
25.00
self
.
expected_reservation_fee_without_tax
=
20.83
self
.
expected_reservation_quantity_tax
=
20.833333333333333
self
.
expected_reservation_tax
=
4.166666666666667
self
.
expected_price_currency
=
"currency_module/EUR"
self
.
expected_price_currency
=
"currency_module/EUR"
self
.
login
()
self
.
login
()
...
@@ -135,7 +138,7 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
...
@@ -135,7 +138,7 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
url_string
=
self
.
generateNewSoftwareReleaseUrl
(),
url_string
=
self
.
generateNewSoftwareReleaseUrl
(),
root_slave
=
slave
,
root_slave
=
slave
,
price
=
195.00
,
price
=
195.00
,
resource
=
"currency_module/EUR"
,
price_currency
=
"currency_module/EUR"
,
default_source_reference
=
"default"
,
default_source_reference
=
"default"
,
reference
=
"rapidvm%s"
%
self
.
new_id
,
reference
=
"rapidvm%s"
%
self
.
new_id
,
# Aggregate and Follow up to web pages for product description and
# Aggregate and Follow up to web pages for product description and
...
@@ -240,13 +243,19 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
...
@@ -240,13 +243,19 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
portal_type
=
"Payment Transaction"
,
portal_type
=
"Payment Transaction"
,
simulation_state
=
"started"
)
simulation_state
=
"started"
)
self
.
logout
()
self
.
login
()
# 195 is the month payment
# 195 is the month payment
# 195*1 is the 1 months to pay upfront to use.
# 195*1 is the 1 months to pay upfront to use.
# 25 is the reservation fee deduction.
# 25 is the reservation fee deduction.
authAmount
=
(
int
(
self
.
expected_individual_price_with_tax
*
100
)
*
1
-
int
(
self
.
expected_reservation_fee
*
100
))
*
quantity
authAmount
=
(
int
(
self
.
expected_individual_price_with_tax
*
100
)
*
1
-
int
(
self
.
expected_reservation_fee
*
100
))
*
quantity
self
.
assertEqual
(
int
(
payment
.
PaymentTransaction_getTotalPayablePrice
()
*
100
),
-
authAmount
)
self
.
assertEqual
(
payment
.
getPriceCurrency
(),
self
.
expected_price_currency
)
self
.
logout
()
self
.
login
()
data_kw
=
{
data_kw
=
{
'errorCode'
:
'0'
,
'errorCode'
:
'0'
,
'transactionStatus'
:
'6'
,
'transactionStatus'
:
'6'
,
...
@@ -255,15 +264,15 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
...
@@ -255,15 +264,15 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
}
}
payment
.
PaymentTransaction_createPayzenEvent
().
PayzenEvent_processUpdate
(
data_kw
,
True
)
payment
.
PaymentTransaction_createPayzenEvent
().
PayzenEvent_processUpdate
(
data_kw
,
True
)
def
checkAndPaySubscription
Payment
(
self
,
subscription_request
):
def
_pay
Payment
(
self
,
subscription_request
):
quantity
=
subscription_request
.
getQuantity
()
quantity
=
subscription_request
.
getQuantity
()
invoice
=
subscription_request
.
getCausalityValue
(
portal_type
=
"Sale Invoice Transaction"
)
self
.
assertEqual
(
invoice
.
getSimulationState
(),
"confirmed"
)
self
.
assertEqual
(
invoice
.
getCausalityState
(),
"building"
)
# Check Payment
# Check Payment
payment
=
self
.
_getRelatedPaymentValue
(
subscription_request
)
payment
=
self
.
_getRelatedPaymentValue
(
subscription_request
)
self
.
assertEqual
(
self
.
expected_price_currency
,
payment
.
getPriceCurrency
())
self
.
assertEqual
(
-
self
.
expected_reservation_fee
*
quantity
,
payment
.
PaymentTransaction_getTotalPayablePrice
())
self
.
assertEqual
(
payment
.
getSimulationState
(),
"started"
)
self
.
assertEqual
(
payment
.
getSimulationState
(),
"started"
)
# Pay 25 euros per VM
# Pay 25 euros per VM
...
@@ -276,6 +285,17 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
...
@@ -276,6 +285,17 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
# Payzen_processUpdate will mark payment as payed by stopping it.
# Payzen_processUpdate will mark payment as payed by stopping it.
payment
.
PaymentTransaction_createPayzenEvent
().
PayzenEvent_processUpdate
(
data_kw
,
True
)
payment
.
PaymentTransaction_createPayzenEvent
().
PayzenEvent_processUpdate
(
data_kw
,
True
)
return
payment
def
checkAndPaySubscriptionPayment
(
self
,
subscription_request
):
quantity
=
subscription_request
.
getQuantity
()
invoice
=
subscription_request
.
getCausalityValue
(
portal_type
=
"Sale Invoice Transaction"
)
self
.
assertEqual
(
invoice
.
getSimulationState
(),
"confirmed"
)
self
.
assertEqual
(
invoice
.
getCausalityState
(),
"building"
)
# Check Payment
payment
=
self
.
_payPayment
(
subscription_request
)
self
.
tic
()
self
.
tic
()
self
.
assertEqual
(
payment
.
getSimulationState
(),
"stopped"
)
self
.
assertEqual
(
payment
.
getSimulationState
(),
"stopped"
)
...
@@ -307,10 +327,10 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
...
@@ -307,10 +327,10 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
for
line
in
invoice
.
objectValues
():
for
line
in
invoice
.
objectValues
():
if
line
.
getResource
()
==
"service_module/slapos_reservation_fee"
:
if
line
.
getResource
()
==
"service_module/slapos_reservation_fee"
:
self
.
assertEqual
(
line
.
getQuantity
(),
quantity
)
self
.
assertEqual
(
line
.
getQuantity
(),
quantity
)
self
.
assertEqual
(
round
(
line
.
getPrice
(),
2
),
20.83
)
self
.
assertEqual
(
round
(
line
.
getPrice
(),
2
),
self
.
expected_reservation_fee_without_tax
)
if
line
.
getResource
()
==
"service_module/slapos_tax"
:
if
line
.
getResource
()
==
"service_module/slapos_tax"
:
self
.
assertEqual
(
round
(
line
.
getQuantity
(),
2
),
round
(
20.833333333333333
*
quantity
,
2
))
self
.
assertEqual
(
round
(
line
.
getQuantity
(),
2
),
round
(
self
.
expected_reservation_quantity_tax
*
quantity
,
2
))
self
.
assertEqual
(
round
(
line
.
getTotalPrice
(),
2
),
round
(
4.166666666666667
*
quantity
,
2
))
self
.
assertEqual
(
round
(
line
.
getTotalPrice
(),
2
),
round
(
self
.
expected_reservation_tax
*
quantity
,
2
))
self
.
assertEqual
(
round
(
invoice
.
getTotalPrice
(),
2
),
self
.
expected_reservation_fee
*
quantity
)
self
.
assertEqual
(
round
(
invoice
.
getTotalPrice
(),
2
),
self
.
expected_reservation_fee
*
quantity
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment