def validate(puzzleid=None, variantid=None, position=None): if puzzleid == None: raise ValueError("Nothing to validate") if not PuzzleManager.hasPuzzleId(puzzleid): abort(404, description="PuzzleId not found") if variantid != None: variants = PuzzleManager.getPuzzleClass(puzzleid).variants if variantid not in variants: abort(404, description="VariantId not found") if position != None: try: PuzzleManager.validate(puzzleid, variantid, position) except PuzzleException as e: abort(404, description=str(e))
def test_default_path(client): rv = client.get('/') d = json.loads(rv.data) for puzzle in d['response']: assert PuzzleManager.hasPuzzleId(puzzle["gameId"])
parser.add_argument("-i", "--info", action="store_true", help="Solver reveals some helpful info") parser.add_argument("-a", "--auto", action="store_true", help="Puzzle plays itself") parser.add_argument("-l", "--list", action="store_true", help="Lists puzzles and their ids") args = parser.parse_args() if not PuzzleManager.hasPuzzleId(args.puzzleid): print("Possible puzzles:") print("\n".join(PuzzleManager.getPuzzleIds())) raise Exception("Puzzleid is not recorded in PuzzleList") p_cls = PuzzleManager.getPuzzleClass(args.puzzleid) puzzle = None if args.variant: puzzle = p_cls.generateStartPosition(args.variant) if args.position: puzzle = p_cls.deserialize(args.position) if not puzzle: puzzle = p_cls() if args.info or args.auto: