-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bf9230
commit 3a7e623
Showing
6 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.coverage | ||
.pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
import pytest | ||
import boto3 | ||
from moto import mock_aws | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def aws_credentials(): | ||
""" | ||
Mocked AWS Credentials for moto. | ||
""" | ||
|
||
os.environ["AWS_ACCESS_KEY_ID"] = "testing" | ||
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing" | ||
os.environ["AWS_SECURITY_TOKEN"] = "testing" | ||
os.environ["AWS_SESSION_TOKEN"] = "testing" | ||
os.environ["AWS_DEFAULT_REGION"] = "ap-southeast-1" | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def table(aws_credentials): | ||
with mock_aws(): | ||
dynamodb = boto3.resource('dynamodb', region_name='ap-southeast-1') | ||
table = dynamodb.create_table( | ||
TableName='cloud-resume', | ||
KeySchema=[ | ||
{ | ||
'AttributeName': 'id', | ||
'KeyType': 'HASH' | ||
} | ||
], | ||
AttributeDefinitions=[ | ||
{ | ||
'AttributeName': 'id', | ||
'AttributeType': 'S' | ||
} | ||
], | ||
ProvisionedThroughput={ | ||
'ReadCapacityUnits': 1, | ||
'WriteCapacityUnits': 1 | ||
} | ||
) | ||
|
||
yield table | ||
|
||
|
||
def test_lambda_increments_viewer_count(table): | ||
""" | ||
Test that the lambda function increments the viewer count by 1 | ||
""" | ||
|
||
table.put_item( | ||
Item={ | ||
'id': '1', | ||
'views': 0 | ||
} | ||
) | ||
|
||
from index import lambda_handler | ||
response = lambda_handler({}, {}) | ||
assert response == 1 | ||
|
||
# Check that the views have been incremented | ||
response = table.get_item( | ||
Key={ | ||
'id': '1' | ||
} | ||
) | ||
assert response['Item']['views'] == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
boto3==1.34.151 | ||
botocore==1.34.151 | ||
certifi==2024.7.4 | ||
cffi==1.16.0 | ||
charset-normalizer==3.3.2 | ||
coverage==7.6.0 | ||
cryptography==43.0.0 | ||
idna==3.7 | ||
iniconfig==2.0.0 | ||
Jinja2==3.1.4 | ||
jmespath==1.0.1 | ||
MarkupSafe==2.1.5 | ||
moto==5.0.11 | ||
packaging==24.1 | ||
pluggy==1.5.0 | ||
pycparser==2.22 | ||
pytest==8.3.2 | ||
pytest-cov==5.0.0 | ||
python-dateutil==2.9.0.post0 | ||
PyYAML==6.0.1 | ||
requests==2.32.3 | ||
responses==0.25.3 | ||
s3transfer==0.10.2 | ||
six==1.16.0 | ||
urllib3==2.2.2 | ||
Werkzeug==3.0.3 | ||
xmltodict==0.13.0 |