Skip to content

Commit

Permalink
test(test/pricing): add flavor price delete tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sandro-Alessio Gierens <[email protected]>
  • Loading branch information
gierens committed Dec 10, 2024
1 parent 3aa684d commit 7e2d897
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/tests/main.rs
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;
146 changes: 146 additions & 0 deletions test/tests/pricing/flavor_price/delete.rs
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();
}
1 change: 1 addition & 0 deletions test/tests/pricing/flavor_price/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod delete;
1 change: 1 addition & 0 deletions test/tests/pricing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod flavor_price;

0 comments on commit 7e2d897

Please sign in to comment.