Skip to content

Commit

Permalink
split data exchange steps
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonShopin committed Dec 20, 2024
1 parent bb89935 commit af42beb
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 213 deletions.
71 changes: 0 additions & 71 deletions resources/steps/aop_catalog_steps.robot

This file was deleted.

126 changes: 126 additions & 0 deletions resources/steps/api_dynamic_entity_steps.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
*** Settings ***
Resource ../common/common_api.robot

*** Keywords ***
Create api key in db
[Documentation] This keyword creates api key hash for data exchange api in the DB table spy_api_key. Key hash is static and matches env variable `dummy_api_key`.
...
... Each combination of `dummy_api_key` and `dummy_key_hash` is unique
...
### works for MariaDB and PostgreSQL ###
[Arguments] ${key_hash}=${dummy_key_hash} ${created_by}=1
Connect to Spryker DB
${hash_id}= Query select id_api_key from spy_api_key WHERE key_hash='${key_hash}';
${hash_id_length}= Get Length ${hash_id}
IF ${hash_id_length} > 0
Execute Sql String DELETE FROM spy_api_key WHERE key_hash='${key_hash}';
END
${new_id}= Get next id from table spy_api_key id_api_key
Connect to Spryker DB
IF '${db_engine}' == 'pymysql'
Execute Sql String insert into spy_api_key (id_api_key, name, key_hash, created_by) value ('${new_id}', 'autotest${random}', '${key_hash}', '${created_by}');
ELSE
Execute Sql String insert into spy_api_key (id_api_key, name, key_hash, created_by) values ('${new_id}', 'autotest${random}', '${key_hash}', '${created_by}');
END
Disconnect From Database

Delete api key from db
[Documentation] This keyword deletes api key hash for data exchange api in the DB table spy_api_key.
...
### works for MariaDB and PostgreSQL ###
[Arguments] ${key_hash}=${dummy_key_hash}
Connect to Spryker DB
${hash_id}= Query select id_api_key from spy_api_key WHERE key_hash='${key_hash}';
${hash_id_length}= Get Length ${hash_id}
IF ${hash_id_length} > 0
Execute Sql String DELETE FROM spy_api_key WHERE key_hash='${key_hash}';
END
Disconnect From Database

Delete mime_type by id_mime_type in Database:
[Documentation] This keyword deletes a mime type by id_mime_type in the DB table spy_mime_type.
... *Example:*
...
... ``Delete mime_type by id_mime_type in Database: 21``
...
[Arguments] ${id_mime_type}
Connect to Spryker DB
Execute Sql String DELETE FROM spy_mime_type WHERE id_mime_type = '${id_mime_type}';
Disconnect From Database

Find first available product via data exchange api
[Arguments] ${start_from_index}=0 ${end_index}=100
Remove Tags *
Set Tags bapi
API_test_setup
I get access token by user credentials: ${zed_admin.email}
I set Headers: Content-Type=application/json Authorization=Bearer ${token}
FOR ${index} IN RANGE ${start_from_index} ${end_index}
I send a GET request: /dynamic-entity/stock-products/${index}
${is_200}= Run Keyword And Ignore Error Response status code should be: 200
IF 'FAIL' in ${is_200} Continue For Loop
Save value to a variable: [data][is_never_out_of_stock] initial_is_never_out_of_stock
Save value to a variable: [data][quantity] initial_quantity
IF '${initial_is_never_out_of_stock}' == 'False'
IF ${initial_quantity} > 0
Save value to a variable: [data][fk_product] fk_product
Set Test Variable ${index} ${index}
Exit For Loop
ELSE
Continue For Loop
END
ELSE
Save value to a variable: [data][fk_product] fk_product
Set Test Variable ${index} ${index}
Exit For Loop
END
END
Get concrete product sku by id from DB: ${fk_product}
Make sure that concrete product is available: ${concrete_sku}
RETURN ${concrete_sku}

Make sure that concrete product is available:
[Arguments] ${sku}=${concrete_sku}
Remove Tags *
Set Tags glue
API_test_setup
I set Headers: Content-Type==application/json
I send a GET request: /concrete-products/${concrete_sku}/concrete-product-availabilities
${is_available}= Run Keyword And Ignore Error Response body parameter should be: [data][0][attributes][availability] True
IF 'FAIL' in ${is_available}
${index}= Evaluate ${index}+1
Find first available product via data exchange api ${index}
END

Product availability status should be changed on:
[Arguments] ${is_available} ${sku}=${concrete_sku} ${sleep_time}=5s ${iterations}=26
${is_available}= Convert To Title Case ${is_available}
Remove Tags *
Set Tags glue
API_test_setup
I set Headers: Content-Type==application/json
FOR ${index} IN RANGE 1 ${iterations}
I send a GET request: /concrete-products/${concrete_sku}/concrete-product-availabilities
Response status code should be: 200
${actual_availability}= Run Keyword And Ignore Error Response body parameter should be: [data][0][attributes][availability] ${is_available}
IF ${index} == ${iterations}-1
Fail Expected product availability is not reached. Check P&S
END
IF 'PASS' in ${actual_availability}
Exit For Loop
END
IF 'FAIL' in ${actual_availability}
Sleep ${sleep_time}
Continue For Loop
END

END

Restore product initial stock via data exchange api:
[Arguments] ${id_stock_product}=${index}
Remove Tags *
Set Tags bapi
API_test_setup
I get access token by user credentials: ${zed_admin.email}
I set Headers: Content-Type=application/json Authorization=Bearer ${token}
I send a PATCH request: /dynamic-entity/stock-products/${id_stock_product} {"data":{"is_never_out_of_stock":${initial_is_never_out_of_stock},"quantity":${initial_quantity}}}
126 changes: 1 addition & 125 deletions resources/steps/dynamic_entity_steps.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,6 @@ Resource ../../resources/pages/zed/zed_data_exchange_api_configurator_page.ro


*** Keywords ***
Create api key in db
[Documentation] This keyword creates api key hash for data exchange api in the DB table spy_api_key. Key hash is static and matches env varaible `dummy_api_key`.
...
... Each combination of `dummy_api_key` and `dummy_key_hash` is unique
...
### works for MariaDB and PostgreSQL ###
[Arguments] ${key_hash}=${dummy_key_hash} ${created_by}=1
Connect to Spryker DB
${hash_id}= Query select id_api_key from spy_api_key WHERE key_hash='${key_hash}';
${hash_id_length}= Get Length ${hash_id}
IF ${hash_id_length} > 0
Execute Sql String DELETE FROM spy_api_key WHERE key_hash='${key_hash}';
END
${new_id}= Get next id from table spy_api_key id_api_key
Connect to Spryker DB
IF '${db_engine}' == 'pymysql'
Execute Sql String insert into spy_api_key (id_api_key, name, key_hash, created_by) value ('${new_id}', 'autotest${random}', '${key_hash}', '${created_by}');
ELSE
Execute Sql String insert into spy_api_key (id_api_key, name, key_hash, created_by) values ('${new_id}', 'autotest${random}', '${key_hash}', '${created_by}');
END
Disconnect From Database

Delete api key from db
[Documentation] This keyword deletes api key hash for data exchange api in the DB table spy_api_key.
...
### works for MariaDB and PostgreSQL ###
[Arguments] ${key_hash}=${dummy_key_hash}
Connect to Spryker DB
${hash_id}= Query select id_api_key from spy_api_key WHERE key_hash='${key_hash}';
${hash_id_length}= Get Length ${hash_id}
IF ${hash_id_length} > 0
Execute Sql String DELETE FROM spy_api_key WHERE key_hash='${key_hash}';
END
Disconnect From Database

Zed: start creation of new data exchange api configuration for db table:
[Arguments] ${table_name}
Zed: go to first navigation item level: Data Exchange API Configuration
Expand Down Expand Up @@ -92,17 +57,6 @@ Zed: save data exchange api configuration
Page Should Not Contain Element ${zed_error_message} 1s
Page Should Not Contain Element ${zed_error_flash_message} 1s

Delete mime_type by id_mime_type in Database:
[Documentation] This keyword deletes a mime type by id_mime_type in the DB table spy_mime_type.
... *Example:*
...
... ``Delete mime_type by id_mime_type in Database: 21``
...
[Arguments] ${id_mime_type}
Connect to Spryker DB
Execute Sql String DELETE FROM spy_mime_type WHERE id_mime_type = '${id_mime_type}';
Disconnect From Database

Zed: download data exchange api specification should be active:
[Arguments] ${expected_condition}
${currentURL}= Get Location
Expand Down Expand Up @@ -135,87 +89,9 @@ Zed: check that downloaded api specification does not contain:
${file_content}= Get File ${specification_file_path}
Should Not Contain ${file_content} ${expected_content}

Zed: delete dowloaded api specification
Zed: delete downloaded api specification
Remove File ${specification_file_path}

Zed: wait until info box is not displayed
[Arguments] ${iterations}=20 ${delays}=10
Try reloading page until element is/not appear: ${zed_info_flash_message} false tries=${iterations} timeout=${delays} message='Download API Specification' button is disabled. Check "Trigger API specification update" CLI command results

Find first available product via data exchange api
[Arguments] ${start_from_index}=0 ${end_index}=100
Remove Tags *
Set Tags bapi
API_test_setup
I get access token by user credentials: ${zed_admin.email}
I set Headers: Content-Type=application/json Authorization=Bearer ${token}
FOR ${index} IN RANGE ${start_from_index} ${end_index}
I send a GET request: /dynamic-entity/stock-products/${index}
${is_200}= Run Keyword And Ignore Error Response status code should be: 200
IF 'FAIL' in ${is_200} Continue For Loop
Save value to a variable: [data][is_never_out_of_stock] initial_is_never_out_of_stock
Save value to a variable: [data][quantity] initial_quantity
IF '${initial_is_never_out_of_stock}' == 'False'
IF ${initial_quantity} > 0
Save value to a variable: [data][fk_product] fk_product
Set Test Variable ${index} ${index}
Exit For Loop
ELSE
Continue For Loop
END
ELSE
Save value to a variable: [data][fk_product] fk_product
Set Test Variable ${index} ${index}
Exit For Loop
END
END
Get concrete product sku by id from DB: ${fk_product}
Make sure that concrete product is available: ${concrete_sku}
RETURN ${concrete_sku}

Make sure that concrete product is available:
[Arguments] ${sku}=${concrete_sku}
Remove Tags *
Set Tags glue
API_test_setup
I set Headers: Content-Type==application/json
I send a GET request: /concrete-products/${concrete_sku}/concrete-product-availabilities
${is_avaialbe}= Run Keyword And Ignore Error Response body parameter should be: [data][0][attributes][availability] True
IF 'FAIL' in ${is_avaialbe}
${index}= Evaluate ${index}+1
Find first available product via data exchange api ${index}
END

Product availability status should be changed on:
[Arguments] ${is_available} ${sku}=${concrete_sku} ${sleep_time}=5s ${iterations}=26
${is_available}= Convert To Title Case ${is_available}
Remove Tags *
Set Tags glue
API_test_setup
I set Headers: Content-Type==application/json
FOR ${index} IN RANGE 1 ${iterations}
I send a GET request: /concrete-products/${concrete_sku}/concrete-product-availabilities
Response status code should be: 200
${actual_availability}= Run Keyword And Ignore Error Response body parameter should be: [data][0][attributes][availability] ${is_available}
IF ${index} == ${iterations}-1
Fail Expected product availability is not reached. Check P&S
END
IF 'PASS' in ${actual_availability}
Exit For Loop
END
IF 'FAIL' in ${actual_availability}
Sleep ${sleep_time}
Continue For Loop
END

END


Restore product initial stock via data exchange api:
[Arguments] ${id_stock_product}=${index}
Remove Tags *
Set Tags bapi
API_test_setup
I get access token by user credentials: ${zed_admin.email}
I set Headers: Content-Type=application/json Authorization=Bearer ${token}
I send a PATCH request: /dynamic-entity/stock-products/${id_stock_product} {"data":{"is_never_out_of_stock":${initial_is_never_out_of_stock},"quantity":${initial_quantity}}}
1 change: 0 additions & 1 deletion resources/steps/products_steps.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Resource ../common/common.robot
Resource ../pages/zed/zed_edit_product_page.robot
Resource ../pages/zed/zed_view_abstract_product_page.robot
Resource ../pages/zed/zed_view_concrete_product_page.robot
Resource aop_catalog_steps.robot

*** Keywords ***
Zed: discontinue the following product:
Expand Down
2 changes: 1 addition & 1 deletion tests/api/b2b/bapi/dynamic_entity/positive.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Suite Setup API_suite_setup
Test Setup API_test_setup
Resource ../../../../../resources/common/common_api.robot
Resource ../../../../../resources/steps/dynamic_entity_steps.robot
Resource ../../../../../resources/steps/api_dynamic_entity_steps.robot
Test Tags bapi

*** Test Cases ***
Expand Down
2 changes: 1 addition & 1 deletion tests/api/b2c/bapi/dynamic_entity/positive.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Suite Setup API_suite_setup
Test Setup API_test_setup
Resource ../../../../../resources/common/common_api.robot
Resource ../../../../../resources/steps/dynamic_entity_steps.robot
Resource ../../../../../resources/steps/api_dynamic_entity_steps.robot
Test Tags bapi

*** Test Cases ***
Expand Down
2 changes: 1 addition & 1 deletion tests/api/mp_b2b/bapi/dynamic_entity/positive.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Suite Setup API_suite_setup
Test Setup API_test_setup
Resource ../../../../../resources/common/common_api.robot
Resource ../../../../../resources/steps/dynamic_entity_steps.robot
Resource ../../../../../resources/steps/api_dynamic_entity_steps.robot
Test Tags bapi

*** Test Cases ***
Expand Down
2 changes: 1 addition & 1 deletion tests/api/mp_b2c/bapi/dynamic_entity/positive.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Suite Setup API_suite_setup
Test Setup API_test_setup
Resource ../../../../../resources/common/common_api.robot
Resource ../../../../../resources/steps/dynamic_entity_steps.robot
Resource ../../../../../resources/steps/api_dynamic_entity_steps.robot
Test Tags bapi

*** Test Cases ***
Expand Down
1 change: 0 additions & 1 deletion tests/api/suite/bapi/dynamic_entity/complex/positive.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Suite Setup API_suite_setup
Test Setup API_test_setup
Resource ../../../../../../resources/common/common_api.robot
Resource ../../../../../../resources/steps/dynamic_entity_steps.robot

Test Tags bapi

Expand Down
Loading

0 comments on commit af42beb

Please sign in to comment.