def test_simple(self): user = self.create_user() repo = self.create_repo() app = self.create_app(repository=repo) task = self.create_task(app=app, user=user) db.session.commit() workspace = Workspace(path=repo.get_path(), ) vcs_backend = vcs.get( repo.vcs, url=repo.url, workspace=workspace, ) if vcs_backend.exists(): vcs_backend.update() else: vcs_backend.clone() celery.apply("freight.execute_task", task_id=task.id) db.session.expire_all() assert task.date_started is not None assert task.date_finished is not None assert task.status == TaskStatus.finished logchunks = list( LogChunk.query.filter(LogChunk.task_id == task.id, ).order_by( LogChunk.offset.asc())) assert len(logchunks) >= 1 all_text = ''.join(c.text for c in logchunks) assert ">> Running ['/bin/echo', 'helloworld']" in all_text
def test_with_pending_task(self, mock_send, mock_queue_get): user = self.create_user() repo = self.create_repo() app = self.create_app(repository=repo) task = self.create_task( app=app, user=user, status=TaskStatus.pending, ) db.session.commit() pending = [{ 'task': str(task.id), 'type': 'dummy', 'config': {'foo': 'bar'}, 'event': NotifierEvent.TASK_STARTED, }] mock_queue_get.side_effect = lambda: maybe_pop(pending) celery.apply("freight.send_pending_notifications") mock_send.assert_called_once_with( task=task, config={'foo': 'bar'}, event=NotifierEvent.TASK_STARTED, ) assert mock_queue_get.mock_calls == [ call(), call(), ]
def test_with_pending_task(self, mock_send, mock_queue_get): user = self.create_user() repo = self.create_repo() app = self.create_app(repository=repo) task = self.create_task( app=app, user=user, status=TaskStatus.pending, ) db.session.commit() pending = [{ 'task': str(task.id), 'type': 'dummy', 'config': { 'foo': 'bar' }, 'event': NotifierEvent.TASK_STARTED, }] mock_queue_get.side_effect = lambda: maybe_pop(pending) celery.apply("freight.send_pending_notifications") mock_send.assert_called_once_with( task=task, config={'foo': 'bar'}, event=NotifierEvent.TASK_STARTED, ) assert mock_queue_get.mock_calls == [ call(), call(), ]
def test_delete_app(self): user = self.create_user() repo = self.create_repo() app = self.create_app(repository=repo) task = self.create_task(app=app, user=user) celery.apply("freight.delete_object", model='App', object_id=app.id) db.session.expire_all() assert Task.query.filter(Task.app_id == app.id).count() == 0 assert not App.query.get(app.id)
def test_without_pending_task(self, mock_send_task): user = self.create_user() repo = self.create_repo() app = self.create_app(repository=repo) task = self.create_task( app=app, user=user, status=TaskStatus.in_progress, ) db.session.commit() celery.apply("freight.check_queue") assert not mock_send_task.called
def test_with_pending_task(self, mock_send_task): user = self.create_user() repo = self.create_repo() app = self.create_app(repository=repo) task = self.create_task( app=app, user=user, status=TaskStatus.pending, ) db.session.commit() celery.apply("freight.check_queue") mock_send_task.assert_called_once_with('freight.execute_task', [task.id])
def test_simple(self): user = self.create_user() repo = self.create_repo() app = self.create_app(repository=repo) task = self.create_task(app=app, user=user) db.session.commit() workspace = Workspace( path=repo.get_path(), ) vcs_backend = vcs.get( repo.vcs, url=repo.url, workspace=workspace, ) if vcs_backend.exists(): vcs_backend.update() else: vcs_backend.clone() celery.apply("freight.execute_task", task_id=task.id) db.session.expire_all() assert task.date_started is not None assert task.date_finished is not None assert task.status == TaskStatus.finished logchunks = list(LogChunk.query.filter( LogChunk.task_id == task.id, ).order_by(LogChunk.offset.asc())) assert len(logchunks) >= 1 all_text = ''.join(c.text for c in logchunks) assert ">> Running ['/bin/echo', 'helloworld']" in all_text