def test_routine_serialization(self): routine = Routine("My routine") task1 = Task("Task 1") task1.register_argument("arg1", arg_type.integer(minimum=0)) task2 = Task("Task 2") task2.register_argument("arg1", arg_type.choice("Yes", "No")) task2.register_argument("arg2", arg_type.integer(maximum=909)) routine.add_task(task1, {"arg1": 10}) routine.add_task(task2, {"arg1": "Yes", "arg2": 700}) serialized = serial.serialize_routine(routine) self.assertDictEqual( serialized, { "name": "My routine", "tasks": [{ "name": "Task 1", "values": { "arg1": 10 }, }, { "name": "Task 2", "values": { "arg1": "Yes", "arg2": 700 } }] })
def test_override_argument(self): arg_type_1 = {"type": "the argument type"} arg_type_2 = {"type": "an other argument type", "other": "value"} task = Task("o") task.register_argument("name", arg_type_1) task.register_argument("name", arg_type_2) self.assertEqual(len(task.arguments), 1) self.assertDictEqual(task.arguments["name"], arg_type_2)
def add_task(): incoming = request.get_json() task = incoming.get('task') try: Task.add_task(task) return jsonify({'success': True}), 200 except IntegrityError: return jsonify({'success': False}), 403
def test_add_multiple_correct_arguments(self): arg_type_1 = {"type": "the argument type"} arg_type_2 = {"type": "an other argument type", "other": "value"} task = Task("a") self.assertEqual(len(task.arguments), 0) task.register_argument("firstArg", arg_type_1) self.assertEqual(len(task.arguments), 1) self.assertDictEqual(task.arguments["firstArg"], arg_type_1) task.register_argument("secondArg", arg_type_2) self.assertEqual(len(task.arguments), 2) self.assertDictEqual(task.arguments["secondArg"], arg_type_2)
def test_empty_name(self): with self.assertRaises(AssertionError): Task("")
def test_non_empty_name(self): task = Task("Test task") self.assertEqual(task.name, "Test task")
def test_add_malformed_argument(self): task = Task("a") with self.assertRaises(AssertionError): task.register_argument("arg1", {})
def setUp(self): self.manager = Manager() self.task = Task("the task") self.routine = Routine("the routine") self.card = Card("the card id", "the card name")
def test_override_task(self): other_task = Task("the task") self.manager.register_task(self.task) self.manager.register_task(other_task) self.assertEqual(len(self.manager.tasks), 1) self.assertIs(other_task, self.manager.tasks["the task"])
#from api.resources import Resource from api.task import Task from api.user import User #from api.advice import Advice import falcon def generic_error_handler(ex, req, resp, params): if isinstance(ex, falcon.HTTPNotFound): raise falcon.HTTPNotFound(description='Not Found') elif isinstance(ex, falcon.HTTPMethodNotAllowed): raise falcon.HTTPMethodNotAllowed(falcon.HTTP_405, description='Method Not Allowed') else: raise app = falcon.API( # middleware=[ # AuthMiddleware() # ] ) #app.add_route('/example', Resource()) app.add_route('/task',Task()) app.add_route('/user',User()) #app.add_route('/advice",Advice()) app.add_error_handler(Exception, generic_error_handler)
def setUp(self) -> None: self.manager = Manager() self.t = Task("a task") self.t.register_argument("first arg", string(min_length=4)) self.manager.register_task(self.t)
class TestDiskDeserializers(unittest.TestCase): def setUp(self) -> None: self.manager = Manager() self.t = Task("a task") self.t.register_argument("first arg", string(min_length=4)) self.manager.register_task(self.t) def test_routine_deserialize(self): serialized_routine = { "name": "A simple routine", "tasks": [{ "name": "a task", "values": { "first arg": "my string" } }] } r = des.deserialize_routine(serialized_routine, self.manager) self.assertIsNotNone(r) self.assertEqual(r.name, "A simple routine") self.assertEqual(len(r.tasks), 1) t, values = r.tasks[0] self.assertEqual(self.t, t) self.assertDictEqual(values, {"first arg": "my string"}) def test_routine_deserialize_invalid_value(self): serialized_routine = { "name": "A simple routine", "tasks": [{ "name": "a task", "values": { "first arg": "bad" } }] } r = des.deserialize_routine(serialized_routine, self.manager) self.assertIsNotNone(r) self.assertEqual(len(r.tasks), 0) def test_routine_deserialize_missing_task(self): serialized_routine = { "name": "A simple routine", "tasks": [{ "name": "a non existing task", "values": { "first arg": "my string" } }] } r = des.deserialize_routine(serialized_routine, self.manager) self.assertIsNotNone(r) self.assertEqual(len(r.tasks), 0) def test_routine_deserialize_missing_arg_value(self): serialized_routine = { "name": "A simple routine", "tasks": [{ "name": "a task", "values": {} }] } r = des.deserialize_routine(serialized_routine, self.manager) self.assertIsNotNone(r) self.assertEqual(len(r.tasks), 0) def test_routine_deserialize_wrong_format_task(self): serialized_routine = { "name": "A simple routine", "tasks": [{ "missing name": "a non existing task", "values": { "first arg": "my string" } }] } r = des.deserialize_routine(serialized_routine, self.manager) self.assertIsNotNone(r) self.assertEqual(len(r.tasks), 0) serialized_routine = { "name": "A simple routine", "tasks": [{ "name": ["Not", "a", "string"], "values": { "first arg": "my string" } }] } r = des.deserialize_routine(serialized_routine, self.manager) self.assertIsNotNone(r) self.assertEqual(len(r.tasks), 0) serialized_routine = { "name": "A simple routine", "tasks": [{ "name": "a task", "values": "not a dict" }] } r = des.deserialize_routine(serialized_routine, self.manager) self.assertIsNotNone(r) self.assertEqual(len(r.tasks), 0) def test_routine_deserialize_wrong_format(self): r = des.deserialize_routine({}, self.manager) self.assertIsNone(r) r = des.deserialize_routine({"name": 5, "tasks": []}, self.manager) self.assertIsNone(r) r = des.deserialize_routine({ "name": "ok", "tasks": None }, self.manager) self.assertIsNone(r) # noinspection PyTypeChecker r = des.deserialize_routine("An other type", self.manager) self.assertIsNone(r) def test_card_deserialize_unlinked(self): card = des.deserialize_card({ "name": "my card", "id": "the id" }, self.manager) self.assertEqual(card.name, "my card") self.assertEqual(card.id, "the id") self.assertFalse(card.is_linked()) def test_card_deserialize_linked_not_found(self): card = des.deserialize_card({ "name": "a card", "id": "an id" }, self.manager) self.assertEqual(card.name, "a card") self.assertEqual(card.id, "an id") self.assertFalse(card.is_linked()) def test_card_deserialize_linked_found(self): routine = Routine("routine name") self.manager.add_routine(routine) card = des.deserialize_card( { "name": "card name", "id": "card id", "target": "routine name" }, self.manager) self.assertTrue(card.is_linked()) self.assertEqual(card.routine_name, "routine name") def test_card_deserialize_wrong_format(self): # noinspection PyTypeChecker self.assertIsNone(des.deserialize_card([], self.manager)) self.assertIsNone(des.deserialize_card({}, self.manager)) self.assertIsNone( des.deserialize_card({ "name": 5, "id": "6546123" }, self.manager)) self.assertIsNone( des.deserialize_card({ "name": "a string", "id": { "other": "thing" } }, self.manager))
def get_all_tasks(): allTasks = Task.get_all_tasks() return jsonify(tasks=allTasks)
def setup(self): # 实例化接口,供case层使用 self.get_code = GetCode() self.login = LogIn() self.logout = LogOut() self.old_user_login = OldUserLogin() self.update_user_info = UpdateUserInfo() self.user_authorize = UserAuthorize() self.user_center = UserCenter() self.book_details = BookDetails() self.chapter = Chapter() self.last_chapter = LastChapter() self.recommended_books = RecommendedBooks() self.send_book = SendBook() self.shelf_clouds = ShelfClouds() self.recharge_list = RechargeList() self.order = Order() self.order_inform = OrderInform() self.recharge_record = RechargeRecord() self.spend_list = SpendList() self.add_desktop = AddDesktop() self.read_time = ReadTime() self.task = Task() self.read_begin = ReadBegin() self.chapter_pay = ChapterPay() self.prestrain = PresTrain() self.read_hold = ReadHold() self.app_start = AppStart() self.book_home = BookHome() self.cate_gory = CateGory() self.cate_gory_second = CateGorySecond() self.free = Free() self.free_second = FreeSecond() self.rank = Rank() self.push = Push() self.feedback = FeedBack() self.app_start_api = AppStartApi() self.front_error = FrontError() self.local_push = LocalPush() self.coupon = Coupon() self.get_coupon = GetCoupon() self.user_coupon = UserCoupon() self.position = Position() self.recharge_activity = RechargeActivity() self.sign = Sign() self.sign_in = SignIn() self.vip_activity = VipActivity() self.share_count = ShareCount() self.turntable_activity = TurntableActivity() self.get_turntable_activity = GetTruntableActivity() self.lottery = Lottery() self.manjian_activity = ManJianActivity() self.get_manjian_activity = GetManJianActivity() self.more_recharge_activity = MoreRechargeActivity() self.collect_cards = CollectCards() self.getcollect_cards = GetCollectCards() self.look = Look() self.play_up = PlayUp() self.search = Search() self.search_think = SearchThink() self.search_keywords = SearchKeyWords() self.user_system = UserSystem() self.user_system_rule = UserSystemRule() self.vivom_essage = VivoMessage() self.vivo_sub = VivoSub()