2018-05-07 01:45:56 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2020-04-22 01:22:10 +00:00
|
|
|
import os
|
|
|
|
import tempfile
|
2017-08-29 04:21:32 +00:00
|
|
|
import unittest
|
2018-05-07 01:45:56 +00:00
|
|
|
import util
|
2017-08-29 04:21:32 +00:00
|
|
|
|
|
|
|
|
2018-05-08 22:18:21 +00:00
|
|
|
class TestMisc(unittest.TestCase):
|
2018-05-07 03:21:59 +00:00
|
|
|
def runTest(self):
|
2018-05-08 22:18:21 +00:00
|
|
|
# version
|
2018-05-25 12:31:32 +00:00
|
|
|
self.assertEqual(util.invoke('version'), 6)
|
2018-05-07 01:45:56 +00:00
|
|
|
|
2018-05-08 22:18:21 +00:00
|
|
|
# sync
|
2018-05-07 02:01:24 +00:00
|
|
|
util.invoke('sync')
|
2018-05-07 01:45:56 +00:00
|
|
|
|
2020-05-01 18:38:23 +00:00
|
|
|
# getProfiles
|
|
|
|
profiles = util.invoke('getProfiles')
|
|
|
|
self.assertIsInstance(profiles, list)
|
|
|
|
self.assertGreater(len(profiles), 0)
|
|
|
|
|
|
|
|
# loadProfile
|
|
|
|
util.invoke('loadProfile', name=profiles[0])
|
|
|
|
|
2018-05-08 22:18:21 +00:00
|
|
|
# multi
|
|
|
|
actions = [util.request('version'), util.request('version'), util.request('version')]
|
|
|
|
results = util.invoke('multi', actions=actions)
|
|
|
|
self.assertEqual(len(results), len(actions))
|
|
|
|
for result in results:
|
|
|
|
self.assertIsNone(result['error'])
|
2018-05-25 12:31:32 +00:00
|
|
|
self.assertEqual(result['result'], 6)
|
2018-05-07 01:45:56 +00:00
|
|
|
|
2020-04-22 01:22:10 +00:00
|
|
|
# exportPackage
|
|
|
|
fd, newname = tempfile.mkstemp(prefix='testexport', suffix='.apkg')
|
|
|
|
os.close(fd)
|
|
|
|
os.unlink(newname)
|
|
|
|
result = util.invoke('exportPackage', deck='Default', path=newname)
|
|
|
|
self.assertTrue(result)
|
|
|
|
self.assertTrue(os.path.exists(newname))
|
|
|
|
|
2020-05-01 18:55:30 +00:00
|
|
|
# importPackage
|
|
|
|
deckName = 'importTest'
|
|
|
|
fd, newname = tempfile.mkstemp(prefix='testimport', suffix='.apkg')
|
|
|
|
os.close(fd)
|
|
|
|
os.unlink(newname)
|
|
|
|
util.invoke('createDeck', deck=deckName)
|
|
|
|
note = {'deckName': deckName, 'modelName': 'Basic', 'fields': {'Front': 'front1', 'Back': 'back1'}, 'tags': ''}
|
|
|
|
noteId = util.invoke('addNote', note=note)
|
|
|
|
util.invoke('exportPackage', deck=deckName, path=newname)
|
|
|
|
util.invoke('deleteDecks', decks=[deckName], cardsToo=True)
|
|
|
|
util.invoke('importPackage', path=newname)
|
|
|
|
deckNames = util.invoke('deckNames')
|
|
|
|
self.assertIn(deckName, deckNames)
|
|
|
|
|
2018-05-07 01:45:56 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|