コード例 #1
0
 def test_next_sequence_number(self):
     with self.app.app_context():
         subscriber_id = self.service.create({})
         sequence_number1 = get_next_sequence_number(
             resource_name=self.resource_name,
             item_id=subscriber_id,
             max_seq_number=self.max_seq_number,
             min_seq_number=self.min_seq_number
         )
         sequence_number2 = get_next_sequence_number(
             resource_name=self.resource_name,
             item_id=subscriber_id,
             max_seq_number=self.max_seq_number,
             min_seq_number=self.min_seq_number
         )
         self.assertEqual(sequence_number1 + 1, sequence_number2)
コード例 #2
0
    def test_rotate_sequence_number(self):
        with self.app.app_context():
            subscriber_id = self.service.create({})

            for i in range(self.max_seq_number + 1):
                last_sequence_number = get_next_sequence_number(
                    resource_name=self.resource_name,
                    item_id=subscriber_id,
                    max_seq_number=self.max_seq_number,
                    min_seq_number=self.min_seq_number
                )
            self.assertEqual(last_sequence_number, self.max_seq_number)

            last_sequence_number = get_next_sequence_number(
                resource_name=self.resource_name,
                item_id=subscriber_id,
                max_seq_number=self.max_seq_number,
                min_seq_number=self.min_seq_number
            )
            self.assertEqual(last_sequence_number, self.min_seq_number)
コード例 #3
0
ファイル: ingest.py プロジェクト: ahilles107/superdesk-core
 def set_ingest_provider_sequence(self, item, provider):
     """
     Sets the value of ingest_provider_sequence in item.
     :param item: object to which ingest_provider_sequence to be set
     :param provider: ingest_provider object, used to build the key name of sequence
     """
     sequence_number = get_next_sequence_number(
         resource_name='ingest_providers',
         item_id=provider[config.ID_FIELD],
         max_seq_number=app.config['MAX_VALUE_OF_INGEST_SEQUENCE']
     )
     item['ingest_provider_sequence'] = str(sequence_number)
コード例 #4
0
    def generate_sequence_number(self, subscriber):
        """
        Generates Published Sequence Number for the passed subscriber
        """

        assert (subscriber is not None), "Subscriber can't be null"
        min_seq_number = 0
        max_seq_number = app.config['MAX_VALUE_OF_PUBLISH_SEQUENCE']
        if subscriber.get('sequence_num_settings'):
            min_seq_number = subscriber['sequence_num_settings']['min']
            max_seq_number = subscriber['sequence_num_settings']['max']

        return get_next_sequence_number(
            resource_name='subscribers',
            item_id=subscriber[config.ID_FIELD],
            max_seq_number=max_seq_number,
            min_seq_number=min_seq_number
        )