Пример #1
0
    def _sync_scoringengine(self, scoringengine_map):
        scoringengine_name = scoringengine_map.name
        se_mapping = dict()
        # Scoring Engines matching by id with discovered Scoring engine
        matching_scoringengines = [se for se in self.available_scoringengines
                                   if se.name == scoringengine_name]
        stale_scoringengines = self._soft_delete_stale_scoringengines(
            scoringengine_map, matching_scoringengines)

        if stale_scoringengines or not matching_scoringengines:
            scoringengine = objects.ScoringEngine(self.ctx)
            scoringengine.name = scoringengine_name
            scoringengine.description = scoringengine_map.description
            scoringengine.metainfo = scoringengine_map.metainfo
            scoringengine.create()
            LOG.info("Scoring Engine %s created", scoringengine_name)

            # Updating the internal states
            self.available_scoringengines_map[scoringengine] = \
                scoringengine_map
            # Map the old scoring engine names to the new (equivalent) SE
            for matching_scoringengine in matching_scoringengines:
                se_mapping[matching_scoringengine.name] = scoringengine

        return se_mapping
Пример #2
0
def get_test_scoring_engine(context, **kw):
    """Return a ScoringEngine object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_scoring_engine = db_utils.get_test_scoring_engine(**kw)
    scoring_engine = objects.ScoringEngine(context)
    for key in db_scoring_engine:
        setattr(scoring_engine, key, db_scoring_engine[key])
    return scoring_engine
Пример #3
0
 def test_create(self, mock_create_scoring_engine):
     mock_create_scoring_engine.return_value = self.fake_scoring_engine
     scoring_engine = objects.ScoringEngine(self.context,
                                            **self.fake_scoring_engine)
     scoring_engine.create()
     expected_scoring_engine = self.fake_scoring_engine.copy()
     expected_scoring_engine['created_at'] = expected_scoring_engine[
         'created_at'].replace(tzinfo=iso8601.iso8601.Utc())
     mock_create_scoring_engine.assert_called_once_with(
         expected_scoring_engine)
     self.assertEqual(self.context, scoring_engine._context)
Пример #4
0
    def test_create(self):
        with mock.patch.object(self.dbapi,
                               'create_scoring_engine',
                               autospec=True) as mock_create_scoring_engine:
            mock_create_scoring_engine.return_value = self.fake_scoring_engine
            scoring_engine = objects.ScoringEngine(self.context,
                                                   **self.fake_scoring_engine)

            scoring_engine.create()
            mock_create_scoring_engine.assert_called_once_with(
                self.fake_scoring_engine)
            self.assertEqual(self.context, scoring_engine._context)