示例#1
0
    def test_inprogress_pending_task(self, mock_push):
        user = self.create_user()
        repo = self.create_repo()

        app_1 = self.create_app(repository=repo)
        deploy_config_1 = self.create_taskconfig(app=app_1)
        task_1 = self.create_task(app=app_1,
                                  user=user,
                                  status=TaskStatus.in_progress)
        deploy_1 = self.create_deploy(app=app_1, task=task_1)
        db.session.commit()

        queue.apply("freight.jobs.check_queue")

        assert not mock_push.called

        app_2 = self.create_app(repository=repo)
        deploy_config_2 = self.create_taskconfig(app=app_2)
        task_2 = self.create_task(app=app_2,
                                  user=user,
                                  status=TaskStatus.pending)
        deploy_2 = self.create_deploy(app=app_2, task=task_2)
        db.session.commit()

        queue.apply("freight.jobs.check_queue")

        mock_push.assert_called_once_with("freight.jobs.execute_deploy",
                                          [deploy_2.id])
示例#2
0
    def test_inprogress_pending_task(self, mock_push):
        user = self.create_user()
        repo = self.create_repo()

        app_1 = self.create_app(repository=repo)
        deploy_config_1 = self.create_taskconfig(app=app_1)
        task_1 = self.create_task(
            app=app_1, user=user, status=TaskStatus.in_progress,
        )
        deploy_1 = self.create_deploy(
            app=app_1, task=task_1,
        )
        db.session.commit()

        queue.apply('freight.jobs.check_queue')

        assert not mock_push.called

        app_2 = self.create_app(repository=repo)
        deploy_config_2 = self.create_taskconfig(app=app_2)
        task_2 = self.create_task(
            app=app_2, user=user, status=TaskStatus.pending,
        )
        deploy_2 = self.create_deploy(
            app=app_2, task=task_2,
        )
        db.session.commit()

        queue.apply('freight.jobs.check_queue')

        mock_push.assert_called_once_with('freight.jobs.execute_deploy', [deploy_2.id])
    def test_simple(self):
        user = self.create_user()
        repo = self.create_repo()
        app = self.create_app(repository=repo)
        self.create_taskconfig(app=app)
        task = self.create_task(app=app, user=user)
        deploy = self.create_deploy(app=app, task=task)
        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()

        queue.apply("freight.jobs.execute_deploy", kwargs={"deploy_id": deploy.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)
        self.create_taskconfig(app=app)
        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)

        queue.apply('freight.jobs.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(),
        ]
示例#5
0
    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)
        self.create_taskconfig(app=app)
        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)

        queue.apply("freight.jobs.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)
        self.create_taskconfig(app=app)
        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)

        queue.apply('freight.jobs.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(),
        ]
示例#7
0
    def test_without_pending_task(self, mock_push):
        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()

        queue.apply('freight.jobs.check_queue')

        assert not mock_push.called
示例#8
0
    def test_with_pending_task(self, mock_push):
        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()

        queue.apply('freight.jobs.check_queue')

        mock_push.assert_called_once_with('freight.jobs.execute_task', [task.id])
示例#9
0
    def test_with_pending_task(self, mock_push):
        user = self.create_user()
        repo = self.create_repo()
        app = self.create_app(repository=repo)
        deploy_config = self.create_taskconfig(app=app)
        task = self.create_task(app=app, user=user, status=TaskStatus.pending)
        deploy = self.create_deploy(app=app, task=task)
        db.session.commit()

        queue.apply("freight.jobs.check_queue")

        mock_push.assert_called_once_with("freight.jobs.execute_deploy",
                                          [deploy.id])
示例#10
0
    def test_without_pending_task(self, mock_push):
        user = self.create_user()
        repo = self.create_repo()
        app = self.create_app(repository=repo)
        deploy_config = self.create_taskconfig(app=app)
        task = self.create_task(app=app,
                                user=user,
                                status=TaskStatus.in_progress)
        deploy = self.create_deploy(app=app, task=task)
        db.session.commit()

        queue.apply("freight.jobs.check_queue")

        assert not mock_push.called
示例#11
0
    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)

        queue.apply('freight.jobs.delete_object', kwargs={
            '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)
示例#12
0
    def test_delete_app(self):
        user = self.create_user()
        repo = self.create_repo()
        app = self.create_app(repository=repo)
        deploy_config = self.create_taskconfig(app=app)
        task = self.create_task(app=app, user=user)

        queue.apply('freight.jobs.delete_object', kwargs={
            '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_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)

        queue.apply("freight.jobs.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()]
示例#14
0
    def test_simple(self):
        user = self.create_user()
        repo = self.create_repo()
        app = self.create_app(repository=repo)
        self.create_taskconfig(app=app)
        task = self.create_task(app=app, user=user)
        deploy = self.create_deploy(app=app, task=task)
        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()

        queue.apply('freight.jobs.execute_deploy', kwargs={'deploy_id': deploy.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