Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 8
0
Archivo: test_cli.py Proyecto: vjf/ckan
 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)
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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'})
Ejemplo n.º 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)
Ejemplo n.º 17
0
Archivo: test_cli.py Proyecto: vjf/ckan
 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'})
Ejemplo n.º 18
0
Archivo: test_cli.py Proyecto: vjf/ckan
 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)
Ejemplo n.º 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",
             }
Ejemplo n.º 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",
             }
Ejemplo n.º 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'})
Ejemplo n.º 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"})
Ejemplo n.º 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'})
Ejemplo n.º 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"}
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 29
0
 def test_queue_name_removal_without_prefix(self):
     with pytest.raises(ValueError):
         jobs.remove_queue_name_prefix(u"foobar")
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 32
0
 def test_queue_name_removal_without_prefix(self):
     jobs.remove_queue_name_prefix(u'foobar')
Ejemplo n.º 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"
Ejemplo n.º 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
Ejemplo n.º 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")
Ejemplo n.º 36
0
 def test_queue_name_removal_without_prefix(self):
     jobs.remove_queue_name_prefix(u'foobar')
Ejemplo n.º 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)