def test_insert_account_conflict(self): with self.app.test_request_context(): with patch.object(Interactions, 'query', return_value={'username': '******'}): response = insert_account(DEFAULT_SUBSCRIPTIONS_TABLE, **self.param_kwargs) self.assertEqual(response.status_code, client.CONFLICT)
def test_delete_account_type_error(self): with self.app.test_request_context(): with patch.object(Interactions, 'query', side_effect=TypeError): response = insert_account(DEFAULT_SUBSCRIPTIONS_TABLE, **self.param_kwargs) self.assertRaises(TypeError) self.assertEqual(response.status_code, client.BAD_REQUEST)
def test_delete_account_rql_driver_error(self): with self.app.test_request_context(): with patch.object(Interactions, 'query', side_effect=RqlDriverError(None)): response = insert_account(DEFAULT_SUBSCRIPTIONS_TABLE, **self.param_kwargs) self.assertRaises(RqlDriverError) self.assertEqual(response.status_code, client.INTERNAL_SERVER_ERROR)
def test_insert_account(self): with self.app.test_request_context(): with patch.object(Interactions, 'query', return_value={}): with patch.object(Interactions, 'insert', return_value={'id': '123'}): response = insert_account(DEFAULT_SUBSCRIPTIONS_TABLE, **self.param_kwargs) self.assertEqual(response.status_code, client.CREATED)
def post(self): """ Creates a new account """ json_data = request.get_json() if not client_echo_valid(json_data['endpoint']): return make_response(jsonify({'Error': 'Echo response failed'}), client.BAD_REQUEST) return insert_account(DEFAULT_ACCOUNTS_TABLE, **{'username': json_data['username'], 'endpoint': json_data['endpoint'], 'is_admin': False, 'failed_count': 0, 'api_key': generate_key(), 'secret_key': generate_key()})