Beispiel #1
0
 def test_get_mode_thumb_orig(self):
     """Ensure the /photos/<photo_id>?mode=thumbnail route behaves correctly."""
     access_token, _ = cognito_signin(boto3.client('cognito-idp'), existed_user)
     # 1. upload
     upload['file'] = (BytesIO(b'my file contents'), 'test_image.jpg')
     response = self.client.post(
         '/photos/file',
         headers=self.test_header,
         content_type='multipart/form-data',
         data=upload
     )
     self.assert200(response)
     photo_id = [item.id for item in Photo.scan(Photo.filename_orig.startswith('test_image.jpg'), limit=1)]
     # 2. thumbnails
     data = {'mode': 'thumbnails'}
     response = self.client.get(
         '/photos/{}'.format(photo_id[0]),
         headers=self.test_header,
         content_type='application/json',
         query_string=data
     )
     self.assert200(response)
     # 3. original
     data = {'mode': 'original'}
     response = self.client.get(
         '/photos/{}'.format(photo_id),
         headers=self.test_header,
         content_type='application/json',
         query_string=data
     )
     self.assert200(response)
Beispiel #2
0
 def create_token_and_header(self):
     with self.app.app_context():
         # Create test user
         msg = '{0}{1}'.format(existed_user['email'], self.app.config['COGNITO_CLIENT_ID'])
         dig = hmac.new(self.app.config['COGNITO_CLIENT_SECRET'].encode('utf-8'),
                        msg=msg.encode('utf-8'),
                        digestmod=hashlib.sha256).digest()
         try:
             cognito_client = boto3.client('cognito-idp')
             response = cognito_client.sign_up(
                 ClientId=self.app.config['COGNITO_CLIENT_ID'],
                 SecretHash=base64.b64encode(dig).decode(),
                 Username=existed_user['email'],
                 Password=existed_user['password'],
                 UserAttributes=[{
                     'Name': 'name',
                     'Value': existed_user['username']
                 }],
                 ValidationData=[{
                     'Name': 'name',
                     'Value': existed_user['username']
                 }]
             )
             username = response['UserSub']
             cognito_client.admin_confirm_sign_up(
                 UserPoolId=self.app.config['COGNITO_POOL_ID'],
                 Username=username
             )
         except cognito_client.exceptions.UsernameExistsException as e:
             pass
         finally:
             self.access_token, _ = cognito_signin(boto3.client('cognito-idp'), existed_user)
             self.test_header = dict(Authorization='Bearer {0}'.format(self.access_token))
Beispiel #3
0
 def test_list(self):
     """Ensure the /photos/ route behaves correctly."""
     access_token, _ = cognito_signin(boto3.client('cognito-idp'), existed_user)
     response = self.client.get(
         '/photos/',
         headers=self.test_header,
         content_type='application/json',
     )
     self.assert200(response)
 def test_signout(self):
     """Ensure signout request works well."""
     with self.client:
         access_token, _ = cognito_signin(boto3.client('cognito-idp'),
                                          existed_user)
         # access_token = create_access_token(identity=existed_user)
         # Signout
         response = self.client.post(
             '/users/signout',
             headers=dict(Authorization='Bearer {0}'.format(access_token)),
             content_type='application/json',
         )
         self.assert200(response)