Comments (3)
Yes @0ri0nRo, that looks like it should work.
from moto.
Hi @0ri0nRo, Moto v5 (the latest release) usesmock_aws
instead of mock_s3
.
Which test example are you using? If it comes from the official Moto documentation, it should always say mock_aws
.
from moto.
If my code is:
import unittest
import lambda_function
import boto3
import botocore
import json
from moto import mock_iam
from lambda_function import AccessKey
class AccessKeyTest(unittest.TestCase):
def test_init(self):
username = 'abc'
a = AccessKey(username, 'eu-north-1')
self.assertEqual(a.user, username)
self.assertEqual(a.param_region, 'eu-north-1')
self.assertEqual(a.param_access, f'/{username}/ACCESS_KEY_ID')
self.assertEqual(a.param_secret, f'/{username}/ACCESS_SECRET_KEY')
def test_custom_params(self):
a = AccessKey('abc', 'eu-north-1', '/custom/access', '/custom/secret')
self.assertEqual(a.param_access, '/custom/access')
self.assertEqual(a.param_secret, '/custom/secret')
@mock_iam
def create_user_with_access_key_and_multiple_policies(
user_name,
inline_policy_document,
attached_policy_document,
inline_policy_name="policy1",
attached_policy_name="policy1",
):
client = boto3.client("iam", region_name="us-east-1")
client.create_user(UserName=user_name)
policy_arn = client.create_policy(
PolicyName=attached_policy_name,
PolicyDocument=json.dumps(attached_policy_document),
)["Policy"]["Arn"]
client.attach_user_policy(UserName=user_name, PolicyArn=policy_arn)
client.put_user_policy(
UserName=user_name,
PolicyName=inline_policy_name,
PolicyDocument=json.dumps(inline_policy_document),
)
return client.create_access_key(UserName=user_name)["AccessKey"]
if __name__ == '__main__':
unittest.main()
I need to change as follow (?):
import unittest
import lambda_function
import boto3
import botocore
import json
from moto import mock_aws
from lambda_function import AccessKey
class AccessKeyTest(unittest.TestCase):
def test_init(self):
username = 'abc'
a = AccessKey(username, 'eu-north-1')
self.assertEqual(a.user, username)
self.assertEqual(a.param_region, 'eu-north-1')
self.assertEqual(a.param_access, f'/{username}/ACCESS_KEY_ID')
self.assertEqual(a.param_secret, f'/{username}/ACCESS_SECRET_KEY')
def test_custom_params(self):
a = AccessKey('abc', 'eu-north-1', '/custom/access', '/custom/secret')
self.assertEqual(a.param_access, '/custom/access')
self.assertEqual(a.param_secret, '/custom/secret')
@mock_aws
def create_user_with_access_key_and_multiple_policies(
user_name,
inline_policy_document,
attached_policy_document,
inline_policy_name="policy1",
attached_policy_name="policy1",
):
client = boto3.client("iam", region_name="us-east-1")
client.create_user(UserName=user_name)
policy_arn = client.create_policy(
PolicyName=attached_policy_name,
PolicyDocument=json.dumps(attached_policy_document),
)["Policy"]["Arn"]
client.attach_user_policy(UserName=user_name, PolicyArn=policy_arn)
client.put_user_policy(
UserName=user_name,
PolicyName=inline_policy_name,
PolicyDocument=json.dumps(inline_policy_document),
)
return client.create_access_key(UserName=user_name)["AccessKey"]
if __name__ == '__main__':
unittest.main()
from moto.
Related Issues (20)
- Unable to easily mock Athena result CSV HOT 3
- Feature - Add basic support for Network Manager. Global and Core Networks HOT 1
- S3: Configure the MaxKeys limit (list_objects/list_objects_v2) using an env variable
- Cognito-Idp: I see 'code_delivery_details' is nil when signingUp.
- IAM - create_policy returns bad tags HOT 1
- DynamoDB query with GSI doesn't return LastEvaluatedKey when paging moto 5.0.4 and later HOT 3
- No validationError raised on multiple "SET" operators in UpdateExpression HOT 1
- Infinite recursion error with moto 5.0.8 HOT 4
- RDS Clusters: Setting default values HOT 1
- EC2 DescribeRouteTables filter 'route.transit-gateway-id' not implemented HOT 3
- Error when I try to use scaffolding to create shield HOT 3
- Unable to create rds cluster HOT 1
- SSM.Client.get_parameter() by ARN instead of Name fails with ParameterNotFound HOT 1
- DynamoDB Table query GSI with ExclusiveStartKey missing the primary key does not raise a ClientError
- EventBridge targets are not identified by moto when parsing cloudformation file.
- Supporting 'appemsh' service
- Missing 'email' field from Cognito JWT ID token
- Implementation for opensearch-serverless coverage.
- DynamoDB pagination issue in GSI with range key
- [Feature Request] Modify Backend Dict
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moto.