Skip to content

TSNobleSoftware/awssert

Repository files navigation

AWSsert

GitHub Workflow Status PyPI PyPI - Python Version Code style: black

AWSsert is a Python library providing declarative assertions about AWS resources to your tests.

Installation

Use the package manager pip to install AWSsert.

pip install awssert

Usage

Installing the package will make AWSserts extra assertions available to all of your tests. Assertions are attached directly to boto3 resource objects, allowing you to write clean and declarative tests:

import boto3

def test_bucket_contains_object():
   bucket = boto3.resource("s3").Bucket("foo")
   assert bucket.should_not.contain("bar")
   bucket.put_object(Key="bar", Body=b"123")
   assert bucket.should.contain("bar")

AWSsert also works in tandem with moto, enabling the same level of clarity to be applied on mock infrastructure:

import boto3
from moto import mock_s3

@mock_s3
def test_mock_bucket_contains_object():
   bucket = boto3.resource("s3").Bucket("foo")
   assert bucket.should_not.contain("bar")
   bucket.put_object(Key="bar", Body=b"123")
   assert bucket.should.contain("bar")

Progress

AWS Service Resource Object AWSsert Supported
CloudFormation Event
Stack
StackResource
StackResourceSummary
CloudWatch Alarm
Metric
DynamoDB Table
EC2 ClassicAddress
DhcpOptions
Image
Instance
InternetGateway
KeyPair
KeyPairInfo
NetworkAcl
NetworkInterface
NetworkInterfaceAssociation
PlacementGroup
Route
RouteTable
RouteTableAssociation
SecurityGroup
Snapshot
Subnet
Tag
Volume
Vpc
VpcPeeringConnection
VpcAddress
Glacier Account
Archive
Job
MultipartUpload
Notification
Vault
IAM AccessKey
AccessKeyPair
AccountPasswordPolicy
AccountSummary
AssumeRolePolicy
CurrentUser
Group
GroupPolicy
InstanceProfile
LoginProfile
MfaDevice
Policy
PolicyVersion
Role
RolePolicy
SamlProvider
ServerCertificate
SigningCertificate
User
UserPolicy
VirtualMfaDevice
OpsWorks Layer
Stack
StackSummary
S3 Bucket
BucketAcl
BucketCors
BucketLifecycle
BucketLifecycleConfiguration
BucketLogging
BucketNotification
BucketPolicy
BucketRequestPayment
BucketTagging
BucketVersioning
BucketWebsite
MultipartUpload
MultipartUploadPart
Object
ObjectAcl
ObjectSummary
ObjectVersion
SNS PlatformApplication
PlatformEndpoint
Subscription
Topic
SQS Message
Queue

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

A full contribution guide and code of conduct are supplied with the repository. In essence, update the unit tests and changelog, and treat fellow users with respect!

License

Apache Software License 2.0