def test_config_invalid_admin_creds(self): args = [ 'config', 'invalid-key', 'invalid-secret', '--profile', IAM_ADMIN ] success, msg = CmdConfig(parse_args(args)).run() self.assertEqual(msg, 'Invalid credentials') self.assertFalse(success)
def test_create_upload_area_no_config_exits_error(self): # given args = ['create', 'testUploadArea'] # when with self.assertRaises(SystemExit) as error: Cmd(parse_args(args)) # then self.assertEqual(error.exception.code, 1)
def test_create_upload_area_no_config_display_error(self): # given args = ['create', 'testUploadArea'] # when success, msg = CmdCreate(None, parse_args(args)).run() # then self.assertFalse(success) self.assertEqual(msg, 'You need configure your profile first')
def test_user_create_upload_area_has_valid_config(self): # given self.aws_mock.is_user = True args = ['create', 'testUploadArea'] # when success, msg = CmdCreate(self.aws_mock, parse_args(args)).run() # then self.assertFalse(success) self.assertEqual(msg, 'You don\'t have permission to use this command')
def test_create_upload_area_with_invalid_credentials(self, aws_mock): # given aws_mock.is_valid_credentials = False args = ['create', 'uploadArea'] # when with self.assertRaises(SystemExit) as error: Cmd(parse_args(args)) # then self.assertEqual(error.exception.code, 1)
def test_upload_inexisting_file(self): # given args = ['upload', 'inexisting-file.txt'] # when with self.assertRaises(SystemExit) as error: parsed_args = parse_args(args) success, msg = CmdUpload(self.aws_mock, parsed_args) self.assertFalse(parsed_args) self.assertFalse(success) self.assertFalse(msg) self.assertEqual(error.exception.code, 2)
def test_admin_create_upload_area_has_exception(self, uuid): # given uuid.return_value = 'uuid' args = ['create', 'testUploadArea'] self.client.put_object.side_effect = Mock( side_effect=Exception('Test')) # when success, msg = CmdCreate(self.aws_mock, parse_args(args)).run() # then self.assertFalse(success)
def test_admin_create_upload_area_no_name(self): # given args = ['create'] # when with self.assertRaises(SystemExit) as error: parsed_args = parse_args(args) success, msg = CmdCreate(self.aws_mock, parsed_args).run() self.assertFalse(parsed_args) self.assertFalse(success) self.assertFalse(msg) self.assertEqual(error.exception.code, 2)
def test_admin_create_upload_area(self, uuid): # given uuid.return_value = 'uuid' args = ['create', 'testUploadArea'] # when success, msg = CmdCreate(self.aws_mock, parse_args(args)).run() # then self.assertTrue(success) metadata = {'name': 'testUploadArea', 'perms': 'ux'} self.client.put_object.assert_called_once_with(Bucket='bucket-name', Key='uuid/', Metadata=metadata)
def test_config_with_bucket(self, set_bucket): args = ['config', user_access, user_secret, '--bucket', 'bucket'] success, msg = CmdConfig(parse_args(args)).run() self.assertTrue(success)
def test_config_valid_admin_creds(self): args = ['config', admin_access, admin_secret] success, msg = CmdConfig(parse_args(args)).run() self.assertTrue(success) self.assertEqual(msg, 'Valid credentials for admin use')
def test_config_valid_user_creds(self): args = ['config', user_access, user_secret] success, msg = CmdConfig(parse_args(args)).run() self.assertTrue(success) self.assertEqual(msg, 'Valid credentials')
def test_config_invalid_creds(self): args = ['config', 'invalid-key', 'invalid-secret'] success, msg = CmdConfig(parse_args(args)).run() self.assertFalse(success) self.assertEqual(msg, 'Invalid credentials')
def test_config_valid_admin_creds(self): args = ['config', admin_access, admin_secret, '--profile', IAM_ADMIN] success, msg = CmdConfig(parse_args(args)).run() self.assertTrue(success) self.assertEqual(msg, 'Valid credentials')