Example #1
0
 def set_run_status(self, run_id: int, status: db.TestRunStatus, traceback: Optional[str] = None) -> None:
     with db.create_session() as session:
         run: db.TestRun = session.query(db.TestRun).filter(db.TestRun.id == run_id).one()
         run.status = status
         if status is db.TestRunStatus.RUNNING:
             run.start = get_current_time()
         if status.finished:
             run.end = get_current_time()
         if isinstance(traceback, str):
             run.traceback = traceback
def test_testrun() -> TestRunModel:
    return TestRunModel(
        id=1,
        created_at=get_current_time(),
        scenario_id=1,
        name="test",
        start=get_current_time(),
        end=get_current_time(),
        executed_by="executor",
        status="SUCCESS",
        report_status="GENERATION_FAILED",
        report=None,
        traceback=None,
    )
Example #3
0
 def set_error_emulation_run(self, emulation_run_id: int,
                             traceback: str) -> None:
     with db.create_session() as session:
         emulation_run = self._get_emulation_run(session, emulation_run_id)
         emulation_run.status = db.EmulationStatus.ERROR
         emulation_run.traceback = traceback
         emulation_run.changed_at = get_current_time()
Example #4
0
 def set_emulation_run_status(self, emulation_run_id: int,
                              status: db.EmulationStatus) -> None:
     with db.create_session() as session:
         emulation_run = self._get_emulation_run(session, emulation_run_id)
         if emulation_run.status != status:
             emulation_run.status = status
             emulation_run.changed_at = get_current_time()
Example #5
0
class TestDatetimeFormatter:
    """ Unit tests for datetime_formatter. """
    @pytest.mark.parametrize(
        ("column_name", "value"),
        [("created_at", get_current_time())],
    )
    def test_created_at(
        self,
        test_table: db.BaseTable,
        test_view: ModelViewConfigured,
        mocker: MockerFixture,
        test_testrun_id: int,
        column_name: str,
        value: datetime,
    ) -> None:
        setattr(test_table, column_name, value)
        result = datetime_formatter(
            view=test_view,
            context=mocker.MagicMock(),
            model=test_table,
            name=column_name,
        )
        assert result == Markup(value.strftime("%d-%m-%Y %H:%M:%S"))

    @pytest.mark.parametrize(
        ("column_name", "value"),
        [("start", get_current_time() + timedelta(seconds=1)),
         ("end", get_current_time() + timedelta(seconds=5))],
    )
    def test_testrun_attrs(
        self,
        test_testrun_view: TestRunView,
        mocker: MockerFixture,
        test_testrun_id: int,
        column_name: str,
        value: datetime,
    ) -> None:
        result = datetime_formatter(
            view=test_testrun_view,
            context=mocker.MagicMock(),
            model=TestRun(**{
                "id": test_testrun_id,
                column_name: value
            }),  # type: ignore
            name=column_name,
        )
        assert result == Markup(value.strftime("%d-%m-%Y %H:%M:%S"))
Example #6
0
 def get_requested_emulation_run(
         self, emulation_run_id: int) -> EmulationRunModel:
     with db.create_session() as session:
         emulation_run = self._get_emulation_run(session, emulation_run_id)
         emulation_run.status = db.EmulationStatus.REQUESTED
         emulation_run.port = self._get_next_port(session)
         emulation_run.changed_at = get_current_time()
         return cast(EmulationRunModel,
                     EmulationRunModel.from_orm(emulation_run))
Example #7
0
def remove_files(name: str, days: int) -> None:
    """ Remove s3 bucket files older . """
    _check_bucket_registered(name)
    manager = _get_s3_manager()
    target_date = get_current_time() - timedelta(days=days)

    objects = manager.get_bucket_objects(name)
    objects_to_delete = []
    for obj in objects:
        if not obj.modified_at < target_date:
            continue
        objects_to_delete.append(obj)
    if not objects_to_delete:
        click.secho(f"No one object older than {days} days.")
        return
    click.secho(f"Objects older then {days} days: {[x.name for x in objects_to_delete]}")
    manager.delete_bucket_objects(bucket=bucket, objects=objects_to_delete)
def test_feature() -> FeatureModel:
    return FeatureModel(
        id=1,
        name="feature",
        author="keks",
        type_id=1,
        task=["OVERHAVE-1"],
        last_edited_by="overlord",
        released=False,
        feature_type=FeatureTypeModel(
            id=1, name=get_test_feature_extractor().feature_types[0]),
        feature_tags=[
            TagsTypeModel(id=1,
                          value="tag1",
                          created_by="qqq",
                          created_at=get_current_time())
        ],
        file_path="my_folder/my_feature",
    )
Example #9
0
def test_bucket_creation_date() -> datetime:
    return get_current_time()