def test_package_stop(self): package = ensure_test_package() set_attr(package, "status", 10) api_r = requests.get(self.url + str(package.id) + "/action", params={"operation": "stop"}) self.assertEqual(requests.codes.ok, api_r.status_code, api_r.text) session.expire(package) self.assertEqual(0, package.status)
def setUpClass(cls): cls.maxDiff = None count = get_hosts_count() to_add = 120 - count test_package = ensure_test_package() bench_package = get_bench_all_package() add_host(test_package.id, count=int(to_add / 2)) add_host(bench_package.id, count=int(to_add / 2))
def test_delete_package_ok(self): test_package = ensure_test_package() test_package_id = test_package.id api_r = requests.delete(self.url + str(test_package_id)) self.assertEqual(204, api_r.status_code, api_r.text) session.expire(test_package) package = get_package(test_package_id) self.assertIsNone(package)
def test_delete_package_error(self): package_id = ensure_test_package().id old_count = len(get_all_packages()) package_id += 1 package = get_package(package_id) while package is not None: package_id += 1 package = get_package(package_id) api_r = requests.delete(self.url + str(package_id)) self.assertEqual(404, api_r.status_code, api_r.text) count = len(get_all_packages()) self.assertEqual(old_count, count)
def test_package_add_hosts(self): package = ensure_test_package() user = ensure_user() b_host1 = add_boinc_host(user.id) b_host2 = add_boinc_host(user.id) assign_host_to_package(b_host1.id, package.id) assign_host_to_package(b_host2.id, package.id) b_host1 = add_boinc_host(user.id) b_host2 = add_boinc_host(user.id) new_hosts_ids = [b_host1.id, b_host2.id] params = {"newHost_ids": new_hosts_ids} api_r = requests.post(self.url + str(package.id) + "/host", json=params) self.assertEqual(requests.codes.ok, api_r.status_code, api_r.text) self.assertEqual(True, api_r.json()["status"]) session.expire_all() hosts = get_active_boinc_hosts(package.id) hosts_ids = [h.id for h in hosts] self.assertEqual(new_hosts_ids, hosts_ids)
def setUp(self): ensure_test_package()