megapy/tests/unit-tests.py

110 lines
2.8 KiB
Python
Raw Normal View History

2013-05-15 23:44:32 +00:00
"""
These unit tests will upload a test file,a test folder and a test contact,
Perform api operations on them,
And them remove them from your account.
"""
import unittest
import random
import os
2019-10-16 20:20:22 +00:00
from mega import Mega
email = os.environ['EMAIL']
password = os.environ['PASS']
2013-05-15 23:44:32 +00:00
mega = Mega()
2013-05-18 00:58:41 +00:00
# anonymous login
m = mega.login()
# normal login
2019-10-16 20:20:22 +00:00
# m = mega.login(email, password)
2013-05-15 23:44:32 +00:00
FIND_RESP = None
TEST_CONTACT = 'test@mega.co.nz'
2019-10-16 20:20:22 +00:00
TEST_PUBLIC_URL = (
'https://mega.nz/#!hYVmXKqL!r0d0-WRnFwulR_shhuEDwrY1Vo103-am1MyUy8oV6Ps'
)
2013-05-15 23:44:32 +00:00
TEST_FILE = os.path.basename(__file__)
TEST_FOLDER = 'mega.py_testfolder_{0}'.format(random.random())
class TestMega(unittest.TestCase):
def test_mega(self):
2013-05-18 01:21:03 +00:00
self.assertIsInstance(mega, Mega)
2013-05-15 23:44:32 +00:00
def test_login(self):
2013-05-18 01:21:03 +00:00
self.assertIsInstance(mega, Mega)
2013-05-15 23:44:32 +00:00
def test_get_user(self):
resp = m.get_user()
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, dict)
2013-05-15 23:44:32 +00:00
def test_get_quota(self):
resp = m.get_quota()
2013-05-18 01:43:48 +00:00
self.assertIsInstance(int(resp), int)
2013-05-15 23:44:32 +00:00
def test_get_storage_space(self):
resp = m.get_storage_space(mega=True)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, dict)
2013-05-15 23:44:32 +00:00
def test_get_files(self):
files = m.get_files()
2013-05-18 01:21:03 +00:00
self.assertIsInstance(files, dict)
2013-05-15 23:44:32 +00:00
def test_get_link(self):
2013-05-16 00:07:14 +00:00
file = m.find(TEST_FILE)
2013-05-15 23:44:32 +00:00
if file:
link = m.get_link(file)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(link, str)
2013-05-15 23:44:32 +00:00
def test_import_public_url(self):
resp = m.import_public_url(TEST_PUBLIC_URL)
file_handle = m.get_id_from_obj(resp)
resp = m.destroy(file_handle)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
def test_create_folder(self):
resp = m.create_folder(TEST_FOLDER)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, dict)
2013-05-15 23:44:32 +00:00
def test_rename(self):
file = m.find(TEST_FOLDER)
if file:
resp = m.rename(file, TEST_FOLDER)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
def test_delete_folder(self):
folder_node = m.find(TEST_FOLDER)[0]
resp = m.delete(folder_node)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
def test_delete(self):
file = m.find(TEST_FILE)
if file:
resp = m.delete(file[0])
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
def test_destroy(self):
file = m.find(TEST_FILE)
if file:
resp = m.destroy(file[0])
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
def test_empty_trash(self):
2019-10-16 20:20:22 +00:00
# resp None if already empty, else int
2013-05-15 23:44:32 +00:00
resp = m.empty_trash()
if resp is not None:
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
def test_add_contact(self):
resp = m.add_contact(TEST_CONTACT)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
def test_remove_contact(self):
resp = m.remove_contact(TEST_CONTACT)
2013-05-18 01:21:03 +00:00
self.assertIsInstance(resp, int)
2013-05-15 23:44:32 +00:00
if __name__ == '__main__':
2013-05-18 01:12:46 +00:00
unittest.main()