def setUp(self): super(TestTasks, self).setUp() self.resource_name = 'task' self.resources_uri = self.root_uri + 'projects/1/sprints/1/stories/1/tasks' self.single_resource_uri = self.resources_uri + '/1' self.example_resource = Task(nr=1, description='some description', comment='some comment', status=1, progress=50, completion_date=None, owner=1, story_id=1, assigned_devs=[], id_=2) self.update_resource = Task(nr=7, description='some updated description', comment='some updated comment', status=2, progress=100, completion_date=None, owner=2, story_id=1, assigned_devs=[], id_=2)
def testServiceVisitWithOneTaskThatDoesNotHaveTheSpecifiedId(self): task1 = Task("task a") task2 = Task("task b") visit = ServiceVisit("name", "address", "customer", [task1]) with self.assertRaises(ValueError): visit.getTaskById(task2.getTaskId())
def testAddValidTaskToServiceVisitWithSomeTasks(self): task1 = Task("task a") visit = ServiceVisit("name", "address", "description", [task1]) task2 = Task("task b") visit.addTask(task2) self.assertEqual(2, len(visit.getTasks()), "checking number of tasks") self.assertTrue(task1 in visit.getTasks(), "checking for pre-existing task") self.assertTrue(task2 in visit.getTasks(), "checking for task added")
def testServiceVisitWithMultipleTasksAndLastHasSpecifiedId(self): task1 = Task("task a") task2 = Task("task b") task3 = Task("task c") visit = ServiceVisit("name", "address", "customer", [task1, task2, task3]) result = visit.getTaskById(task3.getTaskId()) self.assertEqual(task3, result, "checking result")
def game(): """ start (path with dialog) / \ w1 (m1) w2 (d1) \ / knot1 / | \ w3 w4 w5 <- with task t1,t2,t3 \ | end <- task from dialog td1 :return: game with described graph """ #TODO, check interaction model in waypoint dialog = Dialog() dialog_start = Mail(dialog.graph, 'start sub', 'start body') m1 = Mail(dialog.graph, 'second sub', 'second body') td1 = Task(None, 'some task 1', 'some task', 'some solution') d1 = Speech(dialog.graph, 'content', task=td1) game = Game('test') start = Waypoint(game.graph, 'start') w1 = Waypoint(game.graph, 'w1') w2 = Waypoint(game.graph, 'w2') knot = Waypoint(game.graph, 'knot') w3 = Waypoint(game.graph, 'w3') t1 = Task(w3, 'some task 1', 'some task') w4 = Waypoint(game.graph, 'w4') t2 = Task(w4, 'some task 2', 'some task') w5 = Waypoint(game.graph, 'w5') t3 = Task(w5, 'some task 3', 'some task') end = Waypoint(game.graph, 'end') start.add_destination(w1, 1.1) start.add_destination(w2) w1.add_destination(knot) w2.add_destination(knot) knot.add_task(t1) knot.add_task(t2) knot.add_task(t3) w3.add_destination(end) w4.add_destination(end) game.set_start(start) dialog_end = Speech(dialog.graph, 'next content', destination=end) dialog.set_start(dialog_start) dialog_start.add_follow_up(d1) dialog_start.add_follow_up(m1) dialog_start.waypoints.append(start) d1.add_follow_up(dialog_end, None) game.add_non_playable_character(NonPlayableCharacter( 'bob', 'test', dialog)) return game
def dispatchIncomingMessage(self, message): messageType = message.header.messageType task = Task(taskType=messageType, stale=False, uuid=message.header.uuid, data=message.data) if messageType in self.__INSTANT_TASK_TYPES: if messageType == MessageTypes.DELETE_FILE: path = message.data["fullPath"] self.__longFileTaskArchive.cancelTask(path) self.__longFileTaskArchive.removeTask(path) elif messageType == MessageTypes.MOVE_FILE: self.__longFileTaskArchive.cancelTask(message.data["source"]) self.__longFileTaskArchive.cancelTask(message.data["target"]["fullPath"]) self.__longFileTaskArchive.removeTask(message.data["source"]) self.__longFileTaskArchive.removeTask(message.data["target"]["fullPath"]) self.incoming_instant_task_queue.put(task) elif messageType in self.__SLOW_TASK_TYPES: key = task.data["fullPath"] self.__longFileTaskArchive.addTask(key, task) self.incoming_task_queue.put(task) elif messageType == MessageTypes.FILE_TASK_CANCELLED: self._logger.debug(f"Cancelling task for file: {message.data['fullPath']}") self.__longFileTaskArchive.cancelTask(message.data["fullPath"]) self.__longFileTaskArchive.removeTask(message.data["fullPath"]) else: self._logger.warning(f"Unknown message: {message}")
def test_upload_writes_iv_and_encrypts_file_data(self, mockDropbox, mockUploadCursor): uploadSessionStarter = MagicMock() uploadSessionAppender = MagicMock() mockDropbox.return_value.files_upload_session_start = uploadSessionStarter mockDropbox.return_value.files_upload_session_finish = uploadSessionAppender testSecretData = b"secret test data" testFileHandle = BytesIO(testSecretData) testPartName = "testFile__1__1.enc" testClientModified = datetime.datetime(2020, 1, 1, 10, 5, 30) testFileData = { "userTimezone": "+0200", "utcModified": testClientModified.timestamp(), "path": "subDir" } testTask = Task(taskType=MessageTypes.UPLOAD_FILE, data=testFileData) cloudAccount = DropboxAccountWrapper(self.testAccountData) result = cloudAccount.upload(testFileHandle, len(testSecretData), testPartName, testTask) cipher = AES.new(self.testAccountData.cryptoKey.encode(), AES.MODE_CFB, iv=uploadSessionStarter.call_args[0][0]) encoded = mockDropbox.return_value.files_upload_session_finish.call_args[ 0][0] self.assertNotEqual(encoded, testSecretData) self.assertEqual(cipher.decrypt(encoded), testSecretData)
def test_download_file_does_nothing_if_task_is_stale(self, mockRequest): secretData = b"secret test data" testEncoder = AES.new(self.testAccountData.cryptoKey.encode(), AES.MODE_CFB) testIV = testEncoder.iv ivResponse = MagicMock() ivResponse.content = testIV encryptedDataResponse = MagicMock() encryptedDataResponse.content = testEncoder.encrypt(secretData) mockRequest.side_effect = [ivResponse, encryptedDataResponse] testDownloadFileHandle = BytesIO() testFilePartInfo = FilePart( filename="apple.txt__1__1.enc", modified=int( datetime.datetime(2020, 1, 1, 10, 10, 30).timestamp()), size=len(encryptedDataResponse.content) + len(testIV), path="", fullPath="apple.txt__1__1.enc", storingAccountID=self.testAccountData.id, extraInfo={}) testDownloadFileTask = Task(taskType=MessageTypes.DOWNLOAD_FILE, stale=True) cloudAccount = DropboxAccountWrapper(self.testAccountData) cloudAccount.download(testDownloadFileHandle, testFilePartInfo, testDownloadFileTask) testDownloadFileHandle.seek(0) self.assertEqual(b"", testDownloadFileHandle.read())
def test_upload_does_nothing_if_task_is_stale(self, mockDropbox, mockUploadCursor): uploadSessionStarter = MagicMock() uploadSessionAppender = MagicMock() mockDropbox.return_value.files_upload_session_start = uploadSessionStarter mockDropbox.return_value.files_upload_session_finish = uploadSessionAppender testSecretData = b"secret test data" testFileHandle = BytesIO(testSecretData) testPartName = "testFile__1__1.enc" testClientModified = datetime.datetime(2020, 1, 1, 10, 5, 30) testFileData = { "userTimezone": "+0200", "utcModified": testClientModified.timestamp(), "path": "subDir" } testTask = Task(taskType=MessageTypes.UPLOAD_FILE, data=testFileData, stale=True) cloudAccount = DropboxAccountWrapper(self.testAccountData) result = cloudAccount.upload(testFileHandle, len(testSecretData), testPartName, testTask) self.assertEqual(uploadSessionStarter.call_count, 0) self.assertEqual(uploadSessionAppender.call_count, 0) self.assertIsNone(result)
def testValidMaterialProvidedToTaskWithNoMaterials(self): task = Task("task a") task.addMaterial("splitter") self.assertEqual(1, len(task.getMaterials()), "checking number of materials") self.assertTrue("splitter" in task.getMaterials(), "checking for material added")
def __init__(self, config): self.config = config self.score_dir = config.get_argv().score_file self.benchmark_config = config.get_argv().benchmark_config self.task = Task(config) self.workspace = Workspace(config) self.ssh_user = config.get_value('User', 'SSH') self.ssh_passwd_file = config.get_value('PasswdFile', 'SSH') self.ssh_port = config.get_value('Port', 'SSH') self.subnet_ip = config.get_value('ip', 'Subnet') self.subnet_name = config.get_value('name', 'Subnet') self.mode = config.get_value('Mode') self.pwd = os.path.dirname(__file__) self.mq_tag = str(time.time()).replace('.', '_') self._benchmark_pressure_tag_id = None self.logs_dir = os.path.join(self.pwd, '../logs/') self.logger = logging.getLogger(__name__) self.lockfile = self.__lockfile() self.logger.setLevel(logging.DEBUG) handler = logging.FileHandler("log.txt") handler.setLevel(logging.DEBUG) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) self.logger.addHandler(handler)
def parse(self, task: Task, content: str): data = json.loads(content) if data['code'] != 200: raise Exception(f'Failed to parse response {content}') content = data['content'] keyword = content['keyword'] news_items = content.get('results', []) need_next_page = False items = [] for news_item in news_items: item = XinHuaNewsItem() item.url = news_item['url'] item.keyword = keyword item.title = news_item['title'] item.abstract = news_item['des'] item.publish = datetime.datetime.strptime(news_item['pubtime'], '%Y-%m-%d %H:%M:%S') items.append(item) if item.publish >= config.BEGIN_DATE: need_next_page = True if need_next_page: params = task.params params['curPage'] += 1 yield Task(task.url, '', '', params=params, metadata=task.metadata) for item in items: yield item
def test_comment_parser(): with open('./test_files/shop_reviews.html', 'r') as html_file: data = html_file.read() url = 'https://www.dianping.com/shop/90556783/review_all' task = Task(url, '', '') parser = get_parser(url) _parse(parser, task, data)
def test_create_and_delete_game(wait_for_api, create_clean_db, client): # create our game game = Game('test') start = Waypoint(game.graph, 'start') w1 = Waypoint(game.graph, 'w1') w2 = Waypoint(game.graph, 'w2', items=['some item']) end = Waypoint(game.graph, 'end') start.add_destination(w1) task = Task(w2, 'test description', 'test text', 'answer') w1.add_task(task) w2.add_destination(end) game.set_start(start) # create user lg = client.post( f"{ROOT_URL}/register", json=default_account ) assert lg.status_code == 201 token = json.loads(lg.data) # convert it to an API object game_data = generate_api_game(game) lg = client.post( f"{ROOT_URL}/games", json=game_data, headers={'X-TOKEN': token} ) assert lg.status_code == 201 lg = client.get( f"{ROOT_URL}/games" ) assert lg.status_code == 200 assert game.title in [g['title'] for g in lg.data]
def testValidDescriptionProvided(self): task = Task("task a") task.setDescription("task b") self.assertEqual("task b", task.getDescription(), "checking description")
def test_handler_retrieves_accounts_from_database_and_sends_response( self, dispatchResponseMock): testAccounts = [ AccountData(id=1, identifier="testAccountID", accountType=AccountTypes.Dropbox, cryptoKey="sixteen byte key", data={"apiToken": "testApitoken"}) ] testTask = Task(taskType=MessageTypes.GET_ACCOUNT_LIST, uuid=uuid4().hex) self.fakeDB.getAllAccounts.return_value = testAccounts self.testHandler.setTask(testTask) self.testHandler.handle() self.assertEqual(self.fakeDB.getAllAccounts.call_count, 1) self.assertEqual(dispatchResponseMock.call_count, 1) self.assertEqual( dispatchResponseMock.call_args[0][0].header.messageType, MessageTypes.RESPONSE) self.assertEqual(dispatchResponseMock.call_args[0][0].header.uuid, testTask.uuid) self.assertEqual( type(dispatchResponseMock.call_args[0][0].data["accounts"]), list) self.assertEqual( len(dispatchResponseMock.call_args[0][0].data["accounts"]), len(testAccounts)) self.assertEqual( dispatchResponseMock.call_args[0][0].data["accounts"][0], testAccounts[0].serialize())
def update_task(id_task): if request.method == "POST": # query for check id task query_db = db.read("tasks", "id", id_task) task = query_db[0] if len(query_db) == 1 else None if task == None: return jsonify(error(404, "Task not exists")) else: json = request.get_json() id = task["id"] title = json["title"] description = json["description"] date = task["date"] id_list = task["id_list"] status = json["status"] task = Task( id=id, id_list=id_list, title=title, description=description, date=date, status=status, ) if db.update("tasks", id_task, task.to_dict()): return jsonify(task.to_dict()) else: return jsonify(error(203, "Not Allowed"))
def testValidMaterialProvidedToTaskWithOneMaterial(self): task = Task("task a", materials=["splitter"]) task.removeMaterial("splitter") self.assertEqual(0, len(task.getMaterials()), "checking number of materials")
def testServiceVisitWithOneTaskWithSpecifiedId(self): task1 = Task("task a") visit = ServiceVisit("name", "address", "customer", [task1]) result = visit.getTaskById(task1.getTaskId()) self.assertEqual(task1, result, "checking result")
def set_step_completed_in_progress_ini(self, stack, step): """ Look up the lookup up from the step. Check if the stack already exists, if not, insert, otherwise, update Args: stack: string of the stack you are working on step: current step Returns: nothing, just merges """ try: lookup = self.session.query(ProgressLookup)\ .filter(ProgressLookup.original_step == step)\ .order_by(ProgressLookup.original_step.desc())\ .limit(1).one() except NoResultFound: print('No lookup for {} so we will enter one.'.format(step)) try: task = self.session.query(Task).filter(Task.lookup_id == lookup.id)\ .filter(Task.prep_id == stack).one() except NoResultFound: print('No step for {}'.format(step)) task = Task(stack, lookup.id, True) try: self.session.merge(task) self.session.commit() except: print('Bad lookup code for {}'.format(lookup.id)) self.session.rollback()
def testValidStatusProvided(self): task = Task("task a") task.setStatus(TaskStatus.COMPLETE) self.assertEqual(TaskStatus.COMPLETE, task.getStatus(), "checking status")
def createtasks(tasklistinput): """ Creates one class Task for every task in the input file. :param tasklistinput: Tasks from the input file. :return: List of classes Task. """ tasklist = [] for taskinput in tasklistinput: if "dependencies" in taskinput: task = Task(taskinput["name"], taskinput["type"], taskinput["arguments"], taskinput["dependencies"]) else: task = Task(taskinput["name"], taskinput["type"], taskinput["arguments"], None) tasklist.append(task) return tasklist
def set_task(self, list_task): self.m_dictTasks = dict() for task in list_task: if task["taskstate"] == "1": t = Task() t.handle_info(task) self.m_dictTasks[t.type] = t
def add_gov_tasks(scheduler: Scheduler): for keyword in config.KEYWORDS: search_key = urllib.parse.quote(keyword) url = f'http://sousuo.gov.cn/s.htm?t=govall&q={search_key}' metadata = { 'keyword': keyword, } scheduler.append_request_task(Task(url, '', '', metadata=metadata))
def add_weibo_topic_list_tasks(scheduler: Scheduler): for keyword in config.KEYWORDS: search_key = urllib.parse.quote(keyword) url = f'https://s.weibo.com/topic?q={search_key}&pagetype=topic&topic=1&Refer=weibo_topic' metadata = { 'keyword': keyword, } scheduler.append_request_task(Task(url, '', '', metadata=metadata))
def create_task(): r_p = randint(DefaultData.R_PROCESSING_BOUND[0], DefaultData.R_PROCESSING_BOUND[1]) r_s = randint(DefaultData.R_STORAGE_BOUND[0], DefaultData.R_STORAGE_BOUND[1]) q_p = randint(DefaultData.Q_PROCESSING_BOUND[0], DefaultData.Q_PROCESSING_BOUND[1]) q_s = randint(DefaultData.Q_STORAGE_BOUND[0], DefaultData.Q_STORAGE_BOUND[1]) label = 0 if uniform() < 0.5 else 1 sl_max = randint(DefaultData.SERVICE_LATENCY_MAX[0], DefaultData.SERVICE_LATENCY_MAX[1]) return Task(r_p, r_s, q_p, q_s, label, sl_max)
def save_task(): try: task = Task(request.json.get("nome"), request.json.get("descricao"), 'aberto') #request.json.get("status")) task.save() return {'sucess': True, 'erro': False, 'response': task.json()} except Exception as e: return {'sucess': False, 'erro': True, 'response': str(e)}
def testValidDescriptionAndStatusAndNonEmptyListOfMaterialsProvided(self): result = Task("task a", TaskStatus.COMPLETE, ["splitter", "coax"]) self.assertEquals("task a", result.getDescription(), "checking description") self.assertEquals(TaskStatus.COMPLETE, result.getStatus(), "checking status") self.assertEquals(2, len(result.getMaterials()), "checking number of materials") self.assertEquals("splitter", result.getMaterials()[0], "checking first material") self.assertEquals("coax", result.getMaterials()[1], "checking second material")
def testValidMaterialProvidedToTaskWithSomeMaterials(self): task = Task("task a", materials=["splitter"]) task.addMaterial("coax") self.assertEqual(2, len(task.getMaterials()), "checking number of materials") self.assertTrue("splitter" in task.getMaterials(), "checking for existing material") self.assertTrue("coax" in task.getMaterials(), "checking for material added")
def testAddValidTaskToServiceVisitWithNoTasks(self): visit = ServiceVisit("name", "address", "description") task = Task("task a") visit.addTask(task) self.assertEqual(1, len(visit.getTasks()), "checking number of tasks") self.assertTrue(task in visit.getTasks(), "checking for task added")