Repository: getmoto/moto

Issue:
NotImplementedError: The list_user_policies action has not been implemented
I was trying to test iam [get_all_user_policies()](http://boto.cloudhackers.com/en/latest/ref/iam.html#boto.iam.connection.IAMConnection.get_all_user_policies), but got this error.

```
  File "/home/z/pproj/ecs-refarch-cloudformation/services/ken/src/libs/aws.py", line 2974, in get_iam_summary
    result = conn.get_all_user_policies(user['user_name'], marker=marker)['list_user_policies_response']
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/boto/iam/connection.py", line 435, in get_all_user_policies
    list_marker='PolicyNames')
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/boto/iam/connection.py", line 85, in get_response
    response = self.make_request(action, params, path, verb)
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/boto/connection.py", line 1116, in make_request
    return self._mexe(http_request)
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/boto/connection.py", line 944, in _mexe
    response = connection.getresponse()
  File "/usr/lib64/python2.7/httplib.py", line 1133, in getresponse
    response = self.response_class(*args, **kwds)
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/boto/connection.py", line 390, in __init__
    http_client.HTTPResponse.__init__(self, *args, **kwargs)
  File "/usr/lib64/python2.7/httplib.py", line 390, in __init__
    self.fp = sock.makefile('rb', 0)
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/httpretty/core.py", line 332, in makefile
    self._entry.fill_filekind(self.fd)
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/httpretty/core.py", line 591, in fill_filekind
    status, headers, self.body = self.callable_body(self.request, self.info.full_url(), headers)
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/moto/core/responses.py", line 107, in dispatch
    return cls()._dispatch(*args, **kwargs)
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/moto/core/responses.py", line 167, in _dispatch
    return self.call_action()
  File "/home/u1/.virtualenvs/ken/lib/python2.7/site-packages/moto/core/responses.py", line 193, in call_action
    raise NotImplementedError("The {0} action has not been implemented".format(action))
NotImplementedError: The list_user_policies action has not been implemented
```


Discussion:
Thanks for opening. I will add it to the feature list.

Resolving patch:
diff --git a/moto/iam/models.py b/moto/iam/models.py
--- a/moto/iam/models.py
+++ b/moto/iam/models.py
@@ -729,6 +729,10 @@ def get_user_policy(self, user_name, policy_name):
         policy = user.get_policy(policy_name)
         return policy
 
+    def list_user_policies(self, user_name):
+        user = self.get_user(user_name)
+        return user.policies.keys()
+
     def put_user_policy(self, user_name, policy_name, policy_json):
         user = self.get_user(user_name)
         user.put_policy(policy_name, policy_json)
diff --git a/moto/iam/responses.py b/moto/iam/responses.py
--- a/moto/iam/responses.py
+++ b/moto/iam/responses.py
@@ -287,6 +287,12 @@ def get_user_policy(self):
             policy_document=policy_document
         )
 
+    def list_user_policies(self):
+        user_name = self._get_param('UserName')
+        policies = iam_backend.list_user_policies(user_name)
+        template = self.response_template(LIST_USER_POLICIES_TEMPLATE)
+        return template.render(policies=policies)
+
     def put_user_policy(self):
         user_name = self._get_param('UserName')
         policy_name = self._get_param('PolicyName')
@@ -854,6 +860,20 @@ def get_credential_report(self):
    </ResponseMetadata>
 </GetUserPolicyResponse>"""
 
+LIST_USER_POLICIES_TEMPLATE = """<ListUserPoliciesResponse>
+   <ListUserPoliciesResult>
+      <PolicyNames>
+        {% for policy in policies %}
+         <member>{{ policy }}</member>
+        {% endfor %}
+      </PolicyNames>
+   </ListUserPoliciesResult>
+   <IsTruncated>false</IsTruncated>
+   <ResponseMetadata>
+      <RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
+   </ResponseMetadata>
+</ListUserPoliciesResponse>"""
+
 CREATE_ACCESS_KEY_TEMPLATE = """<CreateAccessKeyResponse>
    <CreateAccessKeyResult>
      <AccessKey>


Test patch:
diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py
--- a/tests/test_iam/test_iam.py
+++ b/tests/test_iam/test_iam.py
@@ -234,6 +234,39 @@ def test_list_users():
     user['Arn'].should.equal('arn:aws:iam::123456789012:user/my-user')
 
 
+@mock_iam()
+def test_user_policies():
+    policy_name = 'UserManagedPolicy'
+    policy_document = "{'mypolicy': 'test'}"
+    user_name = 'my-user'
+    conn = boto3.client('iam', region_name='us-east-1')
+    conn.create_user(UserName=user_name)
+    conn.put_user_policy(
+        UserName=user_name,
+        PolicyName=policy_name,
+        PolicyDocument=policy_document
+    )
+
+    policy_doc = conn.get_user_policy(
+        UserName=user_name,
+        PolicyName=policy_name
+    )
+    test = policy_document in policy_doc['PolicyDocument']
+    test.should.equal(True)
+
+    policies = conn.list_user_policies(UserName=user_name)
+    len(policies['PolicyNames']).should.equal(1)
+    policies['PolicyNames'][0].should.equal(policy_name)
+
+    conn.delete_user_policy(
+        UserName=user_name,
+        PolicyName=policy_name
+    )
+
+    policies = conn.list_user_policies(UserName=user_name)
+    len(policies['PolicyNames']).should.equal(0)
+
+
 @mock_iam_deprecated()
 def test_create_login_profile():
     conn = boto.connect_iam()