Пример #1
0
 def test_get_queue_default_queue(self):
     u'''
     Test that the default queue is returned if no queue is given.
     '''
     q = jobs.get_queue()
     assert_equal(jobs.remove_queue_name_prefix(q.name),
                  jobs.DEFAULT_QUEUE_NAME)
Пример #2
0
 def test_worker_default_queue(self):
     self.enqueue()
     self.enqueue(queue=u"my_queue")
     jobs.Worker().work(burst=True)
     all_jobs = self.all_jobs()
     assert_equal(len(all_jobs), 1)
     assert_equal(jobs.remove_queue_name_prefix(all_jobs[0].origin), u"my_queue")
Пример #3
0
 def test_get_queue_default_queue(self):
     u'''
     Test that the default queue is returned if no queue is given.
     '''
     q = jobs.get_queue()
     assert_equal(jobs.remove_queue_name_prefix(q.name),
                  jobs.DEFAULT_QUEUE_NAME)
Пример #4
0
 def test_worker_default_queue(self):
     self.enqueue()
     self.enqueue(queue=u"my_queue")
     jobs.Worker().work(burst=True)
     all_jobs = self.all_jobs()
     assert len(all_jobs) == 1
     assert jobs.remove_queue_name_prefix(all_jobs[0].origin) == u"my_queue"
Пример #5
0
 def test_show_existing(self):
     '''
     Test ``jobs show`` for an existing job.
     '''
     job = self.enqueue(queue=u'my_queue', title=u'My Title')
     stdout = paster(u'jobs', u'show', job.id)[1]
     assert_in(job.id, stdout)
     assert_in(jobs.remove_queue_name_prefix(job.origin), stdout)
Пример #6
0
 def test_show_existing(self):
     """
     Test ``jobs show`` for an existing job.
     """
     job = self.enqueue(queue=u"my_queue", title=u"My Title")
     stdout = paster(u"jobs", u"show", job.id)[1]
     assert job.id in stdout
     assert jobs.remove_queue_name_prefix(job.origin) in stdout
Пример #7
0
 def test_show_existing(self, cli):
     """
     Test ``jobs show`` for an existing job.
     """
     job = self.enqueue(queue=u"my_queue", title=u"My Title")
     output = cli.invoke(ckan, [u"jobs", u"show", job.id]).output
     assert job.id in output
     assert jobs.remove_queue_name_prefix(job.origin) in output
Пример #8
0
 def test_show_existing(self):
     '''
     Test ``jobs show`` for an existing job.
     '''
     job = self.enqueue(queue=u'my_queue', title=u'My Title')
     stdout = paster(u'jobs', u'show', job.id)[1]
     assert_in(job.id, stdout)
     assert_in(jobs.remove_queue_name_prefix(job.origin), stdout)
Пример #9
0
 def test_worker_multiple_queues(self):
     self.enqueue()
     self.enqueue(queue=u"queue1")
     self.enqueue(queue=u"queue2")
     jobs.Worker([u"queue1", u"queue2"]).work(burst=True)
     all_jobs = self.all_jobs()
     assert_equal(len(all_jobs), 1)
     assert_equal(jobs.remove_queue_name_prefix(all_jobs[0].origin), jobs.DEFAULT_QUEUE_NAME)
Пример #10
0
 def test_worker_default_queue(self):
     self.enqueue()
     self.enqueue(queue=u'my_queue')
     jobs.Worker().work(burst=True)
     all_jobs = self.all_jobs()
     assert_equal(len(all_jobs), 1)
     assert_equal(jobs.remove_queue_name_prefix(all_jobs[0].origin),
                  u'my_queue')
Пример #11
0
 def test_worker_multiple_queues(self):
     self.enqueue()
     self.enqueue(queue=u"queue1")
     self.enqueue(queue=u"queue2")
     jobs.Worker([u"queue1", u"queue2"]).work(burst=True)
     all_jobs = self.all_jobs()
     assert len(all_jobs) == 1
     assert (jobs.remove_queue_name_prefix(
         all_jobs[0].origin) == jobs.DEFAULT_QUEUE_NAME)
Пример #12
0
 def test_test_default_queue(self):
     """
     Test ``jobs test`` for the default queue.
     """
     stdout = paster(u"jobs", u"test")[1]
     all_jobs = self.all_jobs()
     assert len(all_jobs) == 1
     assert (jobs.remove_queue_name_prefix(
         all_jobs[0].origin) == jobs.DEFAULT_QUEUE_NAME)
Пример #13
0
 def test_worker_multiple_queues(self):
     self.enqueue()
     self.enqueue(queue=u'queue1')
     self.enqueue(queue=u'queue2')
     jobs.Worker([u'queue1', u'queue2']).work(burst=True)
     all_jobs = self.all_jobs()
     assert_equal(len(all_jobs), 1)
     assert_equal(jobs.remove_queue_name_prefix(all_jobs[0].origin),
                  jobs.DEFAULT_QUEUE_NAME)
Пример #14
0
 def test_test_default_queue(self, cli):
     """
     Test ``jobs test`` for the default queue.
     """
     stdout = cli.invoke(ckan, [u"jobs", u"test"]).output
     all_jobs = self.all_jobs()
     assert len(all_jobs) == 1
     assert (jobs.remove_queue_name_prefix(
         all_jobs[0].origin) == jobs.DEFAULT_QUEUE_NAME)
Пример #15
0
 def test_test_specific_queues(self):
     '''
     Test ``jobs test`` for specific queues.
     '''
     stdout = paster(u'jobs', u'test', u'q1', u'q2')[1]
     all_jobs = self.all_jobs()
     eq(len(all_jobs), 2)
     eq({jobs.remove_queue_name_prefix(j.origin) for j in all_jobs},
        {u'q1', u'q2'})
Пример #16
0
 def test_test_default_queue(self):
     '''
     Test ``jobs test`` for the default queue.
     '''
     stdout = paster(u'jobs', u'test')[1]
     all_jobs = self.all_jobs()
     eq(len(all_jobs), 1)
     eq(jobs.remove_queue_name_prefix(all_jobs[0].origin),
        jobs.DEFAULT_QUEUE_NAME)
Пример #17
0
 def test_test_specific_queues(self):
     '''
     Test ``jobs test`` for specific queues.
     '''
     stdout = paster(u'jobs', u'test', u'q1', u'q2')[1]
     all_jobs = self.all_jobs()
     eq(len(all_jobs), 2)
     eq({jobs.remove_queue_name_prefix(j.origin)
         for j in all_jobs}, {u'q1', u'q2'})
Пример #18
0
 def test_test_default_queue(self):
     '''
     Test ``jobs test`` for the default queue.
     '''
     stdout = paster(u'jobs', u'test')[1]
     all_jobs = self.all_jobs()
     eq(len(all_jobs), 1)
     eq(jobs.remove_queue_name_prefix(all_jobs[0].origin),
        jobs.DEFAULT_QUEUE_NAME)
Пример #19
0
 def test_test_specific_queues(self, cli):
     """
     Test ``jobs test`` for specific queues.
     """
     stdout = cli.invoke(ckan, [u"jobs", u"test", u"q1", u"q2"]).output
     all_jobs = self.all_jobs()
     assert len(all_jobs) == 2
     assert {jobs.remove_queue_name_prefix(j.origin)
             for j in all_jobs} == {
                 u"q1",
                 u"q2",
             }
Пример #20
0
 def test_test_specific_queues(self):
     """
     Test ``jobs test`` for specific queues.
     """
     stdout = paster(u"jobs", u"test", u"q1", u"q2")[1]
     all_jobs = self.all_jobs()
     assert len(all_jobs) == 2
     assert {jobs.remove_queue_name_prefix(j.origin)
             for j in all_jobs} == {
                 u"q1",
                 u"q2",
             }
Пример #21
0
 def test_foreign_queues_are_ignored(self):
     u'''
     Test that foreign RQ-queues are ignored.
     '''
     # Create queues for this CKAN instance
     self.enqueue(queue=u'q1')
     self.enqueue(queue=u'q2')
     # Create queue for another CKAN instance
     with changed_config(u'ckan.site_id', u'some-other-ckan-instance'):
         self.enqueue(queue=u'q2')
     # Create queue not related to CKAN
     rq.Queue(u'q4').enqueue_call(jobs.test_job)
     all_queues = jobs.get_all_queues()
     names = {jobs.remove_queue_name_prefix(q.name) for q in all_queues}
     assert_equal(names, {u'q1', u'q2'})
Пример #22
0
 def test_foreign_queues_are_ignored(self):
     u"""
     Test that foreign RQ-queues are ignored.
     """
     # Create queues for this CKAN instance
     self.enqueue(queue=u"q1")
     self.enqueue(queue=u"q2")
     # Create queue for another CKAN instance
     with changed_config(u"ckan.site_id", u"some-other-ckan-instance"):
         self.enqueue(queue=u"q2")
     # Create queue not related to CKAN
     rq.Queue(u"q4").enqueue_call(jobs.test_job)
     all_queues = jobs.get_all_queues()
     names = {jobs.remove_queue_name_prefix(q.name) for q in all_queues}
     assert_equal(names, {u"q1", u"q2"})
Пример #23
0
 def test_foreign_queues_are_ignored(self):
     u'''
     Test that foreign RQ-queues are ignored.
     '''
     # Create queues for this CKAN instance
     self.enqueue(queue=u'q1')
     self.enqueue(queue=u'q2')
     # Create queue for another CKAN instance
     with changed_config(u'ckan.site_id', u'some-other-ckan-instance'):
         self.enqueue(queue=u'q2')
     # Create queue not related to CKAN
     rq.Queue(u'q4').enqueue_call(jobs.test_job)
     all_queues = jobs.get_all_queues()
     names = {jobs.remove_queue_name_prefix(q.name) for q in all_queues}
     assert_equal(names, {u'q1', u'q2'})
Пример #24
0
 def test_foreign_queues_are_ignored(self):
     u"""
     Test that foreign RQ-queues are ignored.
     """
     # Create queues for this CKAN instance
     self.enqueue(queue=u"q1")
     self.enqueue(queue=u"q2")
     # Create queue for another CKAN instance
     with changed_config(u"ckan.site_id", u"some-other-ckan-instance"):
         self.enqueue(queue=u"q2")
     # Create queue not related to CKAN
     rq.Queue(u"q4").enqueue_call(jobs.test_job)
     all_queues = jobs.get_all_queues()
     names = {jobs.remove_queue_name_prefix(q.name) for q in all_queues}
     assert names == {u"q1", u"q2"}
Пример #25
0
def job_clear(context, data_dict):
    '''Clear background job queues.

    Does not affect jobs that are already being processed.

    :param list queues: The queues to clear. If not given then ALL
        queues are cleared.

    :returns: The cleared queues.
    :rtype: list

    .. versionadded:: 2.7
    '''
    _check_access(u'job_clear', context, data_dict)
    queues = data_dict.get(u'queues')
    if queues:
        queues = [jobs.get_queue(q) for q in queues]
    else:
        queues = jobs.get_all_queues()
    names = [jobs.remove_queue_name_prefix(queue.name) for queue in queues]
    for queue, name in zip(queues, names):
        queue.empty()
        log.info(u'Cleared background job queue "{}"'.format(name))
    return names
Пример #26
0
def job_clear(context, data_dict):
    '''Clear background job queues.

    Does not affect jobs that are already being processed.

    :param list queues: The queues to clear. If not given then ALL
        queues are cleared.

    :returns: The cleared queues.
    :rtype: list

    .. versionadded:: 2.7
    '''
    _check_access(u'job_clear', context, data_dict)
    queues = data_dict.get(u'queues')
    if queues:
        queues = [jobs.get_queue(q) for q in queues]
    else:
        queues = jobs.get_all_queues()
    names = [jobs.remove_queue_name_prefix(queue.name) for queue in queues]
    for queue, name in zip(queues, names):
        queue.empty()
        log.info(u'Cleared background job queue "{}"'.format(name))
    return names
Пример #27
0
 def test_get_queue_other_queue(self):
     u'''
     Test that a different queue can be given.
     '''
     q = jobs.get_queue(u'my_queue')
     assert_equal(jobs.remove_queue_name_prefix(q.name), u'my_queue')
Пример #28
0
 def test_get_queue_other_queue(self):
     u'''
     Test that a different queue can be given.
     '''
     q = jobs.get_queue(u'my_queue')
     assert_equal(jobs.remove_queue_name_prefix(q.name), u'my_queue')
Пример #29
0
 def test_queue_name_removal_without_prefix(self):
     with pytest.raises(ValueError):
         jobs.remove_queue_name_prefix(u"foobar")
Пример #30
0
 def test_queue_name_removal_with_prefix(self):
     plain = u"foobar"
     prefixed = jobs.add_queue_name_prefix(plain)
     assert jobs.remove_queue_name_prefix(prefixed) == plain
Пример #31
0
 def test_queue_name_removal_with_prefix(self):
     plain = u'foobar'
     prefixed = jobs.add_queue_name_prefix(plain)
     assert_equal(jobs.remove_queue_name_prefix(prefixed), plain)
Пример #32
0
 def test_queue_name_removal_without_prefix(self):
     jobs.remove_queue_name_prefix(u'foobar')
Пример #33
0
 def test_get_queue_other_queue(self):
     u"""
     Test that a different queue can be given.
     """
     q = jobs.get_queue(u"my_queue")
     assert jobs.remove_queue_name_prefix(q.name) == u"my_queue"
Пример #34
0
 def test_get_queue_default_queue(self):
     u"""
     Test that the default queue is returned if no queue is given.
     """
     q = jobs.get_queue()
     assert jobs.remove_queue_name_prefix(q.name) == jobs.DEFAULT_QUEUE_NAME
Пример #35
0
 def test_get_queue_other_queue(self):
     u"""
     Test that a different queue can be given.
     """
     q = jobs.get_queue(u"my_queue")
     assert_equal(jobs.remove_queue_name_prefix(q.name), u"my_queue")
Пример #36
0
 def test_queue_name_removal_without_prefix(self):
     jobs.remove_queue_name_prefix(u'foobar')
Пример #37
0
 def test_queue_name_removal_with_prefix(self):
     plain = u'foobar'
     prefixed = jobs.add_queue_name_prefix(plain)
     assert_equal(jobs.remove_queue_name_prefix(prefixed), plain)