-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(test/pricing): add flavor price delete tests
Signed-off-by: Sandro-Alessio Gierens <[email protected]>
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod accounting; | ||
mod budgeting; | ||
mod hello; | ||
mod pricing; | ||
mod resources; | ||
mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
use lrzcc::{Api, Token}; | ||
use lrzcc_test::spawn_app; | ||
use std::str::FromStr; | ||
use tokio::task::spawn_blocking; | ||
|
||
#[tokio::test] | ||
async fn e2e_lib_flavor_price_delete_denies_access_to_normal_user() { | ||
// arrange | ||
let server = spawn_app().await; | ||
let test_project = server | ||
.setup_test_project(0, 0, 1) | ||
.await | ||
.expect("Failed to setup test project"); | ||
let user = test_project.normals[0].user.clone(); | ||
let token = test_project.normals[0].token.clone(); | ||
server | ||
.mock_keystone_auth(&token, &user.openstack_id, &user.name) | ||
.mount(&server.keystone_server) | ||
.await; | ||
let flavor = server | ||
.setup_test_flavor() | ||
.await | ||
.expect("Failed to setup test flavor"); | ||
let flavor_price = server | ||
.setup_test_flavor_price(&flavor) | ||
.await | ||
.expect("Failed to setup test flavor group"); | ||
|
||
spawn_blocking(move || { | ||
// arrange | ||
let client = Api::new( | ||
format!("{}/api", &server.address), | ||
Token::from_str(&token).unwrap(), | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
// act | ||
let delete = client.flavor_price.delete(flavor_price.id); | ||
|
||
// assert | ||
assert!(delete.is_err()); | ||
assert_eq!( | ||
delete.unwrap_err().to_string(), | ||
format!("Admin privileges required") | ||
); | ||
}) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn e2e_lib_flavor_price_delete_denies_access_to_master_user() { | ||
// arrange | ||
let server = spawn_app().await; | ||
let test_project = server | ||
.setup_test_project(0, 1, 0) | ||
.await | ||
.expect("Failed to setup test project"); | ||
let user = test_project.masters[0].user.clone(); | ||
let token = test_project.masters[0].token.clone(); | ||
server | ||
.mock_keystone_auth(&token, &user.openstack_id, &user.name) | ||
.mount(&server.keystone_server) | ||
.await; | ||
let flavor = server | ||
.setup_test_flavor() | ||
.await | ||
.expect("Failed to setup test flavor"); | ||
let flavor_price = server | ||
.setup_test_flavor_price(&flavor) | ||
.await | ||
.expect("Failed to setup test flavor group"); | ||
|
||
spawn_blocking(move || { | ||
// arrange | ||
let client = Api::new( | ||
format!("{}/api", &server.address), | ||
Token::from_str(&token).unwrap(), | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
// act | ||
let delete = client.flavor_price.delete(flavor_price.id); | ||
|
||
// assert | ||
assert!(delete.is_err()); | ||
assert_eq!( | ||
delete.unwrap_err().to_string(), | ||
format!("Admin privileges required") | ||
); | ||
}) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn e2e_lib_flavor_price_delete_works() { | ||
// arrange | ||
let server = spawn_app().await; | ||
let test_project = server | ||
.setup_test_project(1, 0, 0) | ||
.await | ||
.expect("Failed to setup test project"); | ||
let user = test_project.admins[0].user.clone(); | ||
let token = test_project.admins[0].token.clone(); | ||
server | ||
.mock_keystone_auth(&token, &user.openstack_id, &user.name) | ||
.mount(&server.keystone_server) | ||
.await; | ||
let flavor = server | ||
.setup_test_flavor() | ||
.await | ||
.expect("Failed to setup test flavor"); | ||
let flavor_price = server | ||
.setup_test_flavor_price(&flavor) | ||
.await | ||
.expect("Failed to setup test flavor group"); | ||
|
||
spawn_blocking(move || { | ||
// arrange | ||
let client = Api::new( | ||
format!("{}/api", &server.address), | ||
Token::from_str(&token).unwrap(), | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
// act and assert 1 - delete | ||
client.flavor_price.delete(flavor_price.id).unwrap(); | ||
|
||
// act and assert 2 - get | ||
let get = client.flavor.get(flavor_price.id); | ||
assert!(get.is_err()); | ||
assert_eq!( | ||
get.unwrap_err().to_string(), | ||
"Resource not found".to_string() | ||
); | ||
}) | ||
.await | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod delete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod flavor_price; |