Exemple #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)
    def setUp(self):
        # Delete any test data that may be remained.
        for item in User.scan(User.username.startswith('test')):
            item.delete()
        for item in Photo.scan(Photo.filename_orig.startswith('test')):
            item.delete()

        # Create test user
        test_user = User(uuid.uuid4().hex)
        test_user.email = user['email']
        test_user.username = user['username']
        test_user.password = generate_password_hash(user['password'])
        test_user.save()
Exemple #3
0
 def test_delete(self):
     """Ensure the /photos/<photo_id> route behaves correctly."""
     # 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. delete
     response = self.client.delete(
         '/photos/{}'.format(photo_id[0]),
         headers=self.test_header,
         content_type='application/json',
     )
     self.assert200(response)
 def tearDown(self):
     # Delete test data
     for item in User.scan(User.username.startswith('test')):
         item.delete()
     for item in Photo.scan(Photo.filename_orig.startswith('test')):
         item.delete()