def test_dynamodb_local_with_dynalite(self): name = "local-identity-vault" os.environ["CIS_ENVIRONMENT"] = "local" os.environ["CIS_DYNALITE_HOST"] = self.dynalite_host os.environ["CIS_DYNALITE_PORT"] = self.dynalite_port os.environ["CIS_ASSUME_ROLE_ARN"] = "arn:aws:iam::123456789000:role/demo-assume-role" dynalite_session = Stubber(boto3.session.Session(region_name="us-west-2")).client.client( "dynamodb", endpoint_url="http://{}:{}".format(self.dynalite_host, self.dynalite_port) ) dynalite_session.create_table( TableName=name, KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}], AttributeDefinitions=[{"AttributeName": "id", "AttributeType": "S"}], ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}, ) from cis_aws import connect c = connect.AWS() c.session() c.assume_role() res = c.identity_vault_client() assert res is not None assert res.get("client") is not None
def setup(self): os.environ["CIS_CONFIG_INI"] = "tests/mozilla-cis.ini" from cis_change_service.common import get_config config = get_config() os.environ["CIS_DYNALITE_PORT"] = str(random.randint(32000, 34000)) os.environ["CIS_KINESALITE_PORT"] = str(random.randint(32000, 34000)) self.kinesalite_port = config("kinesalite_port", namespace="cis") self.kinesalite_host = config("kinesalite_host", namespace="cis") self.dynalite_port = config("dynalite_port", namespace="cis") self.dynaliteprocess = subprocess.Popen( ["dynalite", "--port", self.dynalite_port], preexec_fn=os.setsid) self.kinesaliteprocess = subprocess.Popen( ["kinesalite", "--port", self.kinesalite_port], preexec_fn=os.setsid) conn = Stubber( boto3.session.Session(region_name="us-west-2")).client.client( "kinesis", endpoint_url="http://{}:{}".format(self.kinesalite_host, self.kinesalite_port)) try: name = "local-stream" conn.create_stream(StreamName=name, ShardCount=1) except Exception as e: logger.error("Stream error: {}".format(e)) # This just means we tried too many tests too fast. pass waiter = conn.get_waiter("stream_exists") waiter.wait(StreamName=name, Limit=100, WaiterConfig={ "Delay": 1, "MaxAttempts": 5 }) tags_1 = {"Key": "cis_environment", "Value": "local"} tags_2 = {"Key": "application", "Value": "change-stream"} conn.add_tags_to_stream(StreamName=name, Tags=tags_1) conn.add_tags_to_stream(StreamName=name, Tags=tags_2) name = "local-identity-vault" conn = boto3.client( "dynamodb", region_name="us-west-2", aws_access_key_id="ak", aws_secret_access_key="sk", endpoint_url="http://localhost:{}".format(self.dynalite_port), ) try: conn.create_table( TableName=name, KeySchema=[{ "AttributeName": "id", "KeyType": "HASH" }], AttributeDefinitions=[ { "AttributeName": "id", "AttributeType": "S" }, { "AttributeName": "uuid", "AttributeType": "S" }, { "AttributeName": "sequence_number", "AttributeType": "S" }, { "AttributeName": "primary_email", "AttributeType": "S" }, { "AttributeName": "primary_username", "AttributeType": "S" }, { "AttributeName": "profile", "AttributeType": "S" }, ], ProvisionedThroughput={ "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, GlobalSecondaryIndexes=[ { "IndexName": "{}-sequence_number".format(name), "KeySchema": [{ "AttributeName": "sequence_number", "KeyType": "HASH" }], "Projection": { "ProjectionType": "ALL" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, }, { "IndexName": "{}-primary_email".format(name), "KeySchema": [{ "AttributeName": "primary_email", "KeyType": "HASH" }], "Projection": { "ProjectionType": "ALL" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, }, { "IndexName": "{}-primary_username".format(name), "KeySchema": [{ "AttributeName": "primary_username", "KeyType": "HASH" }], "Projection": { "ProjectionType": "ALL" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, }, { "IndexName": "{}-uuid".format(name), "KeySchema": [{ "AttributeName": "uuid", "KeyType": "HASH" }], "Projection": { "ProjectionType": "ALL" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, }, ], ) waiter = conn.get_waiter("table_exists") waiter.wait(TableName="local-identity-vault", WaiterConfig={ "Delay": 1, "MaxAttempts": 5 }) except Exception as e: logger.error("Table error: {}".format(e)) self.user_profile = FakeUser().as_json() from cis_change_service import api api.app.testing = True self.app = api.app.test_client()