From eaa5121c7256856293309ad8010df97d5523f6e1 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Sat, 17 Aug 2024 15:12:07 +0100 Subject: [PATCH 01/38] testing --- src/AWSLibrary/keywords/cloudWatch.py | 4 ++-- tests/robot/testsuites/SqsTests/SampleTests.robot | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/AWSLibrary/keywords/cloudWatch.py b/src/AWSLibrary/keywords/cloudWatch.py index 1f4a162..8fb842a 100644 --- a/src/AWSLibrary/keywords/cloudWatch.py +++ b/src/AWSLibrary/keywords/cloudWatch.py @@ -108,8 +108,8 @@ def wait_for_logs(self, log_group, filter_pattern, regex_pattern, seconds_behind *Examples:* | ${logs} | CloudWatch Wait For Logs | /aws/group_name | {$.foo.bar = id_value} | 2024.*filename | - | ${logs} | CloudWatch Wait For Logs | /aws/group_name | INFO | \\\d+.*id_code | timeout=60 | - | ${logs} | CloudWatch Wait For Logs | /aws/group_name | " " | \\\w+.*some_code | not_found_fail=${True} | + | ${logs} | CloudWatch Wait For Logs | /aws/group_name | INFO | code.*id_code | timeout=60 | + | ${logs} | CloudWatch Wait For Logs | /aws/group_name | " " | code.*some_code | not_found_fail=${True} | """ client = self.library.session.client('logs', endpoint_url=self.endpoint_url) stream_response = client.describe_log_streams(logGroupName=log_group, diff --git a/tests/robot/testsuites/SqsTests/SampleTests.robot b/tests/robot/testsuites/SqsTests/SampleTests.robot index f079568..d47aeb0 100644 --- a/tests/robot/testsuites/SqsTests/SampleTests.robot +++ b/tests/robot/testsuites/SqsTests/SampleTests.robot @@ -1,7 +1,9 @@ *** Settings *** -Library AWSLibrary +Library ${CURDIR}/../../../../src/AWSLibrary +#Library AWSLibrary Library Collections -Library SeleniumLibrary +Library OperatingSystem +#Library SeleniumLibrary Suite Setup Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} Suite Teardown Delete All Sessions @@ -12,6 +14,10 @@ ${SECRET_KEY} dummy *** Test Cases *** +#test +# ${path} Normalize path ${CURDIR}/../../../../src/AWSLibrary +# Log ${path} warn +# Import Library ${path} Send and Recieve Message SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance From 1c5a9543a071d9e672cbcfb969fb756fac114ee9 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sat, 17 Aug 2024 21:21:37 +0100 Subject: [PATCH 02/38] test --- src/AWSLibrary/keywords/sqs.py | 2 +- .../testsuites/SqsTests/SampleTests.robot | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/AWSLibrary/keywords/sqs.py b/src/AWSLibrary/keywords/sqs.py index ee00086..87a2d53 100644 --- a/src/AWSLibrary/keywords/sqs.py +++ b/src/AWSLibrary/keywords/sqs.py @@ -118,4 +118,4 @@ def _get_queue_url(self, queue_name: str) -> str: if e.response['Error']['Code'] == 'AWS.SimpleQueueService.NonExistentQueue': raise Exception(f"Queue name '{queue_name}' not found.") else: - raise Exception(f"An error occurred while getting the queue URL: {e}") \ No newline at end of file + raise Exception(f"An error occurred while getting the queue URL: {e}") diff --git a/tests/robot/testsuites/SqsTests/SampleTests.robot b/tests/robot/testsuites/SqsTests/SampleTests.robot index d47aeb0..a7b524b 100644 --- a/tests/robot/testsuites/SqsTests/SampleTests.robot +++ b/tests/robot/testsuites/SqsTests/SampleTests.robot @@ -1,10 +1,8 @@ *** Settings *** Library ${CURDIR}/../../../../src/AWSLibrary -#Library AWSLibrary Library Collections Library OperatingSystem -#Library SeleniumLibrary -Suite Setup Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} +Suite Setup Suite Teardown Delete All Sessions *** Variables *** @@ -14,13 +12,8 @@ ${SECRET_KEY} dummy *** Test Cases *** -#test -# ${path} Normalize path ${CURDIR}/../../../../src/AWSLibrary -# Log ${path} warn -# Import Library ${path} - Send and Recieve Message - SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance +# SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance Send Message To SQS test-queueName Hello world! Sleep 2 ${messages} Receive Messages From SQS test-queueName @@ -30,7 +23,7 @@ Send and Recieve Message Should Be Equal ${actual_value} Hello world! Invalid Queue Name - SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance +# SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance TRY Send Message To SQS invalid-queueName Hello world! EXCEPT Queue name 'invalid-queueName' not found. @@ -38,9 +31,13 @@ Invalid Queue Name END Delete Messages - SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance +# SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance Delete All Messages In SQS test-queueName ${messages} Receive Messages From SQS test-queueName ${count} Get Length ${messages} Should Be Equal As Integers ${count} 0 +*** Keywords *** +Create Session And Set Endpoint + Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} + SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance From 69c7d2b453fc6f3a31db4b5160d1969798598ef3 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sat, 17 Aug 2024 21:26:12 +0100 Subject: [PATCH 03/38] test --- tests/robot/testsuites/SqsTests/SampleTests.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/robot/testsuites/SqsTests/SampleTests.robot b/tests/robot/testsuites/SqsTests/SampleTests.robot index a7b524b..d18077e 100644 --- a/tests/robot/testsuites/SqsTests/SampleTests.robot +++ b/tests/robot/testsuites/SqsTests/SampleTests.robot @@ -2,7 +2,7 @@ Library ${CURDIR}/../../../../src/AWSLibrary Library Collections Library OperatingSystem -Suite Setup +Suite Setup Create Session And Set Endpoint Suite Teardown Delete All Sessions *** Variables *** From 81e120ce2fb12aa204f80371cc5617eb5dcade79 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Sat, 17 Aug 2024 22:00:05 +0100 Subject: [PATCH 04/38] improve tests --- .../testsuites/SqsTests/SampleTests.robot | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/robot/testsuites/SqsTests/SampleTests.robot b/tests/robot/testsuites/SqsTests/SampleTests.robot index d18077e..911216e 100644 --- a/tests/robot/testsuites/SqsTests/SampleTests.robot +++ b/tests/robot/testsuites/SqsTests/SampleTests.robot @@ -5,38 +5,41 @@ Library OperatingSystem Suite Setup Create Session And Set Endpoint Suite Teardown Delete All Sessions + *** Variables *** ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy +${queue} test-queueName +${invalid_queue} invalid-queueName *** Test Cases *** Send and Recieve Message -# SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance - Send Message To SQS test-queueName Hello world! + Send Message To SQS ${queue} Hello world! Sleep 2 - ${messages} Receive Messages From SQS test-queueName + ${messages} Receive Messages From SQS ${queue} ${dict_message} Set Variable ${messages}[0] Dictionary Should Contain Key ${dict_message} Body ${actual_value} Get From Dictionary ${dict_message} Body Should Be Equal ${actual_value} Hello world! Invalid Queue Name -# SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance TRY - Send Message To SQS invalid-queueName Hello world! - EXCEPT Queue name 'invalid-queueName' not found. - Log caught exception + Send Message To SQS ${invalid_queue} Hello world! + EXCEPT AS ${error} + Log ${error} END + Should Be Equal ${error} Queue name '${invalid_queue}' not found. + Delete Messages -# SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance - Delete All Messages In SQS test-queueName - ${messages} Receive Messages From SQS test-queueName + Delete All Messages In SQS ${queue} + ${messages} Receive Messages From SQS ${queue} ${count} Get Length ${messages} Should Be Equal As Integers ${count} 0 + *** Keywords *** Create Session And Set Endpoint Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} From bdc5dc10d9edcbeb8e4e10fa2cdb8b3f8ed36761 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Sat, 17 Aug 2024 23:01:50 +0100 Subject: [PATCH 05/38] new format for tests --- localstack/init-aws.sh | 3 +- tests/robot/local_file.txt | 1 + tests/robot/s3.robot | 28 ++++++++++++++++++ .../SqsTests/SampleTests.robot => sqs.robot} | 1 - .../testsuites/S3Tests/AllowedMethods.robot | 16 ---------- .../testsuites/S3Tests/DownloadFile.robot | 20 ------------- .../testsuites/S3Tests/Key_Should_Exist.robot | 18 ------------ .../S3Tests/Key_Should_Not_Exist.robot | 16 ---------- .../testsuites/S3Tests/ListObjects.robot | 20 ------------- .../robot/testsuites/S3Tests/UploadFile.robot | 29 ------------------- 10 files changed, 31 insertions(+), 121 deletions(-) create mode 100644 tests/robot/local_file.txt create mode 100644 tests/robot/s3.robot rename tests/robot/{testsuites/SqsTests/SampleTests.robot => sqs.robot} (99%) delete mode 100644 tests/robot/testsuites/S3Tests/AllowedMethods.robot delete mode 100644 tests/robot/testsuites/S3Tests/DownloadFile.robot delete mode 100644 tests/robot/testsuites/S3Tests/Key_Should_Exist.robot delete mode 100644 tests/robot/testsuites/S3Tests/Key_Should_Not_Exist.robot delete mode 100644 tests/robot/testsuites/S3Tests/ListObjects.robot delete mode 100644 tests/robot/testsuites/S3Tests/UploadFile.robot diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index 4f8d0a0..0e3786e 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -2,4 +2,5 @@ # Hook file to create resources in localstack awslocal sqs create-queue --queue-name test-queueName -echo succesfully created queue \ No newline at end of file +awslocal s3api create-bucket --bucket test-bucket +echo succesfully created services diff --git a/tests/robot/local_file.txt b/tests/robot/local_file.txt new file mode 100644 index 0000000..90b4516 --- /dev/null +++ b/tests/robot/local_file.txt @@ -0,0 +1 @@ +aaaaaa diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot new file mode 100644 index 0000000..702956d --- /dev/null +++ b/tests/robot/s3.robot @@ -0,0 +1,28 @@ +*** Settings *** +Library ${CURDIR}/../../src/AWSLibrary +Library Collections +Library OperatingSystem +Suite Setup Create Session And Set Endpoint +Suite Teardown Delete All Sessions + + +*** Variables *** +${REGION} us-east-1 +${ACCESS_KEY} dummy +${SECRET_KEY} dummy + + +*** Test Cases *** +Test S3 + [Tags] s3 + ${objects} S3 List Objects test-bucket + Log ${objects} warn + S3 Upload File test-bucket s3_file.txt ${CURDIR}/local_file.txt + ${objects} S3 List Objects test-bucket + Log ${objects} warn + + +*** Keywords *** +Create Session And Set Endpoint + Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} + S3 Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance diff --git a/tests/robot/testsuites/SqsTests/SampleTests.robot b/tests/robot/sqs.robot similarity index 99% rename from tests/robot/testsuites/SqsTests/SampleTests.robot rename to tests/robot/sqs.robot index 911216e..6879288 100644 --- a/tests/robot/testsuites/SqsTests/SampleTests.robot +++ b/tests/robot/sqs.robot @@ -32,7 +32,6 @@ Invalid Queue Name END Should Be Equal ${error} Queue name '${invalid_queue}' not found. - Delete Messages Delete All Messages In SQS ${queue} ${messages} Receive Messages From SQS ${queue} diff --git a/tests/robot/testsuites/S3Tests/AllowedMethods.robot b/tests/robot/testsuites/S3Tests/AllowedMethods.robot deleted file mode 100644 index 3ceda20..0000000 --- a/tests/robot/testsuites/S3Tests/AllowedMethods.robot +++ /dev/null @@ -1,16 +0,0 @@ -*** Settings *** -Library Collections -Library AWSLibrary - - - -*** Variable *** -${REGION}= us-east-1 -${BUCKET}= zappastaticbin -${KEY}= test.html -${PATH}= downloaded_test_file.html - - -Bucket Permissions - ${CRUD}= Create List GET - Allowed Methods ${BUCKET} ${CRUD} \ No newline at end of file diff --git a/tests/robot/testsuites/S3Tests/DownloadFile.robot b/tests/robot/testsuites/S3Tests/DownloadFile.robot deleted file mode 100644 index 54f4820..0000000 --- a/tests/robot/testsuites/S3Tests/DownloadFile.robot +++ /dev/null @@ -1,20 +0,0 @@ -*** Settings *** -Library Collections -Library AWSLibrary - - - -*** Variable *** -${REGION}= us-east-1 -${BUCKET}= zappastaticbin -${KEY}= test.html -${PATH}= downloaded_test_file.html - - -*** Test Case *** -Download File - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - Upload File ${BUCKET} ${KEY} ${PATH} - Download File ${BUCKET} ${KEY} ${PATH} - Local File Should Exist ${PATH} - Delete All Sessions \ No newline at end of file diff --git a/tests/robot/testsuites/S3Tests/Key_Should_Exist.robot b/tests/robot/testsuites/S3Tests/Key_Should_Exist.robot deleted file mode 100644 index a853294..0000000 --- a/tests/robot/testsuites/S3Tests/Key_Should_Exist.robot +++ /dev/null @@ -1,18 +0,0 @@ -*** Settings *** -Library Collections -Library AWSLibrary - - - -*** Variable *** -${REGION} us-east-1 -${BUCKET} zappastaticbin -${KEY} path_test.html - - - -*** Test Case *** -Test Key Should Not Exist - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - Key Should Exist ${BUCKET} ${KEY} - Delete All Sessions diff --git a/tests/robot/testsuites/S3Tests/Key_Should_Not_Exist.robot b/tests/robot/testsuites/S3Tests/Key_Should_Not_Exist.robot deleted file mode 100644 index 45ae934..0000000 --- a/tests/robot/testsuites/S3Tests/Key_Should_Not_Exist.robot +++ /dev/null @@ -1,16 +0,0 @@ -*** Settings *** -Library Collections -Library AWSLibrary - - -*** Variable *** -${REGION} us-east-1 -${BUCKET} zappastaticbin -${KEY} fail_test.html - - -*** Test Case *** -Test Key Should Not Exist - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - Key Should Not Exist ${BUCKET} ${KEY} - Delete All Sessions diff --git a/tests/robot/testsuites/S3Tests/ListObjects.robot b/tests/robot/testsuites/S3Tests/ListObjects.robot deleted file mode 100644 index 69a2f23..0000000 --- a/tests/robot/testsuites/S3Tests/ListObjects.robot +++ /dev/null @@ -1,20 +0,0 @@ -*** Settings *** -Library Collections -Library AWSLibrary - - - -*** Variable *** -${REGION}= us-east-1 -${BUCKET}= zappastaticbin -${KEY}= test.html -${PATH}= downloaded_test_file.html - - -*** Test Case *** -List Objects - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - Upload File ${BUCKET} ${KEY} ${PATH} - ${list_of_objects}= List Objects ${BUCKET} - Should Not Be Empty ${list_of_objects} - Delete All Sessions \ No newline at end of file diff --git a/tests/robot/testsuites/S3Tests/UploadFile.robot b/tests/robot/testsuites/S3Tests/UploadFile.robot deleted file mode 100644 index b593118..0000000 --- a/tests/robot/testsuites/S3Tests/UploadFile.robot +++ /dev/null @@ -1,29 +0,0 @@ -*** Settings *** -Library Collections -Library AWSLibrary - - - -*** Variable *** -${REGION}= us-east-1 -${BUCKET}= zappastaticbin -${KEY}= test.html -${PATH}= downloaded_test_file.html -${s3FolderName}= s3FolderName - - -*** Test Case *** -Upload File - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - Upload File ${BUCKET} ${KEY} ${PATH} - Key Should Exist ${BUCKET} ${KEY} - Delete File ${BUCKET} ${KEY} - Delete All Sessions - - -** Test Cases *** -Upload file to S3 folder - ${uploadKey} Set variable ${s3FolderName}/folder_file_test.html - ${uploadpath} Set variable ${EXECDIR}/static/test.html - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - Upload File ${BUCKET} ${uploadKey} ${uploadPath} \ No newline at end of file From abdb9d499829a5a35d0338271cf4893d26962898 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 14:20:52 +0100 Subject: [PATCH 06/38] structure to keyword tests --- tests/robot/data.resource | 16 +++++++++++++ tests/robot/data/local_file.txt | 1 + tests/robot/local_file.txt | 1 - tests/robot/resources.robot | 14 ----------- tests/robot/s3.robot | 42 ++++++++++++++++++++------------- tests/robot/sqs.robot | 29 +++++++---------------- 6 files changed, 51 insertions(+), 52 deletions(-) create mode 100644 tests/robot/data.resource create mode 100644 tests/robot/data/local_file.txt delete mode 100644 tests/robot/local_file.txt delete mode 100644 tests/robot/resources.robot diff --git a/tests/robot/data.resource b/tests/robot/data.resource new file mode 100644 index 0000000..3ca3623 --- /dev/null +++ b/tests/robot/data.resource @@ -0,0 +1,16 @@ +*** Settings *** +Library ${CURDIR}/../../src/AWSLibrary +Library Collections +Library OperatingSystem + +*** Variables *** +${REGION} us-east-1 +${ACCESS_KEY} dummy +${SECRET_KEY} dummy + + +*** Keywords *** +Create Session And Set Endpoint + Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} + SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance + S3 Set Endpoint Url http://localhost:4566 # Point to localstack s3 instance diff --git a/tests/robot/data/local_file.txt b/tests/robot/data/local_file.txt new file mode 100644 index 0000000..09262da --- /dev/null +++ b/tests/robot/data/local_file.txt @@ -0,0 +1 @@ +file for robot testing. diff --git a/tests/robot/local_file.txt b/tests/robot/local_file.txt deleted file mode 100644 index 90b4516..0000000 --- a/tests/robot/local_file.txt +++ /dev/null @@ -1 +0,0 @@ -aaaaaa diff --git a/tests/robot/resources.robot b/tests/robot/resources.robot deleted file mode 100644 index 02279d6..0000000 --- a/tests/robot/resources.robot +++ /dev/null @@ -1,14 +0,0 @@ -*** Settings *** -Library AWSLibrary - - -*** Variable *** -${REGION}= us-east-1 - - -*** Keywords *** -Test Setup - Create Session With Keys ${REGION} - -Test Teardown - Delete All Sessions \ No newline at end of file diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index 702956d..366aaca 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -1,28 +1,36 @@ *** Settings *** -Library ${CURDIR}/../../src/AWSLibrary -Library Collections -Library OperatingSystem +Resource data.resource Suite Setup Create Session And Set Endpoint Suite Teardown Delete All Sessions *** Variables *** -${REGION} us-east-1 -${ACCESS_KEY} dummy -${SECRET_KEY} dummy +${BUCKET_NAME} test-bucket *** Test Cases *** -Test S3 +Test Upload And List [Tags] s3 - ${objects} S3 List Objects test-bucket - Log ${objects} warn - S3 Upload File test-bucket s3_file.txt ${CURDIR}/local_file.txt - ${objects} S3 List Objects test-bucket - Log ${objects} warn - + S3 Upload File ${BUCKET_NAME} s3_file.txt ${CURDIR}/data/local_file.txt + ${objects} S3 List Objects ${BUCKET_NAME} + Should Not Be Empty ${objects} + Should Be Equal ${objects}[0] s3_file.txt + S3 Key Should Exist ${BUCKET_NAME} s3_file.txt -*** Keywords *** -Create Session And Set Endpoint - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - S3 Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance +Test Remove + [Tags] s3 + S3 Key Should Not Exist ${BUCKET_NAME} s3_file_to_remove.txt + ${objects} S3 List Objects ${BUCKET_NAME} + Should Be Empty ${objects} + S3 Upload File ${BUCKET_NAME} s3_file_to_remove.txt ${CURDIR}/data/local_file.txt + S3 Key Should Exist ${BUCKET_NAME} s3_file_to_remove.txt + S3 Delete File ${BUCKET_NAME} s3_file_to_remove.txt + S3 Key Should Not Exist ${BUCKET_NAME} s3_file_to_remove.txt + +Test Download + [Tags] s3 + [Setup] Remove File ${OUTPUTDIR}/downloaded_file.txt + File Should Not Exist ${OUTPUTDIR}/downloaded_file.txt + S3 Upload File ${BUCKET_NAME} s3_file_to_download.txt ${CURDIR}/data/local_file.txt + S3 Download File ${BUCKET_NAME} s3_file_to_download.txt ${OUTPUTDIR}/downloaded_file.txt + File Should Exist ${OUTPUTDIR}/downloaded_file.txt diff --git a/tests/robot/sqs.robot b/tests/robot/sqs.robot index 6879288..4594900 100644 --- a/tests/robot/sqs.robot +++ b/tests/robot/sqs.robot @@ -1,24 +1,19 @@ *** Settings *** -Library ${CURDIR}/../../../../src/AWSLibrary -Library Collections -Library OperatingSystem +Resource data.resource Suite Setup Create Session And Set Endpoint Suite Teardown Delete All Sessions *** Variables *** -${REGION} us-east-1 -${ACCESS_KEY} dummy -${SECRET_KEY} dummy -${queue} test-queueName -${invalid_queue} invalid-queueName +${QUEUE_NAME} test-queueName +${INVALID_QUEUE} invalid-queueName *** Test Cases *** Send and Recieve Message - Send Message To SQS ${queue} Hello world! + Send Message To SQS ${QUEUE_NAME} Hello world! Sleep 2 - ${messages} Receive Messages From SQS ${queue} + ${messages} Receive Messages From SQS ${QUEUE_NAME} ${dict_message} Set Variable ${messages}[0] Dictionary Should Contain Key ${dict_message} Body ${actual_value} Get From Dictionary ${dict_message} Body @@ -26,20 +21,14 @@ Send and Recieve Message Invalid Queue Name TRY - Send Message To SQS ${invalid_queue} Hello world! + Send Message To SQS ${INVALID_QUEUE} Hello world! EXCEPT AS ${error} Log ${error} END - Should Be Equal ${error} Queue name '${invalid_queue}' not found. + Should Be Equal ${error} Queue name '${INVALID_QUEUE}' not found. Delete Messages - Delete All Messages In SQS ${queue} - ${messages} Receive Messages From SQS ${queue} + Delete All Messages In SQS ${QUEUE_NAME} + ${messages} Receive Messages From SQS ${QUEUE_NAME} ${count} Get Length ${messages} Should Be Equal As Integers ${count} 0 - - -*** Keywords *** -Create Session And Set Endpoint - Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance From 5db6279bbc8d618ac22e9117e7af1cb982832b34 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Sun, 18 Aug 2024 14:27:57 +0100 Subject: [PATCH 07/38] fix --- localstack/docker-compose.yml | 2 +- tests/robot/s3.robot | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/localstack/docker-compose.yml b/localstack/docker-compose.yml index b62d5f9..ce53d78 100644 --- a/localstack/docker-compose.yml +++ b/localstack/docker-compose.yml @@ -14,4 +14,4 @@ services: volumes: - './init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh' - .localstack:/var/lib/localstack - - '/var/run/docker.sock:/var/run/docker.sock' \ No newline at end of file + - '/var/run/docker.sock:/var/run/docker.sock' diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index 366aaca..7e95f17 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -20,7 +20,7 @@ Test Upload And List Test Remove [Tags] s3 S3 Key Should Not Exist ${BUCKET_NAME} s3_file_to_remove.txt - ${objects} S3 List Objects ${BUCKET_NAME} + ${objects} S3 List Objects ${BUCKET_NAME} prefix=s3_file_to_remove Should Be Empty ${objects} S3 Upload File ${BUCKET_NAME} s3_file_to_remove.txt ${CURDIR}/data/local_file.txt S3 Key Should Exist ${BUCKET_NAME} s3_file_to_remove.txt From 4c48dbe4ba538c2444421ef727742bb60c41d381 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 14:52:57 +0100 Subject: [PATCH 08/38] update s3 tests --- tests/robot/s3.robot | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index 7e95f17..7dc37ec 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -17,9 +17,9 @@ Test Upload And List Should Be Equal ${objects}[0] s3_file.txt S3 Key Should Exist ${BUCKET_NAME} s3_file.txt -Test Remove +Test Remove And List With Prefix [Tags] s3 - S3 Key Should Not Exist ${BUCKET_NAME} s3_file_to_remove.txt + [Setup] S3 Key Should Not Exist ${BUCKET_NAME} s3_file_to_remove.txt ${objects} S3 List Objects ${BUCKET_NAME} prefix=s3_file_to_remove Should Be Empty ${objects} S3 Upload File ${BUCKET_NAME} s3_file_to_remove.txt ${CURDIR}/data/local_file.txt @@ -34,3 +34,17 @@ Test Download S3 Upload File ${BUCKET_NAME} s3_file_to_download.txt ${CURDIR}/data/local_file.txt S3 Download File ${BUCKET_NAME} s3_file_to_download.txt ${OUTPUTDIR}/downloaded_file.txt File Should Exist ${OUTPUTDIR}/downloaded_file.txt + +Test Get Content + [Tags] s3 + [Setup] S3 Upload File ${BUCKET_NAME} s3_file_to_read.txt ${CURDIR}/data/local_file.txt + ${content} S3 Get File Content ${BUCKET_NAME} s3_file_to_read.txt + Should Be Equal ${content} file for robot testing. + +Test Create Bucket And Copy + [Tags] s3 + [Setup] S3 Upload File ${BUCKET_NAME} s3_file_to_copy.txt ${CURDIR}/data/local_file.txt + ${id} Evaluate random.sample(range(1111, 9999), 1) random + S3 Create Bucket new-bucket-${id} + S3 Copy Between Buckets ${BUCKET_NAME} s3_file_to_copy.txt new-bucket-${id} s3_file_copied.txt + S3 Key Should Exist new-bucket-${id} s3_file_copied.txt From ca1124f414ee6fcac36d95812ea26325096b3c23 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Sun, 18 Aug 2024 15:17:24 +0100 Subject: [PATCH 09/38] fix --- localstack/init-aws.sh | 1 + tests/robot/data/local_file.txt | 2 +- tests/robot/s3.robot | 17 ++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index 0e3786e..381faf2 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -3,4 +3,5 @@ # Hook file to create resources in localstack awslocal sqs create-queue --queue-name test-queueName awslocal s3api create-bucket --bucket test-bucket +awslocal s3api create-bucket --bucket test-bucket-2 echo succesfully created services diff --git a/tests/robot/data/local_file.txt b/tests/robot/data/local_file.txt index 09262da..ed2e578 100644 --- a/tests/robot/data/local_file.txt +++ b/tests/robot/data/local_file.txt @@ -1 +1 @@ -file for robot testing. +file for robot testing. diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index 7dc37ec..fe5f6f9 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -6,6 +6,7 @@ Suite Teardown Delete All Sessions *** Variables *** ${BUCKET_NAME} test-bucket +${BUCKET_NAME_2} test-bucket-2 *** Test Cases *** @@ -16,6 +17,7 @@ Test Upload And List Should Not Be Empty ${objects} Should Be Equal ${objects}[0] s3_file.txt S3 Key Should Exist ${BUCKET_NAME} s3_file.txt + [Teardown] S3 Delete File ${BUCKET_NAME} s3_file.txt Test Remove And List With Prefix [Tags] s3 @@ -34,17 +36,18 @@ Test Download S3 Upload File ${BUCKET_NAME} s3_file_to_download.txt ${CURDIR}/data/local_file.txt S3 Download File ${BUCKET_NAME} s3_file_to_download.txt ${OUTPUTDIR}/downloaded_file.txt File Should Exist ${OUTPUTDIR}/downloaded_file.txt + [Teardown] S3 Delete File ${BUCKET_NAME} s3_file_to_download.txt Test Get Content - [Tags] s3 + [Tags] s33 [Setup] S3 Upload File ${BUCKET_NAME} s3_file_to_read.txt ${CURDIR}/data/local_file.txt ${content} S3 Get File Content ${BUCKET_NAME} s3_file_to_read.txt - Should Be Equal ${content} file for robot testing. + Should Be Equal As Strings ${content} file for robot testing. -Test Create Bucket And Copy +Test Copy [Tags] s3 [Setup] S3 Upload File ${BUCKET_NAME} s3_file_to_copy.txt ${CURDIR}/data/local_file.txt - ${id} Evaluate random.sample(range(1111, 9999), 1) random - S3 Create Bucket new-bucket-${id} - S3 Copy Between Buckets ${BUCKET_NAME} s3_file_to_copy.txt new-bucket-${id} s3_file_copied.txt - S3 Key Should Exist new-bucket-${id} s3_file_copied.txt + S3 Copy Between Buckets ${BUCKET_NAME} s3_file_to_copy.txt ${BUCKET_NAME_2} s3_file_copied.txt + S3 Key Should Exist ${BUCKET_NAME_2} s3_file_copied.txt + [Teardown] Run Keywords S3 Delete File ${BUCKET_NAME} s3_file_to_copy.txt + ... AND S3 Delete File ${BUCKET_NAME_2} s3_file_copied.txt From 9e3daef812d9f4eaeb2b2fef1f7e543b66e6617f Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 15:18:46 +0100 Subject: [PATCH 10/38] fix txt --- tests/robot/data/local_file.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/robot/data/local_file.txt b/tests/robot/data/local_file.txt index ed2e578..43f9992 100644 --- a/tests/robot/data/local_file.txt +++ b/tests/robot/data/local_file.txt @@ -1 +1 @@ -file for robot testing. +file for robot testing. \ No newline at end of file From 8c6da5082d5ef0f81ee40c220d1f3dc1b5a8a6b5 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 15:27:08 +0100 Subject: [PATCH 11/38] More test --- tests/robot/s3.robot | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index fe5f6f9..0f705ee 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -19,6 +19,20 @@ Test Upload And List S3 Key Should Exist ${BUCKET_NAME} s3_file.txt [Teardown] S3 Delete File ${BUCKET_NAME} s3_file.txt +Test Upload And List With Folder + [Tags] s3 + S3 Upload File ${BUCKET_NAME} s3_file_no_folder.txt ${CURDIR}/data/local_file.txt + S3 Upload File ${BUCKET_NAME} new_folder/s3_file_in_folder.txt ${CURDIR}/data/local_file.txt + ${objects} S3 List Objects ${BUCKET_NAME} + Should Not Be Empty ${objects} + List Should Contain Value ${objects} s3_file_no_folder.txt + List Should Contain Value ${objects} new_folder/s3_file_in_folder.txt + ${objects_folder} S3 List Objects ${BUCKET_NAME} new_folder/ + List Should Not Contain Value ${objects_folder} s3_file_no_folder.txt + List Should Contain Value ${objects_folder} new_folder/s3_file_in_folder.txt + [Teardown] Run Keywords S3 Delete File ${BUCKET_NAME} s3_file_no_folder.txt + ... AND S3 Delete File ${BUCKET_NAME} new_folder/s3_file_in_folder.txt + Test Remove And List With Prefix [Tags] s3 [Setup] S3 Key Should Not Exist ${BUCKET_NAME} s3_file_to_remove.txt @@ -39,7 +53,7 @@ Test Download [Teardown] S3 Delete File ${BUCKET_NAME} s3_file_to_download.txt Test Get Content - [Tags] s33 + [Tags] s3 [Setup] S3 Upload File ${BUCKET_NAME} s3_file_to_read.txt ${CURDIR}/data/local_file.txt ${content} S3 Get File Content ${BUCKET_NAME} s3_file_to_read.txt Should Be Equal As Strings ${content} file for robot testing. @@ -51,3 +65,9 @@ Test Copy S3 Key Should Exist ${BUCKET_NAME_2} s3_file_copied.txt [Teardown] Run Keywords S3 Delete File ${BUCKET_NAME} s3_file_to_copy.txt ... AND S3 Delete File ${BUCKET_NAME_2} s3_file_copied.txt + +Test Metadata + [Tags] s3 + [Setup] S3 Upload File ${BUCKET_NAME} s3_file_metadata.txt ${CURDIR}/data/local_file.txt + ${metadata} S3 Get File Metadata ${BUCKET_NAME} s3_file_metadata.txt + Log ${metadata} warn From ce402591f7b9b1694f450cba9a6cf21f7a638ef9 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Sun, 18 Aug 2024 16:26:43 +0100 Subject: [PATCH 12/38] fix --- tests/robot/data/local_file.txt | 2 +- tests/robot/s3.robot | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/robot/data/local_file.txt b/tests/robot/data/local_file.txt index 43f9992..09262da 100644 --- a/tests/robot/data/local_file.txt +++ b/tests/robot/data/local_file.txt @@ -1 +1 @@ -file for robot testing. \ No newline at end of file +file for robot testing. diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index 0f705ee..a295bdc 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -57,6 +57,7 @@ Test Get Content [Setup] S3 Upload File ${BUCKET_NAME} s3_file_to_read.txt ${CURDIR}/data/local_file.txt ${content} S3 Get File Content ${BUCKET_NAME} s3_file_to_read.txt Should Be Equal As Strings ${content} file for robot testing. + [Teardown] S3 Delete File ${BUCKET_NAME} s3_file_to_read.txt Test Copy [Tags] s3 From 2051d38962bbca1409279cdfc4e10736055056f0 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 16:28:00 +0100 Subject: [PATCH 13/38] remove --- tests/robot/data/local_file.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/robot/data/local_file.txt diff --git a/tests/robot/data/local_file.txt b/tests/robot/data/local_file.txt deleted file mode 100644 index 09262da..0000000 --- a/tests/robot/data/local_file.txt +++ /dev/null @@ -1 +0,0 @@ -file for robot testing. From a6e3a32654d42d10d85034bae4018c657db390d8 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 16:28:53 +0100 Subject: [PATCH 14/38] new file --- tests/robot/data/local_file.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/robot/data/local_file.txt diff --git a/tests/robot/data/local_file.txt b/tests/robot/data/local_file.txt new file mode 100644 index 0000000..90eac5d --- /dev/null +++ b/tests/robot/data/local_file.txt @@ -0,0 +1 @@ +File for Robot Framework test \ No newline at end of file From 3bda9c4fdea653fa7e51c2e049e64744bb5eb775 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Sun, 18 Aug 2024 16:53:59 +0100 Subject: [PATCH 15/38] update metadata test --- tests/robot/s3.robot | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index a295bdc..950668f 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -56,7 +56,7 @@ Test Get Content [Tags] s3 [Setup] S3 Upload File ${BUCKET_NAME} s3_file_to_read.txt ${CURDIR}/data/local_file.txt ${content} S3 Get File Content ${BUCKET_NAME} s3_file_to_read.txt - Should Be Equal As Strings ${content} file for robot testing. + Should Be Equal As Strings ${content} File for Robot Framework test [Teardown] S3 Delete File ${BUCKET_NAME} s3_file_to_read.txt Test Copy @@ -71,4 +71,7 @@ Test Metadata [Tags] s3 [Setup] S3 Upload File ${BUCKET_NAME} s3_file_metadata.txt ${CURDIR}/data/local_file.txt ${metadata} S3 Get File Metadata ${BUCKET_NAME} s3_file_metadata.txt - Log ${metadata} warn + Dictionary Should Contain Key ${metadata} ResponseMetadata + Dictionary Should Contain Key ${metadata} Metadata + Dictionary Should Contain Key ${metadata}[ResponseMetadata] RequestId + Dictionary Should Contain Key ${metadata}[ResponseMetadata][HTTPHeaders] last-modified From fe3a7427f60ef10287f5fece5827335dc8dbb01a Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 17:04:30 +0100 Subject: [PATCH 16/38] update test and gitignore --- .gitignore | 77 -------------------------------------------- tests/robot/s3.robot | 1 + 2 files changed, 1 insertion(+), 77 deletions(-) diff --git a/.gitignore b/.gitignore index 47da5b0..c7c117c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,6 @@ __pycache__/ *.py[cod] *$py.class -# C extensions -*.so - # Distribution / packaging .Python build/ @@ -34,16 +31,6 @@ share/python-wheels/ *.egg MANIFEST -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - # Unit test / coverage reports htmlcov/ .tox/ @@ -57,52 +44,6 @@ coverage.xml .hypothesis/ .pytest_cache/ -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - # Environments .env .venv @@ -112,24 +53,6 @@ ENV/ env.bak/ venv.bak/ -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - #Pycharm .idea tests/robot/local_tests.robot diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index 950668f..02ad38f 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -75,3 +75,4 @@ Test Metadata Dictionary Should Contain Key ${metadata} Metadata Dictionary Should Contain Key ${metadata}[ResponseMetadata] RequestId Dictionary Should Contain Key ${metadata}[ResponseMetadata][HTTPHeaders] last-modified + [Teardown] S3 Delete File ${BUCKET_NAME} s3_file_metadata.txt From 789fc1905f14ffb825732908e98d48644b33e084 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 17:57:45 +0100 Subject: [PATCH 17/38] remove old files and add contributions guidelines --- .flake8 | 4 - .pre-commit-config.yaml | 9 -- .travis.yml | 25 ---- CONTRIBUTING.md | 122 ++++++------------ Dockerfile | 76 ----------- README.md | 3 - deploy-ghpages.py | 39 ------ .../robot/{data.resource => common.resource} | 1 + tests/robot/s3.robot | 2 +- tests/robot/sqs.robot | 5 +- 10 files changed, 46 insertions(+), 240 deletions(-) delete mode 100644 .flake8 delete mode 100644 .pre-commit-config.yaml delete mode 100644 .travis.yml delete mode 100644 Dockerfile delete mode 100644 deploy-ghpages.py rename tests/robot/{data.resource => common.resource} (99%) diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 98bed35..0000000 --- a/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -ignore = E203, E266, E501, W503, F403, F401, W292, E402, W391, W293 -max-line-length = 79 -max-complexity = 18 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 5da0114..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,9 +0,0 @@ -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 - hooks: - - id: check-yaml - - id: trailing-whitespace - - id: flake8 - - id: check-merge-conflict - - id: detect-aws-credentials \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index becfdef..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: python - -dist: - - "xenial" - -python: - - "3.7" - -install: - - pip install -r requirements.txt - -script: - - tox -v -e py - -after_success: - - python deploy-ghpages.py - -deploy: - provider: pypi - user: teaglebuilt - password: - secure: "lOVVg02Ipe1sSvWQG3CxOyLKnaYR7MvUXEhT7aB8DhvdA9jf2hDlKrdsYDkj6usr7nHQPvKU+k4Cayqo1cE6L1gnvpgCCdolOgXzBP6mF12+PL0eTw5U4F3J4XuOgCziZJpFARDILjR2r34t1ZgWEvv/DpXbufuIGapNumS5TMuB9sbRWReBfil8z7bepytBVoJbR20cpdhgLvL/bp79OOcKZxPlLDU0X36HkXLsBRahWDgTopfsJzPao+YD2n9NmAcKrzAxt3Xv6Es4AiTLBErdQSUAnCv0OfQTkjLTAYp6cflpK64CLUVLLqjqmWt3Hn/PjOsgvkEoc4aolQZQfCruPIwpc2M61vY/sC1egj1Hof+btBNpGO2F1UrUHHLaIX/se/XPwb9lo3tgeViNxI3Ef4o5MS3Lc7kpJnechg/y5zKn85t5dp9vEKQFirKO7l68xeuHQYdupD8/uvOAed9YsMTWOLsaY/YkXDtJFI9q8UDVvi5amEtoPvv+lWeD+FJDz7vXe8JEGvSh2+iU7j/MoG3Fru4tKdhm4+1V/qNDJqs8Sl13A8EJ0bP0L0cgNz18tfPg1PXfpUvQAF2ZQ3UHUO48qtHQ1gtdNCnsWBr4PFpHyJOQ9GzeeJVZB6eKw3+7b6668l+OTLTj6QJq128CD3zIOMNhx15G7oUll3I=" - skip_cleanup: true - on: - tags: true \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1c2f50d..ff673f9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,113 +1,71 @@ -# ***** UNDER CONSTRUCTION ***** +# Development environment + +Feel free to create issues for ideas for new functionality with other aws services We are working to create an environment with tests in localstack https://github.com/localstack/localstack if you have experience with this tool and time, any help will be appreciated. - ## Contributing to RobotFramework-AWS -Thank you for considering contributing to a library for interacting with AWS Services in RobotFramework for Test Automation. +Thank you for considering contributing to a library for interacting with AWS services in RobotFramework +for test automation. -Let's go over setting up the development environment. - -Setup virtualenvironment: +Configure your environment as desired, the requirements are in the requirements.txt file ```sh -python -m venv venv +pip install -r requirements.txt ``` -activate +## Testing -```sh -source venv/bin/activate -``` +### Localstack -install dependencies +For now, we have inside the folder localstack the docker compose file and in the init-aws.sh the commands to send +for localstack. +To start localstack just run inside localstack folder: ```sh -pip install -r requirements.txt +docker-compose up ``` +Then you can use inside robot, the endpoint http://localhost:4566 -set environment variables for aws as ACCESS_KEY and SECRET_KEY +### Robot Framework -install package development setup from root directory where setup.py is +The tests suites are inside tests/robot folder -```sh -pip install -e . -``` - -## TESTING +The common variables, keywords and libraries should be in common.resource file. The tests suites have the +aws module name like s3.robot or sqs.robot then we can run it separately. -For every keyword or method created, will be followed with two different tests. Unit and Robot tests. -Located in the tests directory are separated tests by type unit/robot. +Any extra file like txt, json, csv or similar should be inside data folder. -Robot Tests will need a configuration file added to the root of robot/ for tests to run. - -`run_arguments.robot` +The robot files should import only the common.resource. ```robotframework -## SUITE NAME ---name AWS Library Testing - -## SETTINGS -# tools must be in same directory as run_arguments.robot ---pythonpath ./AWSLibrary ---pythonpath . - -# LOG LEVEL -# --loglevel DEBUG ---loglevel INFO - -# put all logs into directory ---outputdir reports -# --timestampoutputs ---debugfile debug.log - -## VIRTUAL DISPLAY --v USE_XVFB:True - -## PROXY --v USE_PROXY:False --v PROXY_TYPE:socks --v PROXY_HOST:localhost --v PROXY_PORT:9999 - -## VARIABLES --v ACCESS_KEY: --v SECRET_KEY: - -testsuites/ -``` - -## Local AWS Services with Localstack - -```sh -docker-compose up -d - +*** Settings *** +Resource common.resource +Suite Setup Create Session And Set Endpoint +Suite Teardown Delete All Sessions ``` - +All the libraries import should be in common.resource, as the suite setup. -Make sure and add your aws credentials in the variables section. +```robotframework +*** Settings *** +Library ${CURDIR}/../../src/AWSLibrary +Library Collections +Library OperatingSystem -Unit tests and Robot Tests are automated with tox. You can run tox to test your build before committing your changes -```sh -tox +*** Keywords *** +Create Session And Set Endpoint + Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} + SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance + S3 Set Endpoint Url http://localhost:4566 # Point to localstack s3 instance ``` -Upon pushing your branch. Tox will run and travis ci will run the reports - -Tox will grab the AWS environment variables that you set. which you can see in tox.ini - -### Pre Commit - -We use flake8 for checking for linting errors +### TO-DO -Git Secrets will run on commit to make sure there are no hardcoded credentials in any files - -Upon pushing your branch. Tox will run and travis ci will run the reports - -### Issues - -Feel free to create issues for ideas for new functionality with other aws services +* Create CloudWatch and DynamoDB in localstack and create robot tests +* Add more services in library and in localstack +* Add robot tests for this new services +* Create GitHub actions to run the tests in push and merges. diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 02460bd..0000000 --- a/Dockerfile +++ /dev/null @@ -1,76 +0,0 @@ - -FROM localstack/java-maven-node-python - -# install basic tools -RUN pip install awscli awscli-local requests --upgrade -RUN apk add iputils - -# add files required to run "make install" -ADD Makefile requirements.txt ./ -RUN mkdir -p localstack/utils/kinesis/ && mkdir -p localstack/services/ && \ - touch localstack/__init__.py localstack/utils/__init__.py localstack/services/__init__.py localstack/utils/kinesis/__init__.py -ADD localstack/constants.py localstack/config.py localstack/ -ADD localstack/services/install.py localstack/services/ -ADD localstack/utils/common.py localstack/utils/bootstrap.py localstack/utils/ -ADD localstack/utils/aws/ localstack/utils/aws/ -ADD localstack/utils/kinesis/ localstack/utils/kinesis/ -ADD localstack/ext/ localstack/ext/ - -# install dependencies -RUN make install - -# add files required to run "make init" -ADD localstack/package.json localstack/package.json -ADD localstack/services/__init__.py localstack/services/install.py localstack/services/ - -# initialize installation (downloads remaining dependencies) -RUN make init - -# (re-)install web dashboard dependencies (already installed in base image) -ADD localstack/dashboard/web localstack/dashboard/web -RUN make install-web - -# install supervisor config file and entrypoint script -ADD bin/supervisord.conf /etc/supervisord.conf -ADD bin/docker-entrypoint.sh /usr/local/bin/ - -# expose service & web dashboard ports -EXPOSE 4567-4597 8080 - -# define command at startup -ENTRYPOINT ["docker-entrypoint.sh"] - -# expose default environment (required for aws-cli to work) -ENV MAVEN_CONFIG=/opt/code/localstack \ - USER=localstack \ - PYTHONUNBUFFERED=1 - -# clean up and prepare for squashing the image -RUN apk del --purge git -RUN pip uninstall -y awscli boto3 botocore localstack_client idna s3transfer -RUN rm -rf /tmp/* /root/.cache /opt/yarn-v1.15.2; mkdir -p /tmp/localstack -RUN ln -s /opt/code/localstack/.venv/bin/aws /usr/bin/aws -ENV PYTHONPATH=/opt/code/localstack/.venv/lib/python3.7/site-packages - -# add rest of the code -ADD localstack/ localstack/ -ADD bin/localstack bin/localstack - -# fix some permissions and create local user -RUN mkdir -p /.npm && \ - mkdir -p localstack/infra/elasticsearch/data && \ - mkdir -p localstack/infra/elasticsearch/logs && \ - chmod 777 . && \ - chmod 755 /root && \ - chmod -R 777 /.npm && \ - chmod -R 777 localstack/infra/elasticsearch/config && \ - chmod -R 777 localstack/infra/elasticsearch/data && \ - chmod -R 777 localstack/infra/elasticsearch/logs && \ - chmod -R 777 /tmp/localstack && \ - adduser -D localstack && \ - chown -R localstack:localstack . /tmp/localstack && \ - ln -s `pwd` /tmp/localstack_install_dir - -# run tests (to verify the build before pushing the image) -ADD tests/ tests/ -RUN LAMBDA_EXECUTOR=local make test \ No newline at end of file diff --git a/README.md b/README.md index 8dc2b77..56fe012 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,4 @@ Test Case ### Attention Contributors -The project development contribution session and local testing with "localstack" is under construction and needs to be -reviewed, contributions are welcome. - [Contribution guidelines for this project](CONTRIBUTING.md) diff --git a/deploy-ghpages.py b/deploy-ghpages.py deleted file mode 100644 index 64f4534..0000000 --- a/deploy-ghpages.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -Travis CI Script For generating libdoc for robotpageobjects.Page and publishing it -""" -from os import getenv, chdir -from re import sub -from subprocess import check_output, check_call -from tempfile import mkdtemp -from shutil import rmtree -import os - -if getenv('TRAVIS_REPO_SLUG') != 'teaglebuilt/robotframework-AWS': - print("Repo is a fork, not building docs") - exit() - -if getenv('TRAVIS_BRANCH') != 'master': - print("Branch is not master, not building docs") - exit() - -if getenv('TRAVIS_PULL_REQUEST') != 'false': - print("Pull request detected, not building docs") - exit() - -repo = check_output("git config remote.origin.url", shell=True) -repo = sub(r'^git:', 'https:', repo.decode()).strip() -deploy_url = sub(r'https://', 'https://%s@' % getenv('GIT_TOKEN'), repo) -deploy_branch = 'gh-pages' -rev = check_output("git rev-parse HEAD", shell=True).strip() -dir = mkdtemp() -check_call("git clone --branch %s %s %s" % (deploy_branch, repo, dir), shell=True) -chdir(dir) -check_call("python -m robot.libdoc -n robotframework-aws AWSLibrary index.html", shell=True) -print("Docs built successfully") -check_call("git config user.name '%s'" % getenv('GIT_NAME'), shell=True) -check_call("git config user.email '%s'" % getenv('GIT_EMAIL'), shell=True) -check_call("git commit -m 'Built from %s' index.html" % rev, shell=True) -check_call("git push -q %s %s" % (deploy_url, deploy_branch), shell=True) -chdir(getenv('TRAVIS_BUILD_DIR')) -rmtree(dir) -print("Docs pushed successfully") diff --git a/tests/robot/data.resource b/tests/robot/common.resource similarity index 99% rename from tests/robot/data.resource rename to tests/robot/common.resource index 3ca3623..142fba9 100644 --- a/tests/robot/data.resource +++ b/tests/robot/common.resource @@ -3,6 +3,7 @@ Library ${CURDIR}/../../src/AWSLibrary Library Collections Library OperatingSystem + *** Variables *** ${REGION} us-east-1 ${ACCESS_KEY} dummy diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index 02ad38f..a7a9f48 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -1,5 +1,5 @@ *** Settings *** -Resource data.resource +Resource common.resource Suite Setup Create Session And Set Endpoint Suite Teardown Delete All Sessions diff --git a/tests/robot/sqs.robot b/tests/robot/sqs.robot index 4594900..d8854c4 100644 --- a/tests/robot/sqs.robot +++ b/tests/robot/sqs.robot @@ -1,5 +1,5 @@ *** Settings *** -Resource data.resource +Resource common.resource Suite Setup Create Session And Set Endpoint Suite Teardown Delete All Sessions @@ -11,6 +11,7 @@ ${INVALID_QUEUE} invalid-queueName *** Test Cases *** Send and Recieve Message + [Tags] sqs Send Message To SQS ${QUEUE_NAME} Hello world! Sleep 2 ${messages} Receive Messages From SQS ${QUEUE_NAME} @@ -20,6 +21,7 @@ Send and Recieve Message Should Be Equal ${actual_value} Hello world! Invalid Queue Name + [Tags] sqs TRY Send Message To SQS ${INVALID_QUEUE} Hello world! EXCEPT AS ${error} @@ -28,6 +30,7 @@ Invalid Queue Name Should Be Equal ${error} Queue name '${INVALID_QUEUE}' not found. Delete Messages + [Tags] sqs Delete All Messages In SQS ${QUEUE_NAME} ${messages} Receive Messages From SQS ${QUEUE_NAME} ${count} Get Length ${messages} From e08b4ca0b749acac38b3fd17d39c6bafc52bef97 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 17:59:15 +0100 Subject: [PATCH 18/38] to-do ticks --- CONTRIBUTING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ff673f9..91f89a7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ Create Session And Set Endpoint ### TO-DO -* Create CloudWatch and DynamoDB in localstack and create robot tests -* Add more services in library and in localstack -* Add robot tests for this new services -* Create GitHub actions to run the tests in push and merges. +- [ ] Create CloudWatch and DynamoDB in localstack and create robot tests +- [ ] Add more services in library and in localstack +- [ ] Add robot tests for this new services +- [ ] Create GitHub actions to run the tests in push and merges. From a616968951e9e12073e0edc75d67e366521a9272 Mon Sep 17 00:00:00 2001 From: Samuel Cabral Date: Sun, 18 Aug 2024 18:08:55 +0100 Subject: [PATCH 19/38] more contributing guidelines --- CONTRIBUTING.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 91f89a7..180fddc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,7 +47,8 @@ Suite Setup Create Session And Set Endpoint Suite Teardown Delete All Sessions ``` -All the libraries import should be in common.resource, as the suite setup. +All the libraries import should be in common.resource, as the suite setup. The import to AWSLibrary is relative to +project source, because then you can test the new keywords or changes just running locally the tests ```robotframework *** Settings *** @@ -63,6 +64,18 @@ Create Session And Set Endpoint S3 Set Endpoint Url http://localhost:4566 # Point to localstack s3 instance ``` +To run with debug level all tests, from the main folder: +```sh +robot -d log -L TRACE tests/robot +``` + +To run just one module, like s3: +```sh +robot -d log -L TRACE tests/robot/s3.robot +# or +robot -d log -L TRACE -i s3 tests/robot +``` + ### TO-DO - [ ] Create CloudWatch and DynamoDB in localstack and create robot tests From 0950e92767e27422055f34c25edbfb38deb6448a Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Mon, 19 Aug 2024 16:48:34 +0100 Subject: [PATCH 20/38] add GATEWAY_LISTEN in localstack and improve s3 and sqs tests --- CONTRIBUTING.md | 2 +- localstack/docker-compose.yml | 1 + requirements.txt | 4 +-- src/AWSLibrary/keywords/sqs.py | 15 +++++------ tests/robot/common.resource | 7 ++--- tests/robot/sqs.robot | 21 +++++++++++---- tox.ini | 47 ---------------------------------- 7 files changed, 29 insertions(+), 68 deletions(-) delete mode 100644 tox.ini diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 180fddc..d1d7544 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,7 @@ for localstack. To start localstack just run inside localstack folder: ```sh -docker-compose up +docker-compose up -d ``` Then you can use inside robot, the endpoint http://localhost:4566 diff --git a/localstack/docker-compose.yml b/localstack/docker-compose.yml index ce53d78..1c68ce7 100644 --- a/localstack/docker-compose.yml +++ b/localstack/docker-compose.yml @@ -11,6 +11,7 @@ services: - DEBUG=1 - DOCKER_HOST=unix:///var/run/docker.sock - AWS_DEFAULT_REGION=us-east-1 + - GATEWAY_LISTEN=0.0.0.0 volumes: - './init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh' - .localstack:/var/lib/localstack diff --git a/requirements.txt b/requirements.txt index 2f01ff9..e28d6a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,3 @@ robotframework>=6.1.1 boto3>=1.34.125 -robotframework-pythonlibcore>=4.4.1 -boto3-stubs[sqs]>=1.34.125 -flake8>=7.1.1 +robotframework-pythonlibcore>=4.4.1 \ No newline at end of file diff --git a/src/AWSLibrary/keywords/sqs.py b/src/AWSLibrary/keywords/sqs.py index 87a2d53..6187be9 100644 --- a/src/AWSLibrary/keywords/sqs.py +++ b/src/AWSLibrary/keywords/sqs.py @@ -2,7 +2,6 @@ from AWSLibrary.librarycomponent import LibraryComponent from robot.api import logger from robot.api.deco import keyword -from mypy_boto3_sqs import SQSClient class SQSKeywords(LibraryComponent): @@ -38,7 +37,6 @@ def send_message_to_sqs(self, queue_name: str, message_body: str, message_attrib | Send Message To SQS | queue_name | Hello World! | *Example 2:* - | ${example_type} | Create Dictionary | StringValue | 123 | DataType | String | | ${message_attributes} | Create Dictionary | Example | ${order_type} | | Send Message To SQS | sqs_name | Hello World! | ${message_attributes} | """ @@ -46,7 +44,6 @@ def send_message_to_sqs(self, queue_name: str, message_body: str, message_attrib queue_url = self._get_queue_url(queue_name) if message_attributes is None: message_attributes = {} - try: response = sqs.send_message( QueueUrl=queue_url, @@ -59,16 +56,16 @@ def send_message_to_sqs(self, queue_name: str, message_body: str, message_attrib @keyword('Receive Messages From SQS') def receive_messages_from_sqs(self, queue_name: str, max_number: int = 10, wait_time: int = 10) -> list: - """ Recieve Messages From Queue + """ Receive Messages From Queue | =Arguments= | =Description= | | ``queue_name`` | The queue name. | - | ``max_number`` | Max number of messages to receive. | - | ``wait_time`` | Wait untill to get the messages. | + | ``max_number`` | Max number of messages to receive. Default as 10 | + | ``wait_time`` | Wait until to get the messages. Default as 10 seconds | *Example:* | ${messages_list} | Receive Messages From SQS | queue_name | - | Log List | ${messages_list} | + | ${messages_list} | Receive Messages From SQS | queue_name | max_number=20 | wait_time=30 | """ sqs = self._get_sqs_client() queue_url = self._get_queue_url(queue_name) @@ -104,8 +101,8 @@ def purge_sqs(self, queue_name: str): logger.info(f"Queue '{queue_name}' has been purged successfully.") except botocore.exceptions.ClientError as e: raise Exception(f"An error occurred while purging the queue: {e}") - - def _get_sqs_client(self) -> SQSClient: + + def _get_sqs_client(self): """Retrieve the SQS client.""" return self.library.session.client('sqs', endpoint_url=self.endpoint_url) diff --git a/tests/robot/common.resource b/tests/robot/common.resource index 142fba9..db54e27 100644 --- a/tests/robot/common.resource +++ b/tests/robot/common.resource @@ -8,10 +8,11 @@ Library OperatingSystem ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy - +#${LOCALSTACK_ENDPOINT} http://localhost:4566 +${LOCALSTACK_ENDPOINT} http://192.168.1.86:4566 *** Keywords *** Create Session And Set Endpoint Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} - SQS Set Endpoint Url http://localhost:4566 # Point to localstack sqs instance - S3 Set Endpoint Url http://localhost:4566 # Point to localstack s3 instance + SQS Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack sqs instance + S3 Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack s3 instance diff --git a/tests/robot/sqs.robot b/tests/robot/sqs.robot index d8854c4..c51741d 100644 --- a/tests/robot/sqs.robot +++ b/tests/robot/sqs.robot @@ -10,15 +10,26 @@ ${INVALID_QUEUE} invalid-queueName *** Test Cases *** -Send and Recieve Message +Send and Receive Message [Tags] sqs Send Message To SQS ${QUEUE_NAME} Hello world! - Sleep 2 ${messages} Receive Messages From SQS ${QUEUE_NAME} ${dict_message} Set Variable ${messages}[0] Dictionary Should Contain Key ${dict_message} Body ${actual_value} Get From Dictionary ${dict_message} Body Should Be Equal ${actual_value} Hello world! + [Teardown] Delete All Messages In SQS ${QUEUE_NAME} + +Send and Receive Messages + [Tags] sqs + ${messages_number} Set Variable ${5} + FOR ${index} IN RANGE 1 ${messages_number}+1 + Send Message To SQS ${QUEUE_NAME} Message 0${index} + END + ${messages} Receive Messages From SQS ${QUEUE_NAME} + ${messages_len} Get Length ${messages} + Should Be Equal As Integers ${messages_len} ${messages_number} + [Teardown] Delete All Messages In SQS ${QUEUE_NAME} Invalid Queue Name [Tags] sqs @@ -32,6 +43,6 @@ Invalid Queue Name Delete Messages [Tags] sqs Delete All Messages In SQS ${QUEUE_NAME} - ${messages} Receive Messages From SQS ${QUEUE_NAME} - ${count} Get Length ${messages} - Should Be Equal As Integers ${count} 0 + ${messages} Receive Messages From SQS ${QUEUE_NAME} wait_time=5 + ${messages_len} Get Length ${messages} + Should Be Equal As Integers ${messages_len} 0 diff --git a/tox.ini b/tox.ini deleted file mode 100644 index d010a01..0000000 --- a/tox.ini +++ /dev/null @@ -1,47 +0,0 @@ -[tox] -skipsdist = False - -[testenv:unit] -basepython = python3 -deps = - pytest - pytest-cov - coverage - coveralls - boto3 - requests - botocore -passenv = - ACCESS_KEY - SECRET_KEY - PROFILE - COVERALLS_REPO_TOKEN -usedevelop = True -commands = - coverage erase - coverage run --source=src/AWSLibrary -m pytest tests - coverage report -m - coveralls - - -[testenv:robot] -deps = - robotframework - botocore - boto3 - requests -changedir = {toxinidir}/tests/robot -commands = python -m robot -A run_arguments.robot -passenv = - ACCESS_KEY - SECRET_KEY - PROFILE - - -[testenv:flake8] -basepython = python3.7 -description = lint with flake8 -deps = - flake8 -ignore= F841,E902,F401 -commands = flake8 {posargs} flake8/ From 78cf133473161f37a3d1775120124e3296ae172f Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Mon, 19 Aug 2024 17:01:04 +0100 Subject: [PATCH 21/38] test to create dynamo table --- localstack/init-aws.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index 381faf2..7d568f5 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -4,4 +4,10 @@ awslocal sqs create-queue --queue-name test-queueName awslocal s3api create-bucket --bucket test-bucket awslocal s3api create-bucket --bucket test-bucket-2 +awslocal dynamodb create-table \ + --table-name global01 \ + --key-schema AttributeName=id,KeyType=HASH \ + --attribute-definitions AttributeName=id,AttributeType=S \ + --billing-mode PAY_PER_REQUEST \ + --region us-east-1 echo succesfully created services From 2819972e53b52cbb3a694698bddf2b40555db410 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Mon, 19 Aug 2024 18:13:49 +0100 Subject: [PATCH 22/38] add dynamo tests --- tests/robot/common.resource | 6 +++--- tests/robot/data/variables.py | 12 ++++++++++++ tests/robot/dynamo.robot | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/robot/data/variables.py create mode 100644 tests/robot/dynamo.robot diff --git a/tests/robot/common.resource b/tests/robot/common.resource index db54e27..27d92d6 100644 --- a/tests/robot/common.resource +++ b/tests/robot/common.resource @@ -2,17 +2,17 @@ Library ${CURDIR}/../../src/AWSLibrary Library Collections Library OperatingSystem - +Variables data/variables.py *** Variables *** ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy -#${LOCALSTACK_ENDPOINT} http://localhost:4566 -${LOCALSTACK_ENDPOINT} http://192.168.1.86:4566 +${LOCALSTACK_ENDPOINT} http://localhost:4566 *** Keywords *** Create Session And Set Endpoint Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} SQS Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack sqs instance S3 Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack s3 instance + Dynamo Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack s3 instance diff --git a/tests/robot/data/variables.py b/tests/robot/data/variables.py new file mode 100644 index 0000000..6065743 --- /dev/null +++ b/tests/robot/data/variables.py @@ -0,0 +1,12 @@ + +# Dummy registers for localstack DynamoDB +ITEM_CODE_01 = { + "id": "code01", + "name": "item name", + "quantity": 5, + "active": True, + "factory": { + "id": 285, + "description": "item description" + } +} diff --git a/tests/robot/dynamo.robot b/tests/robot/dynamo.robot new file mode 100644 index 0000000..34d25ba --- /dev/null +++ b/tests/robot/dynamo.robot @@ -0,0 +1,30 @@ +*** Settings *** +Resource common.resource +Suite Setup Create Session And Set Endpoint +Suite Teardown Delete All Sessions + + +*** Variables *** +${TABLE_NAME} global01 + + +*** Test Cases *** +Test Put And Query Item + [Tags] dynamo + Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} + ${result} Dynamo Query Table ${TABLE_NAME} id code01 + Should Be Equal ${result}[0] ${ITEM_CODE_01} + +Test Delete And Update Key + [Tags] dynamo + [Setup] Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} + Dynamo Remove Key ${TABLE_NAME} id code01 factory + ${result_delete} Dynamo Query Table ${TABLE_NAME} id code01 + Dictionary Should Not Contain Key ${result_delete}[0] factory + Dynamo Update Key ${TABLE_NAME} id code01 quantity ${10} + Dynamo Update Key ${TABLE_NAME} id code01 active ${False} + Dynamo Update Key ${TABLE_NAME} id code01 name new name + ${result_update} Dynamo Query Table ${TABLE_NAME} id code01 + Should Be Equal ${result_update}[0][quantity] ${10} + Should Be Equal ${result_update}[0][active] ${False} + Should Be Equal ${result_update}[0][name] new name From a73b3d5431f3049f8ed23ab57eb4342ab06266c2 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 10:26:15 +0100 Subject: [PATCH 23/38] test new table --- .gitignore | 1 + localstack/init-aws.sh | 12 +++++++++++- tests/robot/common.resource | 4 ++-- tests/robot/dynamo.robot | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c7c117c..6c52410 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ coverage.xml .venv env/ venv/ +virtual_env/ ENV/ env.bak/ venv.bak/ diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index 7d568f5..bbef737 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -5,9 +5,19 @@ awslocal sqs create-queue --queue-name test-queueName awslocal s3api create-bucket --bucket test-bucket awslocal s3api create-bucket --bucket test-bucket-2 awslocal dynamodb create-table \ - --table-name global01 \ + --table-name global \ --key-schema AttributeName=id,KeyType=HASH \ --attribute-definitions AttributeName=id,AttributeType=S \ --billing-mode PAY_PER_REQUEST \ --region us-east-1 +awslocal dynamodb create-table \ + --table-name music \ + --key-schema \ + AttributeName=Artist,KeyType=HASH \ + AttributeName=SongTitle,KeyType=HASH \ + --attribute-definitions \ + AttributeName=Artist,AttributeType=S \ + AttributeName=SongTitle,AttributeType=S \ + --billing-mode PAY_PER_REQUEST \ + --region us-east-1 echo succesfully created services diff --git a/tests/robot/common.resource b/tests/robot/common.resource index 27d92d6..79a4bb3 100644 --- a/tests/robot/common.resource +++ b/tests/robot/common.resource @@ -8,11 +8,11 @@ Variables data/variables.py ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy -${LOCALSTACK_ENDPOINT} http://localhost:4566 +${LOCALSTACK_ENDPOINT} http://192.168.1.86:4566 *** Keywords *** Create Session And Set Endpoint Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} SQS Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack sqs instance S3 Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack s3 instance - Dynamo Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack s3 instance + Dynamo Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack dynamo instance diff --git a/tests/robot/dynamo.robot b/tests/robot/dynamo.robot index 34d25ba..9dacc16 100644 --- a/tests/robot/dynamo.robot +++ b/tests/robot/dynamo.robot @@ -5,7 +5,7 @@ Suite Teardown Delete All Sessions *** Variables *** -${TABLE_NAME} global01 +${TABLE_NAME} global *** Test Cases *** From ef6ac5396b94d1c43ff0a2b5b41db01fefd80eac Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 10:36:58 +0100 Subject: [PATCH 24/38] fix --- localstack/init-aws.sh | 2 +- tests/robot/data/variables.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index bbef737..da54e78 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -14,7 +14,7 @@ awslocal dynamodb create-table \ --table-name music \ --key-schema \ AttributeName=Artist,KeyType=HASH \ - AttributeName=SongTitle,KeyType=HASH \ + AttributeName=SongTitle,KeyType=RANGE \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ diff --git a/tests/robot/data/variables.py b/tests/robot/data/variables.py index 6065743..45927fe 100644 --- a/tests/robot/data/variables.py +++ b/tests/robot/data/variables.py @@ -1,4 +1,3 @@ - # Dummy registers for localstack DynamoDB ITEM_CODE_01 = { "id": "code01", @@ -10,3 +9,21 @@ "description": "item description" } } +MUSIC_01 = { + "Artist": "Black Sabbath", + "SongTitle": "War Pigs", + "Album": "Paranoid", + "Year": 1970 +} +MUSIC_02 = { + "Artist": "Black Sabbath", + "SongTitle": "Paranoid", + "Album": "Paranoid", + "Year": 1970 +} +MUSIC_03 = { + "Artist": "Black Sabbath", + "SongTitle": "Iron Man", + "Album": "Paranoid", + "Year": 1970 +} From 7d8f7b002069951c13a89e5e7d8cb6dc61280a9f Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 13:30:58 +0100 Subject: [PATCH 25/38] update dynamo tests --- localstack/init-aws.sh | 4 +-- tests/robot/common.resource | 2 +- tests/robot/dynamo.robot | 58 ++++++++++++++++++++++++++++++++++++- tests/robot/s3.robot | 2 +- tests/robot/sqs.robot | 2 +- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index da54e78..3ca7997 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -2,10 +2,10 @@ # Hook file to create resources in localstack awslocal sqs create-queue --queue-name test-queueName -awslocal s3api create-bucket --bucket test-bucket +awslocal s3api create-bucket --bucket test-bucket-1 awslocal s3api create-bucket --bucket test-bucket-2 awslocal dynamodb create-table \ - --table-name global \ + --table-name storage \ --key-schema AttributeName=id,KeyType=HASH \ --attribute-definitions AttributeName=id,AttributeType=S \ --billing-mode PAY_PER_REQUEST \ diff --git a/tests/robot/common.resource b/tests/robot/common.resource index 79a4bb3..d4209d2 100644 --- a/tests/robot/common.resource +++ b/tests/robot/common.resource @@ -8,7 +8,7 @@ Variables data/variables.py ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy -${LOCALSTACK_ENDPOINT} http://192.168.1.86:4566 +${LOCALSTACK_ENDPOINT} http://localhost:4566 *** Keywords *** Create Session And Set Endpoint diff --git a/tests/robot/dynamo.robot b/tests/robot/dynamo.robot index 9dacc16..becace2 100644 --- a/tests/robot/dynamo.robot +++ b/tests/robot/dynamo.robot @@ -5,7 +5,8 @@ Suite Teardown Delete All Sessions *** Variables *** -${TABLE_NAME} global +${TABLE_NAME} storage +${TABLE_MUSIC} music *** Test Cases *** @@ -13,6 +14,8 @@ Test Put And Query Item [Tags] dynamo Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} ${result} Dynamo Query Table ${TABLE_NAME} id code01 + ${result_len} Get Length ${result} + Should Be Equal As Integers ${result_len} 1 Should Be Equal ${result}[0] ${ITEM_CODE_01} Test Delete And Update Key @@ -28,3 +31,56 @@ Test Delete And Update Key Should Be Equal ${result_update}[0][quantity] ${10} Should Be Equal ${result_update}[0][active] ${False} Should Be Equal ${result_update}[0][name] new name + +Test Delete Item + [Tags] dynamo + [Setup] Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} + ${result} Dynamo Query Table ${TABLE_NAME} id code01 + Should Not Be Empty ${result} + Dynamo Delete Item ${TABLE_NAME} id code01 + ${result_delete} Dynamo Query Table ${TABLE_NAME} id code01 + Should Be Empty ${result_delete} + +Test Insert New Key + [Tags] run + [Setup] Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} + ${result} Dynamo Query Table ${TABLE_NAME} id code01 + Dictionary Should Not Contain Key ${result}[0] new_code + ${new_item} Copy Dictionary ${result}[0] deepcopy=${True} + Set To Dictionary ${new_item} new_code=ABCD + Dynamo Put Item ${TABLE_NAME} ${new_item} + ${result_update} Dynamo Query Table ${TABLE_NAME} id code01 + Dictionary Should Contain Key ${result_update}[0] new_code + +Test Put And Query Item With Sort Key + [Tags] dynamo + Dynamo Put Item ${TABLE_MUSIC} ${MUSIC_01} + Dynamo Put Item ${TABLE_MUSIC} ${MUSIC_02} + Dynamo Put Item ${TABLE_MUSIC} ${MUSIC_03} + ${result_list} Dynamo Query Table ${TABLE_MUSIC} Artist Black Sabbath + ${result_len} Get Length ${result_list} + Should Be Equal As Integers ${result_len} 3 + List Should Contain Value ${result_list} ${MUSIC_01} + List Should Contain Value ${result_list} ${MUSIC_02} + List Should Contain Value ${result_list} ${MUSIC_03} + ${result} Dynamo Query Table ${TABLE_MUSIC} Artist Black Sabbath SongTitle Paranoid + ${result_len} Get Length ${result} + Should Be Equal As Integers ${result_len} 1 + Should Be Equal ${result}[0] ${MUSIC_02} + +Test Delete And Update Key With Sort Key + [Tags] dynamo + [Setup] Run Keywords Dynamo Put Item ${TABLE_MUSIC} ${MUSIC_01} + ... AND Dynamo Put Item ${TABLE_MUSIC} ${MUSIC_02} + ... AND Dynamo Put Item ${TABLE_MUSIC} ${MUSIC_03} + Dynamo Remove Key ${TABLE_MUSIC} Artist Black Sabbath Year + ... sort_key=SongTitle sort_value=War Pigs + ${result_delete} Dynamo Query Table ${TABLE_MUSIC} Artist Black Sabbath SongTitle War Pigs + Dictionary Should Not Contain Key ${result_delete}[0] Year + Dynamo Update Key ${TABLE_MUSIC} Artist Black Sabbath Year ${2012} + ... sort_key=SongTitle sort_value=Paranoid + Dynamo Update Key ${TABLE_MUSIC} Artist Black Sabbath Album Paranoid Remaster + ... sort_key=SongTitle sort_value=Paranoid + ${result_update} Dynamo Query Table ${TABLE_MUSIC} Artist Black Sabbath SongTitle Paranoid + Should Be Equal ${result_update}[0][Year] ${2012} + Should Be Equal ${result_update}[0][Album] Paranoid Remaster diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index a7a9f48..eab0228 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -5,7 +5,7 @@ Suite Teardown Delete All Sessions *** Variables *** -${BUCKET_NAME} test-bucket +${BUCKET_NAME} test-bucket-1 ${BUCKET_NAME_2} test-bucket-2 diff --git a/tests/robot/sqs.robot b/tests/robot/sqs.robot index c51741d..941290d 100644 --- a/tests/robot/sqs.robot +++ b/tests/robot/sqs.robot @@ -5,7 +5,7 @@ Suite Teardown Delete All Sessions *** Variables *** -${QUEUE_NAME} test-queueName +${QUEUE_NAME} test-queueName ${INVALID_QUEUE} invalid-queueName From a5239580e41c7ef0f8fb03b3e73e1e94de0caa36 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 14:08:15 +0100 Subject: [PATCH 26/38] Update dynamo tests --- tests/robot/dynamo.robot | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/robot/dynamo.robot b/tests/robot/dynamo.robot index becace2..f336ac9 100644 --- a/tests/robot/dynamo.robot +++ b/tests/robot/dynamo.robot @@ -32,6 +32,16 @@ Test Delete And Update Key Should Be Equal ${result_update}[0][active] ${False} Should Be Equal ${result_update}[0][name] new name +Test Delete And Update Nested Key + [Tags] dynamo + [Setup] Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} + Dynamo Remove Key ${TABLE_NAME} id code01 factory.id + ${result_delete} Dynamo Query Table ${TABLE_NAME} id code01 + Dictionary Should Not Contain Key ${result_delete}[0][factory] id + Dynamo Update Key ${TABLE_NAME} id code01 factory.description New description + ${result_update} Dynamo Query Table ${TABLE_NAME} id code01 + Should Be Equal ${result_update}[0][factory][description] New description + Test Delete Item [Tags] dynamo [Setup] Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} @@ -42,15 +52,17 @@ Test Delete Item Should Be Empty ${result_delete} Test Insert New Key - [Tags] run + [Tags] dynamo [Setup] Dynamo Put Item ${TABLE_NAME} ${ITEM_CODE_01} ${result} Dynamo Query Table ${TABLE_NAME} id code01 - Dictionary Should Not Contain Key ${result}[0] new_code + Dictionary Should Not Contain Key ${result}[0] codes_list ${new_item} Copy Dictionary ${result}[0] deepcopy=${True} - Set To Dictionary ${new_item} new_code=ABCD + ${codes_list} Create List ${10} ${22} ${19} ${16} + Set To Dictionary ${new_item} codes_list=${codes_list} Dynamo Put Item ${TABLE_NAME} ${new_item} ${result_update} Dynamo Query Table ${TABLE_NAME} id code01 - Dictionary Should Contain Key ${result_update}[0] new_code + Dictionary Should Contain Key ${result_update}[0] codes_list + Should Be Equal ${result_update}[0][codes_list] ${codes_list} Test Put And Query Item With Sort Key [Tags] dynamo From c1244ca905284f19af88cd767c0d4b2ab96a4041 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 14:28:21 +0100 Subject: [PATCH 27/38] add logs in localstack --- localstack/docker-compose.yml | 2 +- tests/robot/common.resource | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/localstack/docker-compose.yml b/localstack/docker-compose.yml index 1c68ce7..ab7acaa 100644 --- a/localstack/docker-compose.yml +++ b/localstack/docker-compose.yml @@ -7,7 +7,7 @@ services: - '4563-4599:4563-4599' - '8055:8080' environment: - - SERVICES=s3,lambda,dynamodb,rds,sqs + - SERVICES=s3,lambda,dynamodb,rds,sqs,logs - DEBUG=1 - DOCKER_HOST=unix:///var/run/docker.sock - AWS_DEFAULT_REGION=us-east-1 diff --git a/tests/robot/common.resource b/tests/robot/common.resource index d4209d2..97f0818 100644 --- a/tests/robot/common.resource +++ b/tests/robot/common.resource @@ -4,12 +4,14 @@ Library Collections Library OperatingSystem Variables data/variables.py + *** Variables *** ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy ${LOCALSTACK_ENDPOINT} http://localhost:4566 + *** Keywords *** Create Session And Set Endpoint Create Session With Keys ${REGION} ${ACCESS_KEY} ${SECRET_KEY} From e905934e9f73edd71b60db7a0c219d1f2e165315 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 16:34:12 +0100 Subject: [PATCH 28/38] add cloudwatch tests --- localstack/init-aws.sh | 4 ++++ src/AWSLibrary/keywords/cloudWatch.py | 3 ++- tests/robot/cloudwatch.robot | 24 ++++++++++++++++++++++++ tests/robot/common.resource | 5 ++++- tests/robot/data/keywords.py | 27 +++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 tests/robot/cloudwatch.robot create mode 100644 tests/robot/data/keywords.py diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index 3ca7997..0cc67f8 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -20,4 +20,8 @@ awslocal dynamodb create-table \ AttributeName=SongTitle,AttributeType=S \ --billing-mode PAY_PER_REQUEST \ --region us-east-1 +awslocal awslocal logs create-log-group --log-group-name test +awslocal logs create-log-stream \ + --log-group-name test \ + --log-stream-name test echo succesfully created services diff --git a/src/AWSLibrary/keywords/cloudWatch.py b/src/AWSLibrary/keywords/cloudWatch.py index 8fb842a..bf52d6e 100644 --- a/src/AWSLibrary/keywords/cloudWatch.py +++ b/src/AWSLibrary/keywords/cloudWatch.py @@ -65,7 +65,8 @@ def insights_query(self, log_group, query, start_time=60): logger.debug("waiting for Logs Insights") time.sleep(0.5) response = client.get_query_results(queryId=query_id) - return response['results'] + results = [sublist[1:] for sublist in response['results']] + return results @keyword('CloudWatch Wait For Logs') def wait_for_logs(self, log_group, filter_pattern, regex_pattern, seconds_behind=60, timeout=30, diff --git a/tests/robot/cloudwatch.robot b/tests/robot/cloudwatch.robot new file mode 100644 index 0000000..21b6966 --- /dev/null +++ b/tests/robot/cloudwatch.robot @@ -0,0 +1,24 @@ +*** Settings *** +Resource common.resource +Suite Setup Create Session And Set Endpoint +Suite Teardown Delete All Sessions + + +*** Variables *** +${LOG_GROUP} test + + +*** Test Cases *** +Test Wait For Log + [Tags] cloudwatch + [Setup] keywords.Send Cloudwatch Message Hello From CloudWatch + ${logs} CloudWatch Wait For Logs ${LOG_GROUP} " " Hello timeout=10 + Should Not Be Empty ${logs} + Should Contain ${logs}[0] Hello From CloudWatch + +Test Log Insights + [Tags] cloudwatch + [Setup] keywords.Send Cloudwatch Message Hello From CloudWatch + ${logs} CloudWatch Logs Insights ${LOG_GROUP} fields @message | filter @message like 'Hello' | sort @timestamp desc | limit 10 + Should Not Be Empty ${logs} + Should Contain ${logs}[0] Hello From CloudWatch \ No newline at end of file diff --git a/tests/robot/common.resource b/tests/robot/common.resource index 97f0818..d6ffafa 100644 --- a/tests/robot/common.resource +++ b/tests/robot/common.resource @@ -2,6 +2,7 @@ Library ${CURDIR}/../../src/AWSLibrary Library Collections Library OperatingSystem +Library data/keywords.py Variables data/variables.py @@ -9,7 +10,8 @@ Variables data/variables.py ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy -${LOCALSTACK_ENDPOINT} http://localhost:4566 +#${LOCALSTACK_ENDPOINT} http://localhost:4566 +${LOCALSTACK_ENDPOINT} http://192.168.1.86:4566 *** Keywords *** @@ -18,3 +20,4 @@ Create Session And Set Endpoint SQS Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack sqs instance S3 Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack s3 instance Dynamo Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack dynamo instance + CloudWatch Set Endpoint Url ${LOCALSTACK_ENDPOINT} # Point to localstack cloudwatch instance diff --git a/tests/robot/data/keywords.py b/tests/robot/data/keywords.py new file mode 100644 index 0000000..09a65cd --- /dev/null +++ b/tests/robot/data/keywords.py @@ -0,0 +1,27 @@ +import boto3 +import time + + +endpoint = "http://192.168.1.86:4566" +LOG_GROUP = 'test' +LOG_STREAM = 'test' + + +def send_cloudwatch_message(message): + session = boto3.Session( + aws_access_key_id="dummy", + aws_secret_access_key="dummy", + region_name="us-east-1" + ) + logs = session.client('logs', endpoint_url=endpoint) + timestamp = int(round(time.time() * 1000)) + logs.put_log_events( + logGroupName=LOG_GROUP, + logStreamName=LOG_STREAM, + logEvents=[ + { + 'timestamp': timestamp, + 'message': time.strftime('%Y-%m-%d %H:%M:%S')+' %s' % message + } + ] + ) From dcdce9c4630a6568f8a8f77f7aa815cd99f906e6 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Tue, 20 Aug 2024 16:38:45 +0100 Subject: [PATCH 29/38] fix --- localstack/init-aws.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localstack/init-aws.sh b/localstack/init-aws.sh index 0cc67f8..9ab74c9 100755 --- a/localstack/init-aws.sh +++ b/localstack/init-aws.sh @@ -20,7 +20,7 @@ awslocal dynamodb create-table \ AttributeName=SongTitle,AttributeType=S \ --billing-mode PAY_PER_REQUEST \ --region us-east-1 -awslocal awslocal logs create-log-group --log-group-name test +awslocal logs create-log-group --log-group-name test awslocal logs create-log-stream \ --log-group-name test \ --log-stream-name test From 56e154b72ebe6d328637d005f7d8fc601630cb77 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 16:46:06 +0100 Subject: [PATCH 30/38] Finish version 1.0.0 tests --- src/AWSLibrary/version.py | 2 +- tests/robot/cloudwatch.robot | 6 +++--- tests/robot/common.resource | 11 +++++------ tests/robot/data/keywords.py | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/AWSLibrary/version.py b/src/AWSLibrary/version.py index 3526155..8a1ff32 100644 --- a/src/AWSLibrary/version.py +++ b/src/AWSLibrary/version.py @@ -1,4 +1,4 @@ -VERSION = '0.2.0' +VERSION = '1.0.0' def get_version(): diff --git a/tests/robot/cloudwatch.robot b/tests/robot/cloudwatch.robot index 21b6966..ce31fb2 100644 --- a/tests/robot/cloudwatch.robot +++ b/tests/robot/cloudwatch.robot @@ -12,13 +12,13 @@ ${LOG_GROUP} test Test Wait For Log [Tags] cloudwatch [Setup] keywords.Send Cloudwatch Message Hello From CloudWatch - ${logs} CloudWatch Wait For Logs ${LOG_GROUP} " " Hello timeout=10 + ${logs} CloudWatch Wait For Logs ${LOG_GROUP} " " Hello.*Watch timeout=10 Should Not Be Empty ${logs} Should Contain ${logs}[0] Hello From CloudWatch Test Log Insights [Tags] cloudwatch [Setup] keywords.Send Cloudwatch Message Hello From CloudWatch - ${logs} CloudWatch Logs Insights ${LOG_GROUP} fields @message | filter @message like 'Hello' | sort @timestamp desc | limit 10 + ${query} Set Variable fields @message | filter @message like 'Hello' | sort @timestamp desc | limit 10 + ${logs} CloudWatch Logs Insights ${LOG_GROUP} ${query} Should Not Be Empty ${logs} - Should Contain ${logs}[0] Hello From CloudWatch \ No newline at end of file diff --git a/tests/robot/common.resource b/tests/robot/common.resource index d6ffafa..833e261 100644 --- a/tests/robot/common.resource +++ b/tests/robot/common.resource @@ -1,8 +1,8 @@ *** Settings *** -Library ${CURDIR}/../../src/AWSLibrary -Library Collections -Library OperatingSystem -Library data/keywords.py +Library ${CURDIR}/../../src/AWSLibrary +Library Collections +Library OperatingSystem +Library data/keywords.py Variables data/variables.py @@ -10,8 +10,7 @@ Variables data/variables.py ${REGION} us-east-1 ${ACCESS_KEY} dummy ${SECRET_KEY} dummy -#${LOCALSTACK_ENDPOINT} http://localhost:4566 -${LOCALSTACK_ENDPOINT} http://192.168.1.86:4566 +${LOCALSTACK_ENDPOINT} http://localhost:4566 *** Keywords *** diff --git a/tests/robot/data/keywords.py b/tests/robot/data/keywords.py index 09a65cd..920761f 100644 --- a/tests/robot/data/keywords.py +++ b/tests/robot/data/keywords.py @@ -2,7 +2,7 @@ import time -endpoint = "http://192.168.1.86:4566" +endpoint = "http://localhost:4566" LOG_GROUP = 'test' LOG_STREAM = 'test' From e5e3f133904a9e1280e09c59932a009835bf1ae2 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 17:11:07 +0100 Subject: [PATCH 31/38] test github actions --- .github/workflows/run-tests.yml | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..f96cbe6 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,34 @@ +name: Run LocalStack with Docker + +on: + push: + pull_request: + +jobs: + run-localstack: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker + uses: docker/setup-buildx-action@v2 + + - name: Navigate to localstack directory + working-directory: ./localstack + run: | + docker-compose up -d + + - name: Wait for LocalStack to be ready + run: sleep 20 + + - name: Run tests or further commands + working-directory: ./localstack + run: | + echo "LocalStack is running!" + + - name: Teardown LocalStack + working-directory: ./localstack + run: | + docker-compose down \ No newline at end of file From 08aeb9db028bb7bb62f50f00641df1b5975acbbd Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 17:19:42 +0100 Subject: [PATCH 32/38] add apt-get --- .github/workflows/run-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f96cbe6..2eefb59 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,6 +15,11 @@ jobs: - name: Set up Docker uses: docker/setup-buildx-action@v2 + - name: Install Docker Compose + run: | + sudo apt-get update + sudo apt-get install docker-compose -y + - name: Navigate to localstack directory working-directory: ./localstack run: | From 3b7577241abb18c93f500712680acd056af706af Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 17:28:22 +0100 Subject: [PATCH 33/38] add robot tests --- .github/workflows/run-tests.yml | 50 ++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2eefb59..3cd1c4d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -7,33 +7,55 @@ on: jobs: run-localstack: runs-on: ubuntu-latest - steps: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Docker uses: docker/setup-buildx-action@v2 - - name: Install Docker Compose run: | sudo apt-get update sudo apt-get install docker-compose -y - - name: Navigate to localstack directory working-directory: ./localstack run: | docker-compose up -d - - name: Wait for LocalStack to be ready run: sleep 20 - - name: Run tests or further commands - working-directory: ./localstack - run: | - echo "LocalStack is running!" - - - name: Teardown LocalStack - working-directory: ./localstack - run: | - docker-compose down \ No newline at end of file + run-robot-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + env: + ROBOT_TESTS_DIR: ${{ github.workspace }}/Tests + ROBOT_REPORTS_DIR: ${{ github.workspace }}/reports + with: + python-version: '3.10' + - name: Install Dependencies + run: pip install -r requirements.txt + - name: Run Robot File + run: robot -d ./reports ./tests/robot + - name: Upload test results + uses: actions/upload-artifact@v1 + if: always() + with: + name: robot_reports + path: reports + + generate-robot-report: + if: always() + needs: [ run-robot-tests ] + runs-on: ubuntu-latest + steps: + - name: Download reports + uses: actions/download-artifact@v1 + with: + name: robot_reports + - name: Send report to commit + uses: joonvena/robotframework-reporter-action@v2.4 + with: + gh_access_token: ${{ secrets.GITHUB_TOKEN }} + report_path: /robot_reports \ No newline at end of file From f27fa29bf300b88135abf9e13c07bf5c64365dea Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 17:30:01 +0100 Subject: [PATCH 34/38] fix --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 3cd1c4d..b38a53f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -24,6 +24,7 @@ jobs: run: sleep 20 run-robot-tests: + needs: [ run-localstack ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 78c0231c18141fe8ea365f1de18ff77964a5a34b Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 17:36:00 +0100 Subject: [PATCH 35/38] fix 2 --- .github/workflows/run-tests.yml | 45 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b38a53f..9b6d547 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -5,7 +5,7 @@ on: pull_request: jobs: - run-localstack: + run-localstack-and-robot: runs-on: ubuntu-latest steps: - name: Checkout code @@ -22,33 +22,28 @@ jobs: docker-compose up -d - name: Wait for LocalStack to be ready run: sleep 20 - - run-robot-tests: - needs: [ run-localstack ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v2 - env: - ROBOT_TESTS_DIR: ${{ github.workspace }}/Tests - ROBOT_REPORTS_DIR: ${{ github.workspace }}/reports - with: - python-version: '3.10' - - name: Install Dependencies - run: pip install -r requirements.txt - - name: Run Robot File - run: robot -d ./reports ./tests/robot - - name: Upload test results - uses: actions/upload-artifact@v1 - if: always() - with: - name: robot_reports - path: reports + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + env: + ROBOT_TESTS_DIR: ${{ github.workspace }}/Tests + ROBOT_REPORTS_DIR: ${{ github.workspace }}/reports + with: + python-version: '3.10' + - name: Install Dependencies + working-directory: ./ + run: pip install -r requirements.txt + - name: Run Robot Framework + run: robot -d ./reports ./tests/robot + - name: Upload test results + uses: actions/upload-artifact@v1 + if: always() + with: + name: robot_reports + path: reports generate-robot-report: if: always() - needs: [ run-robot-tests ] + needs: [ run-localstack-and-robot ] runs-on: ubuntu-latest steps: - name: Download reports From bb4c5dff0189efabea5198f7b9a68d68c8555cec Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 18:00:20 +0100 Subject: [PATCH 36/38] update actions and fix test --- .github/workflows/run-tests.yml | 14 +++++++------- tests/robot/cloudwatch.robot | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9b6d547..0cdcda0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,4 +1,4 @@ -name: Run LocalStack with Docker +name: Run LocalStack And Execute Keyword Tests on: push: @@ -9,21 +9,21 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Install Docker Compose run: | sudo apt-get update sudo apt-get install docker-compose -y - - name: Navigate to localstack directory + - name: Start Localstack docker working-directory: ./localstack run: | docker-compose up -d - name: Wait for LocalStack to be ready - run: sleep 20 + run: sleep 10 - name: Set up Python 3.10 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 env: ROBOT_TESTS_DIR: ${{ github.workspace }}/Tests ROBOT_REPORTS_DIR: ${{ github.workspace }}/reports @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download reports - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v4 with: name: robot_reports - name: Send report to commit diff --git a/tests/robot/cloudwatch.robot b/tests/robot/cloudwatch.robot index ce31fb2..a37d716 100644 --- a/tests/robot/cloudwatch.robot +++ b/tests/robot/cloudwatch.robot @@ -19,6 +19,7 @@ Test Wait For Log Test Log Insights [Tags] cloudwatch [Setup] keywords.Send Cloudwatch Message Hello From CloudWatch + Sleep 30s #You need to wait for the log to be indexed in cloudwatch for the query to work ${query} Set Variable fields @message | filter @message like 'Hello' | sort @timestamp desc | limit 10 ${logs} CloudWatch Logs Insights ${LOG_GROUP} ${query} Should Not Be Empty ${logs} From 0cfe9271469981d750abc185925f52c3fe570375 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Tue, 20 Aug 2024 18:06:53 +0100 Subject: [PATCH 37/38] fix robot report --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0cdcda0..2b2141e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download reports - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v1 with: name: robot_reports - name: Send report to commit From 8b7eabd82d654ca2624b9b8a055e99d97dd056e1 Mon Sep 17 00:00:00 2001 From: "EMEA-MEDIA\\scabra02" Date: Wed, 21 Aug 2024 09:32:28 +0100 Subject: [PATCH 38/38] update todo list --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1d7544..ff0ec30 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,7 +78,7 @@ robot -d log -L TRACE -i s3 tests/robot ### TO-DO -- [ ] Create CloudWatch and DynamoDB in localstack and create robot tests +- [x] Create CloudWatch and DynamoDB in localstack and create robot tests +- [x] Create GitHub actions to run the tests in push and merges. - [ ] Add more services in library and in localstack - [ ] Add robot tests for this new services -- [ ] Create GitHub actions to run the tests in push and merges.