def runTest(self): # getNumCardsReviewedToday result = util.invoke('getNumCardsReviewedToday') self.assertIsInstance(result, int) # collectionStats result = util.invoke('getCollectionStatsHTML') self.assertIsInstance(result, str)
def _download_pdf(self, tree, save_path: str) -> None: download_link_element = tree.xpath("/html/body/div[4]/div[2]/div/div[1]/div/div[1]/div[2]/div/div[3]/a") download_url = "https://dspace.mit.edu" + download_link_element[0].attrib['href'] response = invoke(download_url) while response.status_code >= 400: # logger.error("Http call failed. Code: {}. Sleeping for {} secs.".format(response.status_code, 5)) sleep(5) response = invoke("https://dspace.mit.edu/handle/" + self.handle + "?show=full") with open(save_path, mode='wb') as save_file: save_file.write(response.content)
def runTest(self): # getNumCardsReviewedToday result = util.invoke('getNumCardsReviewedToday') self.assertIsInstance(result, int) # collectionStats result = util.invoke('getCollectionStatsHTML') self.assertIsInstance(result, str) # no reviews for new deck self.assertEqual( len(util.invoke("cardReviews", deck="test", startID=0)), 0) self.assertEqual(util.invoke("getLatestReviewID", deck="test"), 0) # add reviews cardId = int(util.invoke('findCards', query='deck:test')[0]) latestID = 123456 # small enough to not interfere with existing reviews util.invoke( "insertReviews", reviews=[[latestID - 1, cardId, -1, 3, 4, -60, 2500, 6157, 0], [latestID, cardId, -1, 1, -60, -60, 0, 4846, 0]]) self.assertEqual( len(util.invoke("cardReviews", deck="test", startID=0)), 2) self.assertEqual(util.invoke("getLatestReviewID", deck="test"), latestID)
def download(self) -> None: if os.path.exists(self.pdf_save_path) or os.path.exists(self.metadata_save_path): # logger.info("Skipping already downloaded etd {}.".format(self.handle)) return page = invoke("https://dspace.mit.edu/handle/" + self.handle + "?show=full") while page.status_code >= 400: # logger.error("Http call failed. Code: {}. Sleeping for {} secs.".format(page.status_code, 5)) sleep(5) page = invoke("https://dspace.mit.edu/handle/" + self.handle + "?show=full") tree = html.fromstring(page.content) self._download_pdf(tree, self.pdf_save_path) self._download_metadata(tree, self.metadata_save_path)
def runTest(self): # getNumCardsReviewedToday result = util.invoke('getNumCardsReviewedToday') self.assertIsInstance(result, int) # collectionStats result = util.invoke('getCollectionStatsHTML') self.assertIsInstance(result, str) # no reviews for new deck self.assertEqual(len(util.invoke('cardReviews', deck='test', startID=0)), 0) self.assertEqual(util.invoke('getLatestReviewID', deck='test'), 0)
def setUp(self): util.invoke('createDeck', deck='test') note = { 'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front1', 'Back': 'back1'}, 'tags': ['tag1'], 'options': { 'allowDuplicate': True } } self.noteId = util.invoke('addNote', note=note)
def runTest(self): filename = '_test.txt' data = 'test' # storeMediaFile util.invoke('storeMediaFile', filename=filename, data=data) filename2 = util.invoke('storeMediaFile', filename=filename, data='testtest', deleteExisting=False) self.assertNotEqual(filename2, filename) # retrieveMediaFile (part 1) media = util.invoke('retrieveMediaFile', filename=filename) self.assertEqual(media, data) names = util.invoke('getMediaFilesNames', pattern='_tes*.txt') self.assertEqual(set(names), set([filename, filename2])) # deleteMediaFile util.invoke('deleteMediaFile', filename=filename) # retrieveMediaFile (part 2) media = util.invoke('retrieveMediaFile', filename=filename) self.assertFalse(media)
def runTest(self): # modelNames modelNames = util.invoke('modelNames') self.assertGreater(len(modelNames), 0) # modelNamesAndIds modelNamesAndIds = util.invoke('modelNamesAndIds') self.assertGreater(len(modelNames), 0) # modelFieldNames modelFields = util.invoke('modelFieldNames', modelName=modelNames[0]) # modelFieldsOnTemplates modelFieldsOnTemplates = util.invoke('modelFieldsOnTemplates', modelName=modelNames[0])
def test_bug164(self): note = { 'deckName': 'test', 'modelName': 'Basic', 'fields': { 'Front': ' Whitespace\n', 'Back': '' }, 'options': { 'allowDuplicate': False, 'duplicateScope': 'deck' } } util.invoke('addNote', note=note) self.assertRaises(Exception, lambda: util.invoke('addNote', note=note))
def runTest(self): fd, newname = tempfile.mkstemp(prefix="testexport", suffix=".apkg") os.close(fd) os.unlink(newname) success = util.invoke('exportPackage', deck='Default', path=newname) self.assertTrue(success) self.assertTrue(os.path.exists(newname))
def runTest(self): # version self.assertEqual(util.invoke('version'), 6) # sync util.invoke('sync') # 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']) self.assertEqual(result['result'], 6)
def runTest(self): # version self.assertEqual(util.invoke('version'), 6) # sync util.invoke('sync') # 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']) self.assertEqual(result['result'], 6) # getNumCardsReviewedToday result = util.invoke('getNumCardsReviewedToday') self.assertIsInstance(result, int) # 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))
def get_total_items(collection_handle: str) -> int: """ Sample URL: https://dspace.mit.edu/handle/1721.1/7608/browse?rpp=20&offset=1&etal=-1&sort_by=2&type=dateissued&order=ASC :param collection_handle: :return: an integer with the total number of items in this collection. """ url = "https://dspace.mit.edu/handle/" \ + collection_handle \ + "/browse?rpp=20&offset=1&etal=-1&sort_by=2&type=dateissued&order=ASC" page = util.invoke(url) if page.status_code >= 400: logger.error("Received status code {} for url {}".format( page.status_code, url)) return 0 tree = html.fromstring(page.content) pagination_element = tree.xpath( "/html/body/div[4]/div[2]/div/div[1]/div/div/div[2]/div/div[1]/p") if not len(pagination_element): return 0 return int(pagination_element[0].text.split(" ")[-1])
def runTest(self): filename = '_test.txt' data = 'test' # storeMediaFile util.invoke('storeMediaFile', filename='_test.txt', data=data) # retrieveMediaFile (part 1) media = util.invoke('retrieveMediaFile', filename=filename) self.assertEqual(media, data) names = util.invoke('getMediaFilesNames', pattern='_tes*.txt') self.assertEqual(names, [filename]) # deleteMediaFile util.invoke('deleteMediaFile', filename=filename) # retrieveMediaFile (part 2) media = util.invoke('retrieveMediaFile', filename=filename) self.assertFalse(media)
def runTest(self): filename = '_test.txt' data = 'test' # storeMediaFile util.invoke('storeMediaFile', filename='_test.txt', data=data) # retrieveMediaFile (part 1) media = util.invoke('retrieveMediaFile', filename=filename) self.assertEqual(media, data) # deleteMediaFile util.invoke('deleteMediaFile', filename=filename) # retrieveMediaFile (part 2) media = util.invoke('retrieveMediaFile', filename=filename) self.assertFalse(media)
def runTest(self): # version self.assertEqual(util.invoke('version'), 6) # upgrade util.invoke('upgrade') # sync util.invoke('sync') # 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']) self.assertEqual(result['result'], 6)
def get_handles_on_browse_page(collection_handle: str, offset: int, rpp: int = 20) -> List[dict]: browse_url = "https://dspace.mit.edu/handle/" + collection_handle + "/browse?rpp=" + str(rpp) + "&offset=" \ + str(offset) + "&etal=-1&sort_by=2&type=dateissued&order=ASC" page = util.invoke(browse_url) if page.status_code >= 400: logger.error("Received status code {} for url {}".format( page.status_code, browse_url)) return [] element_list = html.fromstring(page.content) \ .xpath("/html/body/div[4]/div[2]/div/div[1]/div/div/div[3]/ul") handles = list() counter = 1 while True: li = element_list[0].xpath("li[" + str(counter) + "]") if not len(li): break try: handles.append({ 'handle': li[0].xpath("div/div[2]/div/h4/a")[0].attrib['href'].split( "/handle/")[1], 'year': int(li[0].xpath("div/div[2]/div/div/span[2]/small/span[2]") [0].text) }) except ValueError: handles.append({ 'handle': li[0].xpath("div/div[2]/div/h4/a")[0].attrib['href'].split( "/handle/")[1], 'year': li[0].xpath("div/div[2]/div/div/span[2]/small/span[2]")[0].text }) counter = counter + 1 return handles
def runTest(self): # modelNames modelNames = util.invoke('modelNames') self.assertGreater(len(modelNames), 0) # modelNamesAndIds modelNamesAndIds = util.invoke('modelNamesAndIds') self.assertGreater(len(modelNames), 0) # modelFieldNames modelFields = util.invoke('modelFieldNames', modelName=modelNames[0]) # modelFieldsOnTemplates modelFieldsOnTemplates = util.invoke('modelFieldsOnTemplates', modelName=modelNames[0]) # createModel with css newModel = util.invoke('createModel', modelName='testModel', inOrderFields=['field1', 'field2'], cardTemplates=[{'Front':'field1','Back':'field2'}], css='some random css') # createModel without css newModel = util.invoke('createModel', modelName='testModel-second', inOrderFields=['field1', 'field2'], cardTemplates=[{'Front':'field1','Back':'field2'}])
def runTest(self): incorrectId = 1234 # findCards cardIds = util.invoke('findCards', query='deck:test') self.assertEqual(len(cardIds), 1) # setEaseFactors EASE_TO_TRY = 4200 easeFactors = [EASE_TO_TRY for card in cardIds] couldGetEaseFactors = util.invoke('setEaseFactors', cards=cardIds, easeFactors=easeFactors) self.assertEqual([True for card in cardIds], couldGetEaseFactors) couldGetEaseFactors = util.invoke('setEaseFactors', cards=[incorrectId], easeFactors=[EASE_TO_TRY]) self.assertEqual([False], couldGetEaseFactors) # getEaseFactors easeFactorsFound = util.invoke('getEaseFactors', cards=cardIds) self.assertEqual(easeFactors, easeFactorsFound) easeFactorsFound = util.invoke('getEaseFactors', cards=[incorrectId]) self.assertEqual([None], easeFactorsFound) # suspend util.invoke('suspend', cards=cardIds) self.assertRaises(Exception, lambda: util.invoke('suspend', cards=[incorrectId])) # areSuspended (part 1) suspendedStates = util.invoke('areSuspended', cards=cardIds) self.assertEqual(len(cardIds), len(suspendedStates)) self.assertNotIn(False, suspendedStates) self.assertEqual([None], util.invoke('areSuspended', cards=[incorrectId])) # unsuspend util.invoke('unsuspend', cards=cardIds) # areSuspended (part 2) suspendedStates = util.invoke('areSuspended', cards=cardIds) self.assertEqual(len(cardIds), len(suspendedStates)) self.assertNotIn(True, suspendedStates) # areDue dueStates = util.invoke('areDue', cards=cardIds) self.assertEqual(len(cardIds), len(dueStates)) self.assertNotIn(False, dueStates) # getIntervals util.invoke('getIntervals', cards=cardIds, complete=True) util.invoke('getIntervals', cards=cardIds, complete=False) # cardsToNotes noteIds = util.invoke('cardsToNotes', cards=cardIds) self.assertEqual(len(noteIds), len(cardIds)) self.assertIn(self.noteId, noteIds) # cardsInfo cardsInfo = util.invoke('cardsInfo', cards=cardIds) self.assertEqual(len(cardsInfo), len(cardIds)) for i, cardInfo in enumerate(cardsInfo): self.assertEqual(cardInfo['cardId'], cardIds[i]) cardsInfo = util.invoke('cardsInfo', cards=[incorrectId]) self.assertEqual(len(cardsInfo), 1) self.assertDictEqual(cardsInfo[0], dict()) # forgetCards util.invoke('forgetCards', cards=cardIds) # relearnCards util.invoke('relearnCards', cards=cardIds)
def setUp(self): util.invoke('createDeck', deck='test')
def runTest(self): # version self.assertEqual(util.invoke('version'), 6) # sync util.invoke('sync') # getProfiles profiles = util.invoke('getProfiles') self.assertIsInstance(profiles, list) self.assertGreater(len(profiles), 0) # loadProfile util.invoke('loadProfile', name=profiles[0]) # 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']) self.assertEqual(result['result'], 6) # 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)) # 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) # reloadCollection util.invoke("reloadCollection")
def tearDown(self): util.invoke('deleteDecks', decks=['test'], cardsToo=True)
def runTest(self): # guiBrowse util.invoke('guiBrowse', query='deck:Default') # guiAddCards util.invoke('guiAddCards') # guiCurrentCard # util.invoke('guiCurrentCard') # guiStartCardTimer util.invoke('guiStartCardTimer') # guiShowQuestion util.invoke('guiShowQuestion') # guiShowAnswer util.invoke('guiShowAnswer') # guiAnswerCard util.invoke('guiAnswerCard', ease=1) # guiDeckOverview util.invoke('guiDeckOverview', name='Default') # guiDeckBrowser util.invoke('guiDeckBrowser')
def runTest(self): # guiBrowse util.invoke('guiBrowse', query='deck:Default') # guiAddCards util.invoke('guiAddCards') # guiAddCards with preset util.invoke('createDeck', deck='test') note = {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front1', 'Back': 'back1'}, 'tags': ['tag1']} util.invoke('guiAddCards', note=note) # guiAddCards with preset and closeAfterAdding noteWithOption = {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front1', 'Back': 'back1'}, 'options': { 'closeAfterAdding': True }, 'tags': ['tag1']} util.invoke('guiAddCards', note=noteWithOption) # guiCurrentCard # util.invoke('guiCurrentCard') # guiStartCardTimer util.invoke('guiStartCardTimer') # guiShowQuestion util.invoke('guiShowQuestion') # guiShowAnswer util.invoke('guiShowAnswer') # guiAnswerCard util.invoke('guiAnswerCard', ease=1) # guiDeckOverview util.invoke('guiDeckOverview', name='Default') # guiDeckBrowser util.invoke('guiDeckBrowser')
def runTest(self): # guiBrowse util.invoke('guiBrowse', query='deck:Default') # guiAddCards util.invoke('guiAddCards') # guiAddCards with preset util.invoke('createDeck', deck='test') note = { 'deckName': 'test', 'modelName': 'Basic', 'fields': { 'Front': 'front1', 'Back': 'back1' }, 'tags': ['tag1'], } util.invoke('guiAddCards', note=note) # guiAddCards with preset and closeAfterAdding util.invoke('guiAddCards', note={ **note, 'options': { 'closeAfterAdding': True }, }) util.invoke('guiAddCards', note={ **note, 'picture': [{ 'url': 'https://via.placeholder.com/150.png', 'filename': 'placeholder.png', 'fields': ['Front'], }] }) # guiCurrentCard # util.invoke('guiCurrentCard') # guiStartCardTimer util.invoke('guiStartCardTimer') # guiShowQuestion util.invoke('guiShowQuestion') # guiShowAnswer util.invoke('guiShowAnswer') # guiAnswerCard util.invoke('guiAnswerCard', ease=1) # guiDeckOverview util.invoke('guiDeckOverview', name='Default') # guiDeckBrowser util.invoke('guiDeckBrowser') # guiDatabaseCheck util.invoke('guiDatabaseCheck')
def runTest(self): # findCards cardIds = util.invoke('findCards', query='deck:test') self.assertEqual(len(cardIds), 1) # suspend util.invoke('suspend', cards=cardIds) # areSuspended (part 1) suspendedStates = util.invoke('areSuspended', cards=cardIds) self.assertEqual(len(cardIds), len(suspendedStates)) self.assertNotIn(False, suspendedStates) # unsuspend util.invoke('unsuspend', cards=cardIds) # areSuspended (part 2) suspendedStates = util.invoke('areSuspended', cards=cardIds) self.assertEqual(len(cardIds), len(suspendedStates)) self.assertNotIn(True, suspendedStates) # areDue dueStates = util.invoke('areDue', cards=cardIds) self.assertEqual(len(cardIds), len(dueStates)) self.assertNotIn(False, dueStates) # getIntervals util.invoke('getIntervals', cards=cardIds, complete=True) util.invoke('getIntervals', cards=cardIds, complete=False) # cardsToNotes noteIds = util.invoke('cardsToNotes', cards=cardIds) self.assertEqual(len(noteIds), len(cardIds)) self.assertIn(self.noteId, noteIds) # cardsInfo cardsInfo = util.invoke('cardsInfo', cards=cardIds) self.assertEqual(len(cardsInfo), len(cardIds)) for i, cardInfo in enumerate(cardsInfo): self.assertEqual(cardInfo['cardId'], cardIds[i])
def runTest(self): # addNote note = {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front1', 'Back': 'back1'}, 'tags': ['tag1']} noteId = util.invoke('addNote', note=note) self.assertRaises(Exception, lambda: util.invoke('addNote', note=note)) # addTags util.invoke('addTags', notes=[noteId], tags='tag2') # notesInfo (part 1) noteInfos = util.invoke('notesInfo', notes=[noteId]) self.assertEqual(len(noteInfos), 1) noteInfo = noteInfos[0] self.assertEqual(noteInfo['noteId'], noteId) self.assertSetEqual(set(noteInfo['tags']), {'tag1', 'tag2'}) self.assertEqual(noteInfo['fields']['Front']['value'], 'front1') self.assertEqual(noteInfo['fields']['Back']['value'], 'back1') # getTags allTags = util.invoke('getTags') self.assertIn('tag1', allTags) self.assertIn('tag2', allTags) # removeTags util.invoke('removeTags', notes=[noteId], tags='tag2') # updateNoteFields noteUpdate = {'id': noteId, 'fields': {'Front': 'front2', 'Back': 'back2'}} util.invoke('updateNoteFields', note=noteUpdate) # notesInfo (part 2) noteInfos = util.invoke('notesInfo', notes=[noteId]) self.assertEqual(len(noteInfos), 1) noteInfo = noteInfos[0] self.assertSetEqual(set(noteInfo['tags']), {'tag1'}) self.assertIn('tag1', noteInfo['tags']) self.assertNotIn('tag2', noteInfo['tags']) self.assertEqual(noteInfo['fields']['Front']['value'], 'front2') self.assertEqual(noteInfo['fields']['Back']['value'], 'back2') notes = [ {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front3', 'Back': 'back3'}, 'tags': ['tag']}, {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front4', 'Back': 'back4'}, 'tags': ['tag']} ] # canAddNotes (part 1) noteStates = util.invoke('canAddNotes', notes=notes) self.assertEqual(len(noteStates), len(notes)) self.assertNotIn(False, noteStates) # addNotes (part 1) noteIds = util.invoke('addNotes', notes=notes) self.assertEqual(len(noteIds), len(notes)) for noteId in noteIds: self.assertNotEqual(noteId, None) # canAddNotes (part 2) noteStates = util.invoke('canAddNotes', notes=notes) self.assertNotIn(True, noteStates) self.assertEqual(len(noteStates), len(notes)) # addNotes (part 2) noteIds = util.invoke('addNotes', notes=notes) self.assertEqual(len(noteIds), len(notes)) for noteId in noteIds: self.assertEqual(noteId, None) # findNotes noteIds = util.invoke('findNotes', query='deck:test') self.assertEqual(len(noteIds), len(notes) + 1) # deleteNotes util.invoke('deleteNotes', notes=noteIds) noteIds = util.invoke('findNotes', query='deck:test') self.assertEqual(len(noteIds), 0)
def runTest(self): # deckNames (part 1) deckNames = util.invoke('deckNames') self.assertIn('Default', deckNames) # deckNamesAndIds result = util.invoke('deckNamesAndIds') self.assertIn('Default', result) self.assertEqual(result['Default'], 1) # createDeck util.invoke('createDeck', deck='test1') # deckNames (part 2) deckNames = util.invoke('deckNames') self.assertIn('test1', deckNames) # changeDeck note = {'deckName': 'test1', 'modelName': 'Basic', 'fields': {'Front': 'front', 'Back': 'back'}, 'tags': ['tag']} noteId = util.invoke('addNote', note=note) cardIds = util.invoke('findCards', query='deck:test1') util.invoke('changeDeck', cards=cardIds, deck='test2') # deckNames (part 3) deckNames = util.invoke('deckNames') self.assertIn('test2', deckNames) # deleteDecks util.invoke('deleteDecks', decks=['test1', 'test2'], cardsToo=True) # deckNames (part 4) deckNames = util.invoke('deckNames') self.assertNotIn('test1', deckNames) self.assertNotIn('test2', deckNames) # getDeckConfig deckConfig = util.invoke('getDeckConfig', deck='Default') self.assertEqual('Default', deckConfig['name']) # saveDeckConfig deckConfig = util.invoke('saveDeckConfig', config=deckConfig) # setDeckConfigId setDeckConfigId = util.invoke('setDeckConfigId', decks=['Default'], configId=1) self.assertTrue(setDeckConfigId) # cloneDeckConfigId (part 1) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=1, name='test') self.assertTrue(deckConfigId) # removeDeckConfigId (part 1) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertTrue(removedDeckConfigId) # removeDeckConfigId (part 2) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertFalse(removedDeckConfigId) # cloneDeckConfigId (part 2) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=deckConfigId, name='test') self.assertFalse(deckConfigId)
def runTest(self): # deckNames (part 1) deckNames = util.invoke('deckNames') self.assertIn('Default', deckNames) # deckNamesAndIds result = util.invoke('deckNamesAndIds') self.assertIn('Default', result) self.assertEqual(result['Default'], 1) # createDeck util.invoke('createDeck', deck='test1') # deckNames (part 2) deckNames = util.invoke('deckNames') self.assertIn('test1', deckNames) # changeDeck note = {'deckName': 'test1', 'modelName': 'Basic', 'fields': {'Front': 'front', 'Back': 'back'}, 'tags': ['tag']} noteId = util.invoke('addNote', note=note) cardIds = util.invoke('findCards', query='deck:test1') util.invoke('changeDeck', cards=cardIds, deck='test2') # deckNames (part 3) deckNames = util.invoke('deckNames') self.assertIn('test2', deckNames) # deleteDecks util.invoke('deleteDecks', decks=['test1', 'test2'], cardsToo=True) # deckNames (part 4) deckNames = util.invoke('deckNames') self.assertNotIn('test1', deckNames) self.assertNotIn('test2', deckNames) # getDeckConfig deckConfig = util.invoke('getDeckConfig', deck='Default') self.assertEqual('Default', deckConfig['name']) # saveDeckConfig deckConfig = util.invoke('saveDeckConfig', config=deckConfig) # setDeckConfigId setDeckConfigId = util.invoke('setDeckConfigId', decks=['Default'], configId=1) self.assertTrue(setDeckConfigId) # cloneDeckConfigId (part 1) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=1, name='test') self.assertTrue(deckConfigId) # removeDeckConfigId (part 1) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertTrue(removedDeckConfigId) # removeDeckConfigId (part 2) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertFalse(removedDeckConfigId) # cloneDeckConfigId (part 2) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=deckConfigId, name='test') self.assertFalse(deckConfigId) # updateCompleteDeck util.invoke('updateCompleteDeck', data={ 'deck': 'test3', 'cards': { '12': { 'id': 12, 'nid': 23, 'ord': 0, 'type': 0, 'queue': 0, 'due': 1186031, 'factor': 0, 'ivl': 0, 'reps': 0, 'lapses': 0, 'left': 0 } }, 'notes': { '23': { 'id': 23, 'mid': 34, 'fields': ['frontValue', 'backValue'], 'tags': ['aTag'] } }, 'models': { '34': { 'id': 34, 'fields': ['Front', 'Back'], 'templateNames': ['Card 1'], 'name': 'anotherModel', } } }) deckNames = util.invoke('deckNames') self.assertIn('test3', deckNames) cardIDs = util.invoke('findCards', query='deck:test3') self.assertEqual(len(cardIDs), 1) self.assertEqual(cardIDs[0], 12)
def setUp(self): util.invoke('createDeck', deck='test') note = {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front1', 'Back': 'back1'}, 'tags': ['tag1']} self.noteId = util.invoke('addNote', note=note)
def runTest(self): # findCards cardIds = util.invoke('findCards', query='deck:test') self.assertEqual(len(cardIds), 1) # setEaseFactors EASE_TO_TRY = 4200 easeFactors = [EASE_TO_TRY for card in cardIds] couldGetEaseFactors = util.invoke('setEaseFactors', cards=cardIds, easeFactors=easeFactors) self.assertEqual([True for card in cardIds], couldGetEaseFactors) # getEaseFactors easeFactorsFound = util.invoke('getEaseFactors', cards=cardIds) self.assertEqual(easeFactors, easeFactorsFound) # suspend util.invoke('suspend', cards=cardIds) # areSuspended (part 1) suspendedStates = util.invoke('areSuspended', cards=cardIds) self.assertEqual(len(cardIds), len(suspendedStates)) self.assertNotIn(False, suspendedStates) # unsuspend util.invoke('unsuspend', cards=cardIds) # areSuspended (part 2) suspendedStates = util.invoke('areSuspended', cards=cardIds) self.assertEqual(len(cardIds), len(suspendedStates)) self.assertNotIn(True, suspendedStates) # areDue dueStates = util.invoke('areDue', cards=cardIds) self.assertEqual(len(cardIds), len(dueStates)) self.assertNotIn(False, dueStates) # getIntervals util.invoke('getIntervals', cards=cardIds, complete=True) util.invoke('getIntervals', cards=cardIds, complete=False) # cardsToNotes noteIds = util.invoke('cardsToNotes', cards=cardIds) self.assertEqual(len(noteIds), len(cardIds)) self.assertIn(self.noteId, noteIds) # cardsInfo cardsInfo = util.invoke('cardsInfo', cards=cardIds) self.assertEqual(len(cardsInfo), len(cardIds)) for i, cardInfo in enumerate(cardsInfo): self.assertEqual(cardInfo['cardId'], cardIds[i])
def runTest(self): # deckNames (part 1) deckNames = util.invoke('deckNames') self.assertIn('Default', deckNames) # deckNamesAndIds result = util.invoke('deckNamesAndIds') self.assertIn('Default', result) self.assertEqual(result['Default'], 1) # createDeck util.invoke('createDeck', deck='test1') # deckNames (part 2) deckNames = util.invoke('deckNames') self.assertIn('test1', deckNames) # changeDeck note = { 'deckName': 'test1', 'modelName': 'Basic', 'fields': { 'Front': 'front', 'Back': 'back' }, 'tags': ['tag'] } noteId = util.invoke('addNote', note=note) cardIds = util.invoke('findCards', query='deck:test1') util.invoke('changeDeck', cards=cardIds, deck='test2') # deckNames (part 3) deckNames = util.invoke('deckNames') self.assertIn('test2', deckNames) # deleteDecks util.invoke('deleteDecks', decks=['test1', 'test2'], cardsToo=True) # deckNames (part 4) deckNames = util.invoke('deckNames') self.assertNotIn('test1', deckNames) self.assertNotIn('test2', deckNames) # getDeckConfig deckConfig = util.invoke('getDeckConfig', deck='Default') self.assertEqual('Default', deckConfig['name']) # saveDeckConfig deckConfig = util.invoke('saveDeckConfig', config=deckConfig) # setDeckConfigId setDeckConfigId = util.invoke('setDeckConfigId', decks=['Default'], configId=1) self.assertTrue(setDeckConfigId) # cloneDeckConfigId (part 1) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=1, name='test') self.assertTrue(deckConfigId) # removeDeckConfigId (part 1) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertTrue(removedDeckConfigId) # removeDeckConfigId (part 2) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertFalse(removedDeckConfigId) # cloneDeckConfigId (part 2) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=deckConfigId, name='test') self.assertFalse(deckConfigId)
def runTest(self): # deckNames (part 1) deckNames = util.invoke('deckNames') self.assertIn('Default', deckNames) # deckNamesAndIds result = util.invoke('deckNamesAndIds') self.assertIn('Default', result) self.assertEqual(result['Default'], 1) # createDeck util.invoke('createDeck', deck='test1') # deckNames (part 2) deckNames = util.invoke('deckNames') self.assertIn('test1', deckNames) # changeDeck note = { 'deckName': 'test1', 'modelName': 'Basic', 'fields': { 'Front': 'front', 'Back': 'back' }, 'tags': ['tag'] } noteId = util.invoke('addNote', note=note) cardIds = util.invoke('findCards', query='deck:test1') util.invoke('changeDeck', cards=cardIds, deck='test2') # deckNames (part 3) deckNames = util.invoke('deckNames') self.assertIn('test2', deckNames) # deleteDecks util.invoke('deleteDecks', decks=['test1', 'test2'], cardsToo=True) # deckNames (part 4) deckNames = util.invoke('deckNames') self.assertNotIn('test1', deckNames) self.assertNotIn('test2', deckNames) # getDeckConfig deckConfig = util.invoke('getDeckConfig', deck='Default') self.assertEqual('Default', deckConfig['name']) # saveDeckConfig deckConfig = util.invoke('saveDeckConfig', config=deckConfig) # setDeckConfigId setDeckConfigId = util.invoke('setDeckConfigId', decks=['Default'], configId=1) self.assertTrue(setDeckConfigId) # cloneDeckConfigId (part 1) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=1, name='test') self.assertTrue(deckConfigId) # removeDeckConfigId (part 1) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertTrue(removedDeckConfigId) # removeDeckConfigId (part 2) removedDeckConfigId = util.invoke('removeDeckConfigId', configId=deckConfigId) self.assertFalse(removedDeckConfigId) # cloneDeckConfigId (part 2) deckConfigId = util.invoke('cloneDeckConfigId', cloneFrom=deckConfigId, name='test') self.assertFalse(deckConfigId) # updateCompleteDeck util.invoke("updateCompleteDeck", data={ "deck": "test3", "cards": { "12": { "id": 12, "nid": 23, "ord": 0, "type": 0, "queue": 0, "due": 1186031, "factor": 0, "ivl": 0, "reps": 0, "lapses": 0, "left": 0 } }, "notes": { "23": { "id": 23, "mid": 34, "fields": ["frontValue", "backValue"], "tags": ["aTag"] } }, "models": { "34": { "id": 34, "fields": ["Front", "Back"], "templateNames": ["Card 1"], "name": "anotherModel", } } }) deckNames = util.invoke("deckNames") self.assertIn("test3", deckNames) cardIDs = util.invoke('findCards', query='deck:test3') self.assertEqual(len(cardIDs), 1) self.assertEqual(cardIDs[0], 12)
def runTest(self): # modelNames modelNames = util.invoke('modelNames') self.assertGreater(len(modelNames), 0) # modelNamesAndIds modelNamesAndIds = util.invoke('modelNamesAndIds') self.assertGreater(len(modelNames), 0) # modelFieldNames modelFields = util.invoke('modelFieldNames', modelName=modelNames[0]) # modelFieldsOnTemplates modelFieldsOnTemplates = util.invoke('modelFieldsOnTemplates', modelName=modelNames[0]) # createModel with css newModel = util.invoke('createModel', modelName=MODEL_1_NAME, inOrderFields=['field1', 'field2'], cardTemplates=[CARD_1_TEMPLATE], css=CSS) # createModel without css newModel = util.invoke('createModel', modelName=MODEL_2_NAME, inOrderFields=['field1', 'field2'], cardTemplates=[CARD_1_TEMPLATE]) # modelStyling: get model 1 css css = util.invoke('modelStyling', modelName=MODEL_1_NAME) self.assertEqual({'css': CSS}, css) # modelTemplates: get model 1 templates templates = util.invoke('modelTemplates', modelName=MODEL_1_NAME) self.assertEqual({'Card 1': CARD_1_TEMPLATE}, templates) # updateModelStyling: change and verify model css util.invoke('updateModelStyling', model={ 'name': MODEL_1_NAME, 'css': NEW_CSS }) new_css = util.invoke('modelStyling', modelName=MODEL_1_NAME) self.assertEqual({'css': NEW_CSS}, new_css) # updateModelTemplates: change and verify model 1 templates util.invoke('updateModelTemplates', model={ 'name': MODEL_1_NAME, 'templates': { 'Card 1': NEW_CARD_1_TEMPLATE } }) templates = util.invoke('modelTemplates', modelName=MODEL_1_NAME) self.assertEqual({'Card 1': NEW_CARD_1_TEMPLATE}, templates) # findAndReplaceInModels: find and replace text in all models or model by name util.invoke('findAndReplaceInModels', modelName=MODEL_1_NAME, findText=TEXT_TO_REPLACE, replaceText=REPLACE_WITH_TEXT, front=True, back=True, css=True) new_css = util.invoke('modelStyling', modelName=MODEL_1_NAME) self.assertEqual({'css': REPLACE_WITH_TEXT}, new_css)