예제 #1
0
    def test_get_resources_raise_on_bad_key(self):
        source_key = 'salesforce/test.json'
        event = TestLambdaFunction.get_s3_event(self.STAGING_BUCKET, source_key)

        with self.assertRaises(IndexError) as context:
            get_resources(
                event=event, 
                source_bucket=self.STAGING_BUCKET, 
                dest_bucket=self.DESTINATION_BUCKET, 
                exile_bucket=self.EXILE_BUCKET)
        
        self.assertTrue('Object landed in incorrect location. Ensure object is in ' +
            '"[bucket]/[source_name]/[object_name]".' in str(context.exception))
예제 #2
0
    def test_get_resources_raise_on_missing_key(self):
        source_key = 'salesforce/record_type/test.json'
        event = TestLambdaFunction.get_s3_event(self.STAGING_BUCKET, source_key)
        event['Records'][0]['s3']['object'].pop('key')

        with self.assertRaises(KeyError) as context:
            get_resources(
                event=event, 
                source_bucket=self.STAGING_BUCKET, 
                dest_bucket=self.DESTINATION_BUCKET, 
                exile_bucket=self.EXILE_BUCKET)
        
        self.assertTrue('Malformed JSON request. Ensure key is located in '+
            'event["Records"][0]["s3"]["object"]["key"].' in str(context.exception))
예제 #3
0
    def test_get_tags_raises_on_no_tags(self):
        source_key = 'salesforce/record_type/test.json'
        event = TestLambdaFunction.get_s3_event(self.STAGING_BUCKET, source_key)
        resources = get_resources(
            event=event, 
            source_bucket=self.STAGING_BUCKET, 
            dest_bucket=self.DESTINATION_BUCKET, 
            exile_bucket=self.EXILE_BUCKET)

        with self.assertRaises(ValueError) as context:
            try_get_tags(resources, self.ssm_client, self.s3_resource)
        
        self.assertTrue('This object has no corresponding tags in AWS Parameter Store.'
                        in str(context.exception))
예제 #4
0
    def test_get_resources(self):
        source_key = 'salesforce/record_type/test.json'
        event = TestLambdaFunction.get_s3_event(self.STAGING_BUCKET, source_key)

        resources = get_resources(
            event=event, 
            source_bucket=self.STAGING_BUCKET, 
            dest_bucket=self.DESTINATION_BUCKET, 
            exile_bucket=self.EXILE_BUCKET)
        
        self.assertEqual(resources['source_bucket'], self.STAGING_BUCKET) 
        self.assertEqual(resources['source_key'], source_key)
        self.assertEqual(resources['destination_bucket'], self.DESTINATION_BUCKET)
        self.assertEqual(resources['exile_bucket'], self.EXILE_BUCKET)
        self.assertEqual(resources['source_name'], 'salesforce')
        self.assertEqual(resources['source_object_name'], 'record_type')
        self.assertEqual(resources['column_partition'], ['created_date'])
        self.assertEqual(resources['prefix'], 'salesforce/record_type/')
예제 #5
0
    def test_try_get_tags(self):
        parm_name = '/salesforce/record_type/classification'
        parm_value = 'private'
        key = 'classification'
        self.ssm_client.put_parameter(
            Name=parm_name, 
            Description='Description',
            Value=parm_value,
            Type='Type'
        )

        source_key = 'salesforce/record_type/test.json'
        event = TestLambdaFunction.get_s3_event(self.STAGING_BUCKET, source_key)
        resources = get_resources(
            event=event, 
            source_bucket=self.STAGING_BUCKET, 
            dest_bucket=self.DESTINATION_BUCKET, 
            exile_bucket=self.EXILE_BUCKET)

        tags = try_get_tags(resources, self.ssm_client, self.s3_resource)

        self.assertEqual(key, tags[0]['Key'])
        self.assertEqual(parm_value, tags[0]['Value'])