Exemplo n.º 1
0
    def test_correct_result(self):
        data = {'foo': 'bar'}

        tb = FilesystemBackend(app=self.app, url=self.url)
        tid = uuid()
        tb.mark_as_done(tid, data)
        assert tb.get_result(tid) == data
Exemplo n.º 2
0
    def test_correct_result(self):
        data = {'foo': 'bar'}

        tb = FilesystemBackend(app=self.app, url=self.url)
        tid = uuid()
        tb.mark_as_done(tid, data)
        self.assertEqual(tb.get_result(tid), data)
Exemplo n.º 3
0
    def test_get_many(self):
        data = {uuid(): 'foo', uuid(): 'bar', uuid(): 'baz'}

        tb = FilesystemBackend(app=self.app, url=self.url)
        for key, value in data.items():
            tb.mark_as_done(key, value)

        for key, result in tb.get_many(data.keys()):
            assert result['result'] == data[key]
Exemplo n.º 4
0
    def test_get_many(self):
        data = {uuid(): 'foo', uuid(): 'bar', uuid(): 'baz'}

        tb = FilesystemBackend(app=self.app, url=self.url)
        for key, value in data.items():
            tb.mark_as_done(key, value)

        for key, result in tb.get_many(data.keys()):
            self.assertEqual(result['result'], data[key])
Exemplo n.º 5
0
 def test_raises_meaningful_errors_for_invalid_urls(
     self,
     url,
     expected_error_message
 ):
     with pytest.raises(
         ImproperlyConfigured,
         match=expected_error_message
     ):
         FilesystemBackend(app=self.app, url=url)
Exemplo n.º 6
0
 def test_forget_deletes_file(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     tid = uuid()
     tb.mark_as_done(tid, 42)
     tb.forget(tid)
     self.assertEqual(len(os.listdir(self.directory)), 0)
Exemplo n.º 7
0
 def test_done_task_is_SUCCESS(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     tid = uuid()
     tb.mark_as_done(tid, 42)
     assert tb.get_state(tid) == states.SUCCESS
Exemplo n.º 8
0
 def test_cleanup(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     yesterday_task_ids = [uuid() for i in range(10)]
     today_task_ids = [uuid() for i in range(10)]
     for tid in yesterday_task_ids:
         tb.mark_as_done(tid, 42)
     day_length = 0.2
     time.sleep(day_length)  # let FS mark some difference in mtimes
     for tid in today_task_ids:
         tb.mark_as_done(tid, 42)
     with patch.object(tb, 'expires', 0):
         tb.cleanup()
     # test that zero expiration time prevents any cleanup
     filenames = set(os.listdir(tb.path))
     assert all(
         tb.get_key_for_task(tid) in filenames
         for tid in yesterday_task_ids + today_task_ids
     )
     # test that non-zero expiration time enables cleanup by file mtime
     with patch.object(tb, 'expires', day_length):
         tb.cleanup()
     filenames = set(os.listdir(tb.path))
     assert not any(
         tb.get_key_for_task(tid) in filenames
         for tid in yesterday_task_ids
     )
     assert all(
         tb.get_key_for_task(tid) in filenames
         for tid in today_task_ids
     )
Exemplo n.º 9
0
 def test_missing_task_is_PENDING(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     assert tb.get_state('xxx-does-not-exist') == states.PENDING
Exemplo n.º 10
0
 def test_mark_as_done_writes_file(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     tb.mark_as_done(uuid(), 42)
     assert len(os.listdir(self.directory)) == 1
Exemplo n.º 11
0
 def test_a_path_in_url(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     assert tb.path == self.path
Exemplo n.º 12
0
 def test_localhost_is_removed_from_url(self):
     url = 'file://localhost' + self.directory
     tb = FilesystemBackend(app=self.app, url=url)
     assert tb.path == self.path
Exemplo n.º 13
0
 def test_a_path_in_app_conf(self):
     self.app.conf.result_fspath = self.url[7:]
     tb = FilesystemBackend(app=self.app)
     self.assertEqual(tb.path, self.path)
Exemplo n.º 14
0
 def test_a_path_is_required(self):
     with pytest.raises(ImproperlyConfigured):
         FilesystemBackend(app=self.app)
Exemplo n.º 15
0
 def test_forget_deletes_file(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     tid = uuid()
     tb.mark_as_done(tid, 42)
     tb.forget(tid)
     assert len(os.listdir(self.directory)) == 0
Exemplo n.º 16
0
 def test_serialization_pickle(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     import pickle
     pickled = pickle.dumps(tb)
     assert isinstance(pickle.loads(pickled), FilesystemBackend)
Exemplo n.º 17
0
 def test_done_task_is_SUCCESS(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     tid = uuid()
     tb.mark_as_done(tid, 42)
     self.assertEqual(tb.get_state(tid), states.SUCCESS)
Exemplo n.º 18
0
 def test_mark_as_done_writes_file(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     tb.mark_as_done(uuid(), 42)
     self.assertEqual(len(os.listdir(self.directory)), 1)
Exemplo n.º 19
0
 def test_missing_task_is_PENDING(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     self.assertEqual(tb.get_state('xxx-does-not-exist'), states.PENDING)
Exemplo n.º 20
0
 def test_path_is_incorrect(self):
     with self.assertRaises(ImproperlyConfigured):
         FilesystemBackend(app=self.app, url=self.url + '-incorrect')
Exemplo n.º 21
0
 def test_a_path_in_url(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     self.assertEqual(tb.path, self.path)
Exemplo n.º 22
0
 def test_pickleable(self):
     tb = FilesystemBackend(app=self.app, url=self.url, serializer='pickle')
     assert pickle.loads(pickle.dumps(tb))
Exemplo n.º 23
0
 def test_missing_task_is_PENDING(self):
     tb = FilesystemBackend(app=self.app, url=self.url)
     self.assertEqual(tb.get_status('xxx-does-not-exist'), states.PENDING)