~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/ec2/tests/test_client.py

  • Committer: Duncan McGreggor
  • Date: 2009-10-06 18:34:35 UTC
  • mfrom: (33.1.5 444124-describe-zones)
  • Revision ID: duncan@canonical.com-20091006183435-el9j4wdv2229l63f
Merged 444124-describe-zones [r=therve] [f=444124]

Added support for getting a list of availability zones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
        ec2 = client.EC2Client(creds=creds)
72
72
        self.assertEqual(creds, ec2.creds)
73
73
 
 
74
    def test_describe_availability_zones_single(self):
 
75
        class StubQuery(object):
 
76
            def __init__(stub, action, creds, endpoint, other_params):
 
77
                self.assertEqual(action, "DescribeAvailabilityZones")
 
78
                self.assertEqual(creds.access_key, "foo")
 
79
                self.assertEqual(creds.secret_key, "bar")
 
80
                self.assertEqual(
 
81
                    {"ZoneName.1": "us-east-1a"},
 
82
                    other_params)
 
83
            def submit(self):
 
84
                return succeed(
 
85
                    payload.sample_describe_availability_zones_single_result)
 
86
 
 
87
        def check_parsed_availability_zone(results):
 
88
            self.assertEquals(len(results), 1)
 
89
            [zone] = results
 
90
            self.assertEquals(zone.name, "us-east-1a")
 
91
            self.assertEquals(zone.state, "available")
 
92
 
 
93
 
 
94
        creds = AWSCredentials("foo", "bar")
 
95
        ec2 = client.EC2Client(creds, query_factory=StubQuery)
 
96
        d = ec2.describe_availability_zones(["us-east-1a"])
 
97
        d.addCallback(check_parsed_availability_zone)
 
98
        return d
 
99
 
 
100
    def test_describe_availability_zones_multiple(self):
 
101
        class StubQuery(object):
 
102
            def __init__(stub, action, creds, endpoint, other_params):
 
103
                self.assertEqual(action, "DescribeAvailabilityZones")
 
104
                self.assertEqual(creds.access_key, "foo")
 
105
                self.assertEqual(creds.secret_key, "bar")
 
106
            def submit(self):
 
107
                return succeed(
 
108
                    payload.sample_describe_availability_zones_multiple_results)
 
109
 
 
110
        def check_parsed_availability_zones(results):
 
111
            self.assertEquals(len(results), 3)
 
112
            self.assertEquals(results[0].name, "us-east-1a")
 
113
            self.assertEquals(results[0].state, "available")
 
114
            self.assertEquals(results[1].name, "us-east-1b")
 
115
            self.assertEquals(results[1].state, "available")
 
116
            self.assertEquals(results[2].name, "us-east-1c")
 
117
            self.assertEquals(results[2].state, "available")
 
118
 
 
119
        creds = AWSCredentials("foo", "bar")
 
120
        ec2 = client.EC2Client(creds, query_factory=StubQuery)
 
121
        d = ec2.describe_availability_zones()
 
122
        d.addCallback(check_parsed_availability_zones)
 
123
        return d
 
124
 
74
125
 
75
126
class EC2ClientInstancesTestCase(TXAWSTestCase):
76
127