def test_drop_contest_not_deletable(self): Utils.setup_encrypted_file() Database.del_meta("admin_token") with open(Config.encrypted_file, "wb") as f: f.write(Utils.build_pack(ruamel.yaml.dump({"deletable": False}))) with self.assertRaises(Forbidden): self.admin_handler.drop_contest(Utils.ZIP_TOKEN)
def test_drop_contest(self): Utils.setup_encrypted_file() Database.del_meta("admin_token") with open(Config.encrypted_file, "wb") as f: f.write(Utils.build_pack(ruamel.yaml.dump({"deletable": True}))) self.admin_handler.drop_contest(Utils.ZIP_TOKEN) self.assertFalse(os.path.exists(Config.storedir)) self.assertFalse(os.path.exists(Config.statementdir)) self.assertFalse(os.path.exists(Config.contest_path)) self.assertFalse(os.path.exists(Config.encrypted_file)) self.assertFalse(os.path.exists(Config.decrypted_file)) self.assertTrue(os.path.exists(Config.db))
def test_upload_pack(self): Utils.setup_encrypted_file() upload_path = os.path.join(os.path.dirname(__file__), "../assets/pack.zip.enc") os.remove(Config.encrypted_file) with open(upload_path, "rb") as f: content = f.read() Database.del_meta("admin_token") self.admin_handler.upload_pack(file={ "content": content, "name": "pack.zip.enc" }) self.assertTrue(os.path.exists(Config.encrypted_file))
def test_drop_contest_not_loaded_wrong_token(self): Utils.setup_encrypted_file() Database.del_meta("admin_token") with self.assertRaises(Forbidden): self.admin_handler.drop_contest("AAAAAA-CZKW-CCJS")
def test_drop_contest_loaded_wrong_token(self): Utils.setup_encrypted_file() Database.set_meta("admin_token", "UHUHU-HUHU") with self.assertRaises(Forbidden): self.admin_handler.drop_contest("LALLA-BALALLA")
def test_extract_no_priv(self): Utils.setup_encrypted_file() os.chmod(Config.encrypted_file, 0o000) with self.assertRaises(InternalServerError): ContestManager.extract_contest(Utils.ZIP_TOKEN)
def test_extract_contest(self): Utils.setup_encrypted_file() # see test/assets/README.md ContestManager.extract_contest(Utils.ZIP_TOKEN)
def test_extract_contest_unknown_username(self): Utils.setup_encrypted_file() with self.assertRaises(Forbidden): ContestManager.extract_contest("FOOBAR-ZVXJ-2IIH-LX5B-ZIGJ")
def test_extract_contest_wrong_password(self): Utils.setup_encrypted_file() with self.assertRaises(Forbidden): ContestManager.extract_contest("EDOOOO-XXXX-XXXX-XXXX-XXXX")