def test_build_part_not_chosen(self): clear_devices() clear_inventory() config = self.get_starter_configuration() for part, name in config.items(): if name: add_inventory_element(name[0] if isinstance(name, list) else name) for part in ["cpu", "ram", "disk"]: with self.assertRaises(MissingPartException) as ctx: self.client.ms("device", ["hardware", "build"], **{**config, part: []}) exception: MissingPartException = ctx.exception self.assertEqual([part], exception.params)
def test_inventory_trade_user_does_not_exists(self): clear_inventory() element_uuid = add_inventory_element("CPU Cooler Plus") with self.assertRaises(UserUUIDDoesNotExistException): self.client.ms("inventory", ["inventory", "trade"], element_uuid=element_uuid, target=uuid())
def test_inventory_trade_cannot_trade_with_yourself(self): clear_inventory() element_uuid = add_inventory_element("CPU Cooler Plus") with self.assertRaises(CannotTradeWithYourselfException): self.client.ms("inventory", ["inventory", "trade"], element_uuid=element_uuid, target=super_uuid)
def test_build_successful(self): clear_devices() clear_inventory() config = self.get_starter_configuration() for _, name in config.items(): if name: add_inventory_element(name[0] if isinstance(name, list) else name) result = self.client.ms("device", ["hardware", "build"], **config) self.assert_dict_with_keys(result, ["success", "performance"]) self.assertTrue(result["success"]) performance = result["performance"] self.assertIsInstance(performance, list) self.assertEqual(5, len(performance)) for e in performance: self.assertIsInstance(e, (int, float))
def test_inventory_list_successful(self): clear_inventory() element_uuid = add_inventory_element("CPU Cooler Plus") expected = { "elements": [{ "element_uuid": element_uuid, "element_name": "CPU Cooler Plus", "related_ms": "", "owner": super_uuid, }] } actual = self.client.ms("inventory", ["inventory", "list"]) self.assertEqual(expected, actual)
def test_inventory_trade_successful(self): clear_inventory() element_uuid = add_inventory_element("CPU Cooler Plus") trade_user = create_random_user() expected = {"ok": True} actual = self.client.ms("inventory", ["inventory", "trade"], element_uuid=element_uuid, target=trade_user) self.assertEqual(actual, expected) client: Client = get_client() client.login("test", super_password) result = InventoryElement.list_inventory(client) self.assertEqual(1, len(result)) self.assertEqual(trade_user, result[0].owner) self.assertEqual("", result[0].related_ms) self.assertEqual(element_uuid, result[0].uuid) self.assertEqual("CPU Cooler Plus", result[0].name)