Пример #1
0
    def test_model_run_list_core(self):
        model = Model.new(session=self.session,
                          reference_id='test_model',
                          project_id=self.project.id,
                          member_created_id=self.member.id,
                          add_to_session=True,
                          flush_session=True)
        model_run = ModelRun.new(session=self.session,
                                 reference_id='test_model_run__a',
                                 project_id=self.project.id,
                                 member_created_id=self.member.id,
                                 model_id=model.id,
                                 add_to_session=True,
                                 flush_session=True)
        model_run2 = ModelRun.new(session=self.session,
                                  reference_id='test_model_run__b',
                                  project_id=self.project.id,
                                  member_created_id=self.member.id,
                                  model_id=model.id,
                                  add_to_session=True,
                                  flush_session=True)
        result, log = model_run_list_core(session=self.session,
                                          log=regular_log.default(),
                                          project_id=self.project.id)

        self.assertIsNot(result, False)
        self.assertEqual(len(result), 2)
        self.assertIsNotNone(result[0].get('id'))
        self.assertIsNotNone(result[0].get('model_id'))
        self.assertIsNotNone(result[0].get('member_created_id'))
        self.assertIsNotNone(result[0].get('project_id'))
        self.assertIsNotNone(result[0].get('created_time'))
        ids = [m['id'] for m in result]
        for m in [model_run, model_run2]:
            self.assertTrue(m.id in ids)
Пример #2
0
    def check_instances_and_create_new_models(self, use_reference_ids=True):
        """
            This function will go through the instance list, and based on the model run
            reference or the DB ID, create the non existent models and model runs.
        :return: tuple (list of created models, list of created runs)
        """
        create_models = []
        created_runs = []
        for instance in self.instance_list:
            if instance.get('model_ref') is None and instance.get(
                    'model_id') is None:
                continue

            model_ref = instance.get('model_ref')
            model_id = instance.get('model_id')
            if use_reference_ids:
                model = Model.get_by_reference_id(self.session,
                                                  reference_id=model_ref,
                                                  project_id=self.project.id)
            else:
                model = Model.get_by_id(session=self.session, id=model_id)

            if model is None:
                # Create the new Model if it does not exists.
                model = Model.new(
                    session=self.session,
                    reference_id=model_ref,
                    project_id=self.project.id,
                    member_created_id=self.member.id if self.member else None)
                create_models.append(model)
            instance['model_id'] = model.id
            model_run_ref = instance.get('model_run_ref')
            if model_run_ref:
                if use_reference_ids:
                    model_run = ModelRun.get_by_reference_id(
                        self.session,
                        reference_id=model_run_ref,
                        model_id=model.id)
                else:
                    model_run = ModelRun.get_by_id(
                        self.session, id=instance.get('model_run_id'))
                if model_run is None:
                    # Create the new Model Run
                    model_run = ModelRun.new(session=self.session,
                                             reference_id=model_run_ref,
                                             project_id=self.project.id,
                                             model_id=model.id,
                                             member_created_id=self.member.id
                                             if self.member else None)
                    created_runs.append(model_run)
                instance['model_run_id'] = model_run.id
        print('RESULT', created_runs, create_models)
        return create_models, created_runs
Пример #3
0
    def test_model_run_list_web(self):
        model = Model.new(session=self.session,
                          reference_id='test_model',
                          project_id=self.project.id,
                          member_created_id=self.member.id,
                          add_to_session=True,
                          flush_session=True)
        model_run = ModelRun.new(session=self.session,
                                 reference_id='test_model_run__a',
                                 project_id=self.project.id,
                                 member_created_id=self.member.id,
                                 model_id=model.id,
                                 add_to_session=True,
                                 flush_session=True)
        model_run2 = ModelRun.new(session=self.session,
                                  reference_id='test_model_run__b',
                                  project_id=self.project.id,
                                  member_created_id=self.member.id,
                                  model_id=model.id,
                                  add_to_session=True,
                                  flush_session=True)
        request_data = {}

        auth_api = common_actions.create_project_auth(project=self.project,
                                                      session=self.session)
        credentials = b64encode(
            "{}:{}".format(auth_api.client_id,
                           auth_api.client_secret).encode()).decode('utf-8')

        endpoint = "/api/v1/project/{}/model-runs/list".format(
            self.project.project_string_id)
        response = self.client.post(endpoint,
                                    data=json.dumps(request_data),
                                    headers={
                                        'directory_id':
                                        str(self.project.directory_default_id),
                                        'Authorization':
                                        'Basic {}'.format(credentials)
                                    })
        data = response.json
        self.assertIsNotNone(data.get('model_run_list'))
        self.assertEqual(len(data.get('model_run_list')), 2)
        self.assertIsNotNone(data.get('model_run_list')[0].get('id'))
        self.assertIsNotNone(data.get('model_run_list')[0].get('created_time'))
        self.assertIsNotNone(data.get('model_run_list')[0].get('model_id'))
        self.assertIsNotNone(
            data.get('model_run_list')[0].get('member_created_id'))
        self.assertIsNotNone(data.get('model_run_list')[0].get('project_id'))
        ids = [m['id'] for m in data.get('model_run_list')]
        for m in [model_run, model_run2]:
            self.assertTrue(m.id in ids)
Пример #4
0
    def test_get_by_id(self):
        model = Model.new(session=self.session,
                          reference_id='test_model_2',
                          project_id=self.project.id,
                          member_created_id=self.member.id,
                          add_to_session=True,
                          flush_session=True)
        model_run = ModelRun.new(session=self.session,
                                 reference_id='test_model_run_2',
                                 project_id=self.project.id,
                                 member_created_id=self.member.id,
                                 add_to_session=True,
                                 model_id=model.id,
                                 flush_session=True)

        model_run2 = ModelRun.get_by_id(self.session, model_run.id)
        self.assertEqual(model_run.id, model_run2.id)
        self.assertEqual(model_run.reference_id, model_run2.reference_id)
Пример #5
0
    def test_list(self):
        model = Model.new(session=self.session,
                          reference_id='test_model_4',
                          project_id=self.project.id,
                          member_created_id=self.member.id,
                          add_to_session=True,
                          flush_session=True)
        model_run1 = ModelRun.new(session=self.session,
                                  reference_id='test_model_run_4',
                                  project_id=self.project.id,
                                  member_created_id=self.member.id,
                                  add_to_session=True,
                                  model_id=model.id,
                                  flush_session=True)
        model_run2 = ModelRun.new(session=self.session,
                                  reference_id='test_model_run_5',
                                  project_id=self.project.id,
                                  member_created_id=self.member.id,
                                  add_to_session=True,
                                  model_id=model.id,
                                  flush_session=True)

        model_run3 = ModelRun.new(session=self.session,
                                  reference_id='test_model_run_6',
                                  project_id=self.project.id,
                                  member_created_id=self.member.id,
                                  add_to_session=True,
                                  model_id=model.id,
                                  flush_session=True)

        models = ModelRun.list(session=self.session,
                               project_id=self.project.id,
                               model_id=model.id)

        id_list = [m.id for m in models]

        self.assertTrue(model_run1.id in id_list)
        self.assertTrue(model_run2.id in id_list)
        self.assertTrue(model_run3.id in id_list)
Пример #6
0
    def test_new(self):
        model = Model.new(session=self.session,
                          reference_id='test_model',
                          project_id=self.project.id,
                          member_created_id=self.member.id,
                          add_to_session=True,
                          flush_session=True)
        model_run = ModelRun.new(session=self.session,
                                 reference_id='test_model_run',
                                 project_id=self.project.id,
                                 member_created_id=self.member.id,
                                 model_id=model.id,
                                 add_to_session=True,
                                 flush_session=True)

        self.assertEqual(model_run.reference_id, 'test_model_run')
        self.assertEqual(model_run.project_id, self.project.id)
        self.assertEqual(model_run.member_created_id, self.member.id)
Пример #7
0
def model_run_list_core(session: object,
                        log: dict = regular_log.default(),
                        project_id: int = None,
                        directory_id: int = None,
                        file_id: int = None,
                        job_id: int = None,
                        status: str = 'open',
                        starts: str = None,
                        type: str = None,
                        ends: str = None,
                        id_list: list = None,
                        members_list: list = []):
    """
        Returns serialized dictionary of the list of issues that match the given filters.
        This method assumes data has been validated previously, so no extra validations are done in the function.

    :param session:
    :param log:
    :param project_id:
    :param task_id:
    :param file_id:
    :param job_id:
    :param status:
    :param members_list:
    :return:
    """
    if project_id is None:
        log['error']['project_id'] = 'Provide project_id'
        return None, log

    model_run_list = ModelRun.list(
        session=session,
        project_id=project_id,
        starts=starts,
        ends=ends,
        id_list=id_list,
    )

    model_run_data = [run.serialize() for run in model_run_list]
    return model_run_data, log