def test_upload_task_log_fails_if_task_not_open(self): t = Task.objects.create( worker=self._worker, arch=self._arch, channel=self._channel, owner=self._user, state=TASK_STATES['CLOSED'], ) req = _make_request(self._worker) with self.assertRaises(ValueError): worker.upload_task_log(req, t.id, '/foo/bar', 0o644, '', '', '', '')
def test_upload_task_log_fails_if_task_not_open(self): t = Task.objects.create( worker=self._worker, arch=self._arch, channel=self._channel, owner=self._user, state=TASK_STATES['CLOSED'], ) req = _make_request(self._worker) with self.assertRaises(ValueError): worker.upload_task_log(req, t.id, '/foo/bar', 0o644, '', '', '', '')
def test_upload_task_log_catch_decode_error(self): t = Task.objects.create( worker=self._worker, arch=self._arch, channel=self._channel, owner=self._user, state=TASK_STATES['OPEN'], ) req = _make_request(self._worker) with tempfile.NamedTemporaryFile(delete=True) as tf: msg = b'this is a text message' checksum = 'invalid-checksum' chunk = base64.encodestring(msg) chunk_start = 0 chunk_size = len(msg) ok = worker.upload_task_log(req, t.id, tf.name, 0o644, str(chunk_start), str(chunk_size), checksum, chunk) self.assertFalse(ok) self.assertEqual(tf.read(), b'')
def test_upload_task_log(self): t = Task.objects.create( worker=self._worker, arch=self._arch, channel=self._channel, owner=self._user, state=TASK_STATES['OPEN'], ) req = _make_request(self._worker) with tempfile.NamedTemporaryFile(delete=True) as tf: msg = b'this is a text message' checksum = hashlib.sha256(msg).hexdigest() encode_func = base64.encodebytes if hasattr(base64, "encodebytes") else base64.encodestring chunk = encode_func(msg) chunk_start = 0 chunk_size = len(msg) ok = worker.upload_task_log(req, t.id, tf.name, 0o644, str(chunk_start), str(chunk_size), checksum, chunk) self.assertTrue(ok) self.assertEqual(tf.read(), msg)
def test_upload_task_log_catch_decode_error(self): t = Task.objects.create( worker=self._worker, arch=self._arch, channel=self._channel, owner=self._user, state=TASK_STATES['OPEN'], ) req = _make_request(self._worker) with tempfile.NamedTemporaryFile(delete=True) as tf: msg = 'this is a text message' checksum = 'invalid-checksum' chunk = base64.encodestring(msg) chunk_start = 0 chunk_size = len(msg) ok = worker.upload_task_log(req, t.id, tf.name, 0o644, str(chunk_start), str(chunk_size), checksum, chunk) self.assertFalse(ok) self.assertEqual(tf.read(), '')
def upload_task_log(self, task_id, relative_path, mode, chunk_start, chunk_len, chunk_checksum, encoded_chunk): return worker.upload_task_log(self._request, task_id, relative_path, mode, chunk_start, chunk_len, chunk_checksum, encoded_chunk)
def test_upload_task_log(self): with self.assertRaises(PermissionDenied): worker.upload_task_log(_make_request(None, False), 1, '/dev/null', 0o666, 0, 0, None, None)
def test_upload_task_log(self): with self.assertRaises(PermissionDenied): worker.upload_task_log(_make_request(None, False), 1, '/dev/null', 0o666, 0, 0, None, None)