-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added flag to limit the number of processed messages from the source …
…queue (#4) * added parameters to enable limiting the amount ou message processed from the queue * added tests to cover the feature for limiting messages received from the queue * refactoring tests * bumping version to 0.2.1 * added clean and folders to .gitignore
- Loading branch information
1 parent
dafc57c
commit a10744e
Showing
12 changed files
with
362 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,4 +165,6 @@ fabric.properties | |
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
.idea/ | ||
.idea/ | ||
|
||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
run-tests: | ||
nosetests tests/ --with-coverage --cover-package=phoenix_letter -s | ||
clean: | ||
find . -name "*.py[co]" -o -name __pycache__ -exec rm -rf {} + | ||
|
||
update-pypi: | ||
rm -rf dist/* | ||
python setup.py sdist | ||
twine upload dist/* | ||
run-tests: clean | ||
nosetests tests/ --with-coverage --cover-package=phoenix_letter -s |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from argparse import ArgumentParser | ||
|
||
|
||
def parse_arguments(args): | ||
parser = ArgumentParser() | ||
parser.add_argument("--src", dest="source", | ||
required=True, | ||
help="Source SQS Queue Name", | ||
metavar="SOURCE_QUEUE") | ||
|
||
parser.add_argument("--dst", dest="destination", | ||
required=True, | ||
help="Destination SQS Queue Name", | ||
metavar="DESTINATION_QUEUE") | ||
|
||
parser.add_argument("--aws-keys", dest="input_keys", | ||
help="Flag that indicates you want to enter custom AWS keys.", action='store_true') | ||
|
||
parser.add_argument("--region", dest="region", default="us-east-1", | ||
required=True, | ||
help="AWS Region", | ||
metavar="REGION") | ||
|
||
parser.add_argument("--empty-receive", dest="max_empty_receives_count", default=10, | ||
help="Max number of empty receives before giving up", | ||
metavar="EMPTY_RECEIVE") | ||
|
||
parser.add_argument("--max", dest="max_messages", default=0, type=int, | ||
help="Max number of messages to process from the source queue.", | ||
metavar="N") | ||
|
||
parser.add_argument("--max-per-request", dest="max_receive_messages", default=10, type=int, choices=range(1, 11), | ||
help="Max number of messages to received from the source queue per request (this will be pass " | ||
"in the MaxNumberOfMessages param). Default: 10 (AWS API max limit)", | ||
metavar="N") | ||
|
||
return parser.parse_args(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from getpass import getpass | ||
|
||
|
||
def get_credentials(): | ||
access_key = getpass("AWS Access Key:") | ||
secret_key = getpass("AWS Secret Key:") | ||
|
||
return access_key, secret_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from enum import IntEnum | ||
|
||
|
||
class ReasonStopEnum(IntEnum): | ||
EMPTY_RECEIVED = 1, | ||
MAX_MESSAGES_RECEIVED = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.2.0' | ||
__version__ = '0.2.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import json | ||
|
||
import six | ||
|
||
from phoenix_letter.common.enums import ReasonStopEnum | ||
|
||
if six.PY2: | ||
from mock import patch | ||
else: | ||
from unittest.mock import patch | ||
|
||
from moto import mock_sqs | ||
|
||
from phoenix_letter.main import main | ||
|
||
from tests.bootstrap import BaseTestCase | ||
|
||
|
||
@mock_sqs | ||
@patch("phoenix_letter.common.credentials.getpass") | ||
class MoveMessagesWithMaxMessageLimitTestCase(BaseTestCase): | ||
|
||
def setUp(self): | ||
super(MoveMessagesWithMaxMessageLimitTestCase, self).setUp() | ||
self.args.append("--aws-keys") | ||
|
||
self.args.append("--max") | ||
self.args.append("1") | ||
|
||
self.args.append("--max-per-request") | ||
self.args.append("1") | ||
|
||
def tearDown(self): | ||
super(MoveMessagesWithMaxMessageLimitTestCase, self).tearDown() | ||
|
||
def test_move_message_without_args(self, mock_get_pass): | ||
with self.assertRaises(SystemExit) as cm: | ||
main([]) | ||
|
||
self.assertEqual(cm.exception.code, 2) | ||
|
||
def test_move_messages_empty_queue(self, mock_get_pass): | ||
mock_get_pass.side_effect = [self.access_key, self.secret_key] * 2 | ||
|
||
self._clean_queues([self.queue_a_url, self.queue_b_url]) | ||
|
||
result = main(self.args) | ||
|
||
self.assertEquals(result, ReasonStopEnum.EMPTY_RECEIVED) | ||
self.assertEqual(mock_get_pass.call_count, 2) | ||
|
||
mock_get_pass.reset_mock() | ||
|
||
def test_move_messages(self, mock_get_pass): | ||
mock_get_pass.side_effect = [self.access_key, self.secret_key] * 2 | ||
|
||
self.add_message(self.queue_a_url) | ||
self.add_message(self.queue_a_url) | ||
|
||
before_processing = self.get_number_of_message(self.queue_a_url) | ||
|
||
result = main(self.args) | ||
|
||
after_processing = self.get_number_of_message(self.queue_a_url) | ||
|
||
self.assertEquals(result, ReasonStopEnum.MAX_MESSAGES_RECEIVED) | ||
self.assertEquals(after_processing, before_processing - 1) | ||
self.assertEquals(mock_get_pass.call_count, 2) | ||
|
||
dst_message = self.sqs.receive_message(QueueUrl=self.queue_b_url, | ||
MessageAttributeNames=["All"], | ||
AttributeNames=['All'], | ||
MaxNumberOfMessages=10) | ||
|
||
self.assertIsNotNone(dst_message) | ||
self.assertIn("Messages", dst_message) | ||
self.assertTrue(len(dst_message["Messages"]) == 1) | ||
|
||
first_message = dst_message["Messages"][0] | ||
self.assertEqual(first_message["Body"], json.dumps(dict(test="This is a test"))) | ||
|
||
msg_attributes = first_message["MessageAttributes"] | ||
self.assertIn("Attribute1", msg_attributes) | ||
self.assertIn("Attribute2", msg_attributes) | ||
|
||
self.assertEqual(msg_attributes["Attribute1"]["StringValue"], "Attribute Value") | ||
self.assertEqual(msg_attributes["Attribute1"]["DataType"], "String") | ||
|
||
self.assertEqual(msg_attributes["Attribute2"]["StringValue"], "Attribute 2 Value") | ||
self.assertEqual(msg_attributes["Attribute2"]["DataType"], "String") | ||
mock_get_pass.reset_mock() |
Oops, something went wrong.