Skip to content

Commit

Permalink
Merge branch 'main' into IDP-1296-publish-scenarios-report
Browse files Browse the repository at this point in the history
  • Loading branch information
TommasoLencioni authored Oct 26, 2023
2 parents 24bdddc + 18400d1 commit 3a2a5bb
Show file tree
Hide file tree
Showing 18 changed files with 936 additions and 632 deletions.
12 changes: 6 additions & 6 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ name = "pypi"
attrs = "==23.1.0"
behave = "==1.2.6"
certifi = "==2023.7.22"
charset-normalizer = "==3.3.0"
charset-normalizer = "==3.3.1"
dynaconf = "==3.2.3"
faker = "==19.8.0"
faker = "==19.12.0"
idna = "==3.4"
iniconfig = "==2.0.0"
iso3166 = "==2.1.1"
packaging = "==23.2"
pluggy = "==1.3.0"
pycountry = "==22.3.5"
pipenv = "==2023.10.3"
pytest = "==7.4.2"
pipenv = "==2023.10.24"
pytest = "==7.4.3"
python-dateutil = "==2.8.2"
python-gnupg = "==0.5.1"
pytz = "==2023.3"
Expand All @@ -31,9 +31,9 @@ pandas = "==2.1.1"
parse = "==1.19.1"
parse-type = "==0.6.2"
regex = "==2023.10.3"
virtualenv = "==20.24.5"
virtualenv = "==20.24.6"
virtualenv-clone = "==0.5.7"
numpy = "==1.26.0"
numpy = "==1.26.1"
exceptiongroup = "==1.1.3"

[dev-packages]
Expand Down
1,096 changes: 544 additions & 552 deletions Pipfile.lock

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions api/idpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,19 @@ def get_ranking_file(selfcare_token: str, initiative_id: str, ranking_file_path:
return res


def get_ranking_page(selfcare_token: str,
initiative_id: str,
page: int = 0):
res = requests.get(
url=f'{settings.base_path.IO}{settings.IDPAY.domain}/initiative/{initiative_id}/ranking/exports?page={page}',
headers={
'Authorization': f'Bearer {selfcare_token}',
},
timeout=settings.default_timeout
)
return res


def put_publish_ranking(selfcare_token: str, initiative_id: str):
res = requests.put(
url=f'{settings.base_path.IO}{settings.IDPAY.domain}/initiative/{initiative_id}/ranking/notified',
Expand Down Expand Up @@ -606,3 +619,20 @@ def put_payment_results(selfcare_token: str,
data=results_file,
timeout=settings.default_timeout
)


def get_initiative_info(selfcare_token: str,
initiative_id: str):
"""API to get information related to an initiative.
:param selfcare_token: token SelfCare.
:param initiative_id: ID of the initiative of interest.
:returns: the response of the call.
:rtype: requests.Response
"""
return requests.get(
f'{settings.base_path.IO}{settings.IDPAY.domain}/initiative/{initiative_id}',
headers={
'Authorization': f'Bearer {selfcare_token}',
'Content-Type': 'application/json',
},
timeout=settings.default_timeout)
14 changes: 14 additions & 0 deletions bdd/features/pilot/pilot_suspension.feature
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,17 @@ Feature: Suspension
When the citizen B tries to accept terms and conditions
Then the latest accept terms and conditions failed for budget terminated
And the onboard of B is KO

Scenario: A transaction can still be authorized even if a suspended citizen tried to pre-authorize it
Given the initiative is "Scontoditipo1"
And the random merchant 1 is onboard
And the citizen A is 25 years old at most
And the citizen A is onboard
And the citizen B is 25 years old at most
And the citizen B is onboard
And the institution suspends correctly the citizen A
And the merchant 1 generates the transaction X of amount 100 cents
And the citizen A tries to pre-authorize the transaction X
When the citizen B confirms the transaction X
Then the transaction X is authorized
And the citizen B is rewarded with 1 euros
27 changes: 10 additions & 17 deletions bdd/features/pilot/pilot_transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,6 @@ Feature: Transaction
When the merchant 1 tries to generate the transaction X of amount -1 cents through MIL
Then the transaction X is not created for invalid amount

Scenario: Against two transactions generated by the same merchant the citizen, who confirms the first will receive error when confirming the second transaction
Given the random merchant 1 is onboard
And the citizen A is onboard
And the merchant 1 generates the transaction X of amount 10000 cents
And the merchant 1 generates the transaction Y of amount 20000 cents
When the citizen A tries to confirm the transaction X
Then the transaction Y is created

@MIL
Scenario: Against two transactions generated by the same merchant through MIL the citizen, who confirms the first will receive error when confirming the second transaction
Given the random merchant 1 is onboard
And the citizen A is onboard
And the merchant 1 generates the transaction X of amount 10000 cents through MIL
And the merchant 1 generates the transaction Y of amount 20000 cents through MIL
When the citizen A tries to confirm the transaction X
Then the transaction Y is created

Scenario: With two transactions generated by two merchants for the citizen to the confirmation of a transaction that erodes the budget to the second authorization receives error
Given the random merchant 1 is onboard
And the random merchant 2 is onboard
Expand Down Expand Up @@ -401,6 +384,16 @@ Feature: Transaction
When the citizen B tries to confirm the transaction X
Then the transaction X is already assigned

Scenario: A citizen can pre-authorize two transactions of maximum amount at the same time
Given the random merchant 1 is onboard
And the citizen A is onboard
And the merchant 1 generates the transaction X of amount 30000 cents
And the merchant 1 generates the transaction Y of amount 30000 cents
When the citizen A pre-authorizes the transaction X
And the citizen A pre-authorizes the transaction Y
Then the transaction X is identified
Then the transaction Y is identified

Scenario: If citizen A pre-authorizes the transactions X and Y, and the transaction X is authorized eroding A's budget, A receives an error upon authorizing the transaction Y
Given the random merchant 1 is onboard
And the citizen A is onboard
Expand Down
42 changes: 2 additions & 40 deletions bdd/features/ranking/onboarding.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@ranking_initiative
@ranking
@onboarding
Feature: A citizen onboards an initiative with ranking

Background:
Expand Down Expand Up @@ -64,40 +65,15 @@ Feature: A citizen onboards an initiative with ranking
| citizens |
| ["A", "B", "C"] |

@unsubscribe
Scenario: Onboard citizen cannot unsubscribe before ranking
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the citizen A onboards and waits for ranking
When the citizen A tries to unsubscribe
Then the latest unsubscribe is KO because the initiative has not started yet
And the citizen A is onboard and waits for ranking

@suspension
Scenario: The Institution cannot suspend an onboard citizen before ranking
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the citizen A onboards and waits for ranking
When the institution tries to suspend the citizen A
Then the latest suspension fails not finding the citizen

@skip
Scenario: A citizen receives KO if it tries to onboard during grace period
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the ranking period ends
And the institution publishes the ranking
And the ranking is produced
When the citizen A tries to onboard
Then the onboard of A is KO

@suspension
Scenario: The Institution tries to suspend an onboard citizen during grace period and receives an KO result
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the citizen A onboards and waits for ranking
When the institution tries to suspend the citizen A
Then the latest suspension fails not finding the citizen

@budget
Scenario Outline: Citizen, with worse criteria then other citizens, is not in ranking for budget exhaustion even if it onboards first
Given citizens <citizens> have fiscal code random
Expand All @@ -111,20 +87,6 @@ Feature: A citizen onboards an initiative with ranking
And <eligible citizens> are ranked in the correct order
And the citizen F is not eligible


Examples: Citizens and ranking order
| citizens | eligible citizens |
| ["A", "B", "C", "D", "E", "F"] | ["A", "B", "C", "D", "E"] |

Scenario: The merchant cannot generate a transaction during the onboarding period
Given the random merchant 1 is onboard
When the merchant 1 tries to generate the transaction X of amount 30000 cents
Then the transaction X is not created because it is out of valid period

@skip
Scenario: The merchant can generate a transaction after the publication of the ranking
Given the random merchant 1 is onboard
And the ranking period ends
And the institution publishes the ranking
When the merchant 1 generates the transaction X of amount 30000 cents
Then the transaction X is created
23 changes: 23 additions & 0 deletions bdd/features/ranking/suspension.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@ranking_initiative
@ranking
@suspension
Feature: A citizen onboards an initiative with ranking

Background:
Given a new initiative "ranking_initiative"

Scenario: The Institution cannot suspend a citizen before onboarding period end
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the citizen A onboards and waits for ranking
When the institution tries to suspend the citizen A
Then the latest suspension fails not finding the citizen

Scenario: The Institution cannot suspend a citizen during grace period before ranking publication
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the citizen A onboards and waits for ranking
And the ranking period ends
And the ranking is produced
When the institution tries to suspend the citizen A
Then the latest suspension fails not finding the citizen
88 changes: 88 additions & 0 deletions bdd/features/ranking/transaction.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
@ranking_initiative
@ranking
@transaction
Feature: A merchant creates a transaction and a citizen tries to confirm it during grace period on an initiative with ranking

@skip
Scenario: A new ranking initiative is generate in order to create the conditions to test grace period after ranking publication
Given a new initiative "Ranking_in_grace_period"
And the citizen A has fiscal code random
And the citizen B has fiscal code random
And the citizen C has fiscal code random
And the citizen A has ISEE 19999 of type "ordinario"
And the citizen C has ISEE 29999 of type "ordinario"
And the citizen B has ISEE 59999 of type "ordinario"
When the citizen A tries to onboard
And the citizen B tries to onboard
And the citizen C tries to onboard
And the ranking period ends
And the institution publishes the ranking

@skip
Scenario: A new ranking initiative is generate in order to create the conditions to test fruition period
Given a new initiative "Ranking_fruition_open"
And the citizen A has fiscal code random
And the citizen B has fiscal code random
And the citizen C has fiscal code random
And the citizen A has ISEE 19999 of type "ordinario"
And the citizen C has ISEE 29999 of type "ordinario"
And the citizen B has ISEE 59999 of type "ordinario"
When the citizen A tries to onboard
And the citizen B tries to onboard
And the citizen C tries to onboard
And the ranking period ends
And the institution publishes the ranking

Scenario: The merchant cannot generate a transaction during the onboarding period
Given a new initiative "ranking_initiative"
And the random merchant 1 is onboard
When the merchant 1 tries to generate the transaction X of amount 30000 cents
Then the transaction X is not created because it is out of valid period

Scenario: A merchant cannot generate a transaction during the grace period
Given the initiative is "Ranking_in_grace_period"
And the random merchant 1 is onboard
And the ranking period ends
And the ranking is produced
When the merchant 1 tries to generate the transaction X of amount 30000 cents
Then the transaction X is not created because it is out of valid period

@skip
Scenario: The merchant can generate a transaction after the publication of the ranking
Given the initiative is "Ranking_fruition_open"
And the initiative is in fruition period
And the initiative has a rank
And the random merchant 1 is onboard
When the merchant 1 generates the transaction X of amount 100 cents
Then the transaction X is created

@skip
Scenario: An elected citizen authorizes a transaction during the fruition period after ranking publication
Given the initiative is "Ranking_fruition_open"
And the initiative is in fruition period
And the initiative has a rank
And the random merchant 1 is onboard
And the merchant 1 generates the transaction X of amount 1 cents
When the elected citizen confirms the transaction x
Then the transaction X is authorized
And the citizen A is rewarded with 0.01 euros

@skip
Scenario: An unelected citizen cannot authorize a transaction during the fruition period after ranking publication
Given the initiative is "Ranking_fruition_open"
And the initiative is in fruition period
And the initiative has a rank
And the random merchant 1 is onboard
And the merchant 1 generates the transaction X of amount 1 cents
When the unelected citizen tries to pre-authorize the transaction X
Then the latest pre-authorization fails because the citizen is not onboard

@skip
Scenario: A not eligible citizen cannot authorize a transaction during the fruition period after ranking publication
Given the initiative is "Ranking_fruition_open"
And the initiative is in fruition period
And the initiative has a rank
And the random merchant 1 is onboard
And the merchant 1 generates the transaction X of amount 1 cents
When the not eligible citizen tries to pre-authorize the transaction X
Then the latest pre-authorization fails because the citizen is not onboard
25 changes: 25 additions & 0 deletions bdd/features/ranking/unsubscribe.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@ranking_initiative
@ranking
@unsubscribe
Feature: A citizen onboards an initiative with ranking

Background:
Given a new initiative "ranking_initiative"

Scenario: Onboard citizen cannot unsubscribe before onboarding period end
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the citizen A onboards and waits for ranking
When the citizen A tries to unsubscribe
Then the latest unsubscribe is KO because the initiative has not started yet
And the citizen A is onboard and waits for ranking

Scenario: Onboard citizen cannot unsubscribe during the grace period before ranking publish
Given the citizen A has fiscal code random
And the citizen A has ISEE 40000 of type "ordinario"
And the citizen A onboards and waits for ranking
And the ranking period ends
And the ranking is produced
When the citizen A tries to unsubscribe
Then the latest unsubscribe is KO because the initiative has not started yet
And the citizen A is onboard and waits for ranking to be published
19 changes: 18 additions & 1 deletion bdd/steps/discount_transaction_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def step_when_citizen_confirms_transaction(context, citizen_name, trx_name):

retry_timeline(expected=timeline_operations.transaction, request=timeline,
num_required=context.trxs_per_citizen[citizen_name], token=curr_token_io,
initiative_id=context.initiative_id, field='operationType', tries=10, delay=3,
initiative_id=context.initiative_id, field='operationType', tries=60, delay=1,
message='Transaction not received')

check_unprocessed_transactions(initiative_id=context.initiative_id,
Expand Down Expand Up @@ -583,6 +583,23 @@ def step_citizen_tries_to_cancel_a_transaction(context, citizen_name, trx_name):
context.latest_citizen_cancellation_response = res


@when('the elected citizen confirms the transaction {trx_name}')
def step_when_onboard_citizen_confirms_transaction(context, trx_name):
step_when_citizen_confirms_transaction(context=context, citizen_name=context.eligible_citizen, trx_name=trx_name)


@when('the unelected citizen tries to pre-authorize the transaction {trx_name}')
def step_when_onboard_citizen_confirms_transaction(context, trx_name):
step_citizen_only_pre_authorize_transaction(context=context, citizen_name=context.not_eligible_citizen,
trx_name=trx_name)


@when('the not eligible citizen tries to pre-authorize the transaction {trx_name}')
def step_when_onboard_citizen_confirms_transaction(context, trx_name):
step_citizen_only_pre_authorize_transaction(context=context, citizen_name=context.not_onboard_citizen,
trx_name=trx_name)


def update_user_counters(context, citizen_name, reward):
if citizen_name not in context.accrued_per_citizen.keys():
context.accrued_per_citizen[citizen_name] = reward
Expand Down
Loading

0 comments on commit 3a2a5bb

Please sign in to comment.