def test_process_pending_data_download(self): """management command processes pending data download""" data_download = request_user_data_download(self.user) self.assertEqual(data_download.status, DataDownload.STATUS_PENDING) out = StringIO() call_command(prepareuserdatadownloads.Command(), stdout=out) command_output = out.getvalue().splitlines()[0].strip() self.assertEqual(command_output, "Data downloads prepared: 1") updated_data_download = DataDownload.objects.get(pk=data_download.pk) self.assertEqual(updated_data_download.status, DataDownload.STATUS_READY) self.assertTrue( updated_data_download.expires_on > data_download.expires_on) self.assertTrue(updated_data_download.file) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, "TestUser, your data download is ready") absolute_url = ''.join([ settings.MISAGO_ADDRESS.rstrip('/'), updated_data_download.file.url ]) self.assertIn(absolute_url, mail.outbox[0].body)
def test_skip_expired_data_download(self): """management command skips expired data download""" data_download = request_user_data_download(self.user) data_download.status = DataDownload.STATUS_EXPIRED data_download.save() out = StringIO() call_command(prepareuserdatadownloads.Command(), stdout=out) command_output = out.getvalue().splitlines()[0].strip() self.assertEqual(command_output, "Data downloads prepared: 0") updated_data_download = DataDownload.objects.get(pk=data_download.pk) self.assertEqual(updated_data_download.status, DataDownload.STATUS_EXPIRED) self.assertEqual(len(mail.outbox), 0)