Esempio n. 1
0
 def setUpClass(cls):
     '''Method used to setup global dependencies for test cases.'''
     
     if aws_config.AWS_ACCESS_KEY == "Put your access key in here" or \
         aws_config.AWS_SECRET_KEY == "Put your secret key in here":
         raise SkipTest("This will be executed only if you provide valid AWS access / secret keys.")
     
     sqs_client = SqsClient(cls.QUEUE_REGION)
     
     cls.QUEUE_URL = sqs_client.get_queue_url(cls.QUEUE_NAME)
     
     host = aws_config.get_service_host(cls.QUEUE_REGION, cls.SERVICE)
     
     assert cls.QUEUE_URL is not None
     assert not cls.QUEUE_URL.startswith("http://%s" % host)
     assert cls.QUEUE_URL.endswith(cls.QUEUE_NAME)
Esempio n. 2
0
 def setUp(self):
     '''Method invoked automatically in order to set up all test cases dependencies.'''
     
     self._sqs_client = SqsClient(SqsClientSanityCheck.QUEUE_REGION)
Esempio n. 3
0
class SqsClientSanityCheck(unittest.TestCase):
    '''This class provides the test cases that ensure that sqs client works correctly.'''

    SERVICE = "sqs"
    QUEUE_NAME = "dmsmart-integration-tests"
    QUEUE_URL = None
    QUEUE_REGION = "eu-west-1"
    REQUEST_SIGNER = AWSRequestSignerV4(aws_config.AWS_ACCESS_KEY, aws_config.AWS_SECRET_KEY, aws_config.AWS_REGION, SERVICE) 
    
    @classmethod
    def setUpClass(cls):
        '''Method used to setup global dependencies for test cases.'''
        
        if aws_config.AWS_ACCESS_KEY == "Put your access key in here" or \
            aws_config.AWS_SECRET_KEY == "Put your secret key in here":
            raise SkipTest("This will be executed only if you provide valid AWS access / secret keys.")
        
        sqs_client = SqsClient(cls.QUEUE_REGION)
        
        cls.QUEUE_URL = sqs_client.get_queue_url(cls.QUEUE_NAME)
        
        host = aws_config.get_service_host(cls.QUEUE_REGION, cls.SERVICE)
        
        assert cls.QUEUE_URL is not None
        assert not cls.QUEUE_URL.startswith("http://%s" % host)
        assert cls.QUEUE_URL.endswith(cls.QUEUE_NAME)
    
    def setUp(self):
        '''Method invoked automatically in order to set up all test cases dependencies.'''
        
        self._sqs_client = SqsClient(SqsClientSanityCheck.QUEUE_REGION)
        
    def test_sqs_create_message(self):
        '''Test case that checks new messages can be created using sqs client.'''
        
        message_body = {"message1": {"name": "Test", "body": "Junk"}}
        message = QueueMessage(body = message_body, 
                               queue_url = SqsClientSanityCheck.QUEUE_URL)
        
        self._sqs_client.create_message(message)
        
        self.assertIsNotNone(message.msg_id)
    
    def test_sqs_receive_message(self):
        '''Test case that checks messages retrieval from the queue.'''
        
        num_messages = 2
        
        added_messages = []
        
        message_body = {"message1": {"name": "Test", "body": "Junk"}}
        
        # push a number of messages to the queue.
        for i in range(0, num_messages):
            message = QueueMessage(body = message_body, 
                                   queue_url = SqsClientSanityCheck.QUEUE_URL)
         
            self._sqs_client.create_message(message)
            
            added_messages.append(message.msg_id)
        
        # retrieve first two messages added
        # we request 3 messages done because one message belongs to create_message success test.
        messages = self._sqs_client.get_messages(SqsClientSanityCheck.QUEUE_URL, num_messages) 
        
        self.assertEqual(len(messages), num_messages)
                
    def test_sqs_delete_message(self):
        '''Test case that checks messages deletion from the queue.'''
        
        num_messages = 2
        
        added_messages = []
        
        message_body = {"message1": {"name": "Test", "body": "Junk"}}
        
        # push a number of messages to the queue.
        for i in range(0, num_messages):
            message = QueueMessage(body = message_body, 
                                   queue_url = SqsClientSanityCheck.QUEUE_URL)
         
            self._sqs_client.create_message(message)
            added_messages.append(message.msg_id)
        
        messages = self._sqs_client.get_messages(SqsClientSanityCheck.QUEUE_URL, num_messages)

        self.assertGreater(len(messages), 0)
        
        deleted_messages = self._sqs_client.delete_messages(SqsClientSanityCheck.QUEUE_URL, messages)
        
        self.assertEqual(len(messages), len(deleted_messages))