def test_main(self): ''' redirect stdout to a pipe in order to parse what comes from stdout to get url and token. ''' stdout = sys.stdout ppr, ppw = os.pipe() sys.stdout = os.fdopen(ppw, 'w') console = os.fdopen(ppr, 'r') filename = 'tiny.bin' with open(filename, 'wb') as f: f.write(self.data_tiny) ffsend.main(['-s', self.service, filename]) sys.stdout.close() ctxt = console.read() url = re.search('Your download link is (.*)', ctxt).group(1) token = re.search('Owner token is (.*)', ctxt).group(1) # restore stdout console.close() sys.stdout = stdout print(ctxt) self.assertTrue(url is not None) self.assertTrue(token is not None) service, fid, secret = ffsend.parse_url(url) ffsend.main(['-i', '-t', token, url]) ffsend.main(['--delete', '-t', token, url]) with self.assertRaises(FFSendError): ffsend.download(service, fid, secret, '.')
def test_bad_delete(self): with open('delete.bin', 'wb') as f: f.write(self.data_tiny) url, token = ffsend.upload(self.service, 'delete.bin') self.assertTrue(url is not None) os.unlink('delete.bin') service, fid, secret = ffsend.parse_url(url) ffsend.download(service, fid, secret, '.') with self.assertRaises(FFSendError): ffsend.delete(service, fid, token)
def test_delete_pw(self): with open('delete.bin', 'wb') as f: f.write(self.data_tiny) url, token = ffsend.upload('delete.bin', password='******') self.assertTrue(url is not None) os.unlink('delete.bin') fid, secret = ffsend.parse_url(url) ffsend.delete(fid, token) with self.assertRaises(FFSendError): ffsend.download(fid, secret, '.', 'password', url)
def do_test(self, service, filename, data, password=None): with open(filename, 'wb') as f: f.write(data) url, token = ffsend.upload(service, filename, password=password) self.assertTrue(url is not None) os.unlink(filename) service, fid, secret = ffsend.parse_url(url) self.assertTrue(service is not None) self.assertTrue(secret is not None) metadata = ffsend.get_metadata(service, fid, secret, password, url) self.assertEqual(metadata['metadata']['name'], filename) self.assertEqual(metadata['metadata']['size'], len(data)) ffsend.download(service, fid, secret, '.', password, url) with open(filename, 'rb') as f: self.assertEqual(data, f.read())
def test_set_dlimit(self): filename = 'dlimit.bin' with open(filename, 'wb') as f: f.write(self.data_tiny) url, token = ffsend.upload(self.service, filename) self.assertTrue(url is not None) os.unlink(filename) service, fid, secret = ffsend.parse_url(url) ffsend.set_params(service, fid, token, dlimit=2) for i in range(2): ffsend.download(service, fid, secret, '.') with open(filename, 'rb') as f: self.assertEqual(self.data_tiny, f.read()) os.unlink(filename) with self.assertRaises(FFSendError): ffsend.download(service, fid, secret, '.')