How to use list_vocabularies method in localstack

Best Python code snippet using localstack_python

store_test.py

Source:store_test.py Github

copy

Full Screen

...28 languages)29 def test_voc(self):30 self._create_vocabulary()31 self._create_user()32 vocs = self.db.list_vocabularies(self.user).values()33 self.assertEqual(1, len(vocs))34 self.assertEqual([self.word1, self.word2],35 next(iter(vocs)).words)36 voc2 = self.db.get_vocabulary(self.user, 1)37 self.assertEqual([self.word1, self.word2],38 voc2.words)39 def test_manage_sessions(self):40 self._create_vocabulary()41 self._create_user()42 self.assertIsNone(self.db.last_session(self.user, self.new_voc))43 session_id = self.db.create_new_session(self.user, self.new_voc)44 self.assertIsNotNone(session_id)45 session = self.db.last_session(self.user, self.new_voc)46 self.assertEqual(session_id.id, session.id)47 first_word = session.current_word48 self.assertTrue((self.word1 == session.current_word) or49 (self.word2 == session.current_word))50 word_attempt = session.guess(session.current_word,51 session.current_word.word_output)52 self.db.add_word_attempt(session, word_attempt)53 db_session = self.db.load_session(session.id)54 self.assertNotEqual(first_word, db_session.current_word)55 self.assertFalse(db_session.is_finished)56 self.assertIsNone(self.db.last_session(self.user, self.new_voc,57 finished=True))58 self.assertIsNotNone(self.db.last_session(self.user, self.new_voc,59 finished=False))60 word_attempt = session.guess(session.current_word,61 session.current_word.word_output)62 self.db.add_word_attempt(session, word_attempt)63 db_session = self.db.load_session(session.id)64 self.assertTrue(db_session.is_finished)65 self.assertEqual(100.0, db_session.accuracy)66 self.assertIsNone(self.db.last_session(self.user, self.new_voc,67 finished=False))68 self.assertIsNotNone(self.db.last_session(self.user, self.new_voc,69 finished=True))70 def test_vocabulary_stats(self):71 self._create_user()72 self._create_vocabulary()73 new_session = self.db.create_new_session(self.user, self.new_voc)74 word = new_session.current_word75 attempt = new_session.guess(word, 'bla')76 self.db.add_word_attempt(new_session, attempt)77 other_word = new_session.current_word78 stats = self.db.vocabulary_stats(self.new_voc)79 self.assertEqual(100.0, stats.errors_prob_for(word))80 self.assertEqual(0.0, stats.errors_prob_for(other_word))81 def test_user(self):82 self._create_user()83 self.assertIsNotNone(self.user)84 with self.assertRaises(DbException):85 self.db.create_user('test@hotmail.com', 'other', set())86 with self.assertRaises(DbException):87 self.db.get_user('test2@gmail.com', 'def')88 with self.assertRaises(DbException):89 self.db.get_user('test@hotmail.com', 'def')90 other_user = self.db.get_user('test@hotmail.com', 'abc')91 self.assertEqual('test@hotmail.com', other_user.email)92 def test_normal_vocabulary(self):93 self._create_vocabulary()94 self._create_user({Language.FRENCH})95 vocs = self.db.list_vocabularies(self.user)96 self.assertEqual(1, len(vocs))97 first_voc = next(iter(vocs.values()))98 self.assertFalse(first_voc.is_flipped)99 first_voc = self.db.get_vocabulary(self.user, first_voc.id)100 self.assertFalse(first_voc.is_flipped)101 self.assertEqual('fr', first_voc.input_language)102 self.assertEqual('de', first_voc.output_language)103 self.assertEqual([self.word1, self.word2],104 first_voc.words)105 new_session = self.db.create_new_session(self.user, first_voc)106 self.assertFalse(new_session.is_flipped)107 self.assertIn(new_session.current_word,108 {self.word1, self.word2})109 session_fetched = self.db.last_session(self.user, first_voc)110 self.assertIn(session_fetched.current_word,111 {self.word1, self.word2})112 session_fetched2 = self.db.load_session(session_fetched.id)113 self.assertIn(session_fetched2.current_word,114 {self.word1, self.word2})115 current_word = session_fetched.current_word116 attempt = session_fetched.guess(current_word, current_word.word_input)117 self.db.add_word_attempt(session_fetched, attempt)118 def test_flipped_vocabulary(self):119 self._create_vocabulary()120 self._create_user({Language.GERMAN})121 vocs = self.db.list_vocabularies(self.user)122 self.assertEqual(1, len(vocs))123 first_voc = next(iter(vocs.values()))124 first_voc = self.db.get_vocabulary(self.user, first_voc.id)125 self.assertTrue(first_voc.is_flipped)126 self.assertEqual('de', first_voc.input_language)127 self.assertEqual('fr', first_voc.output_language)128 self.assertEqual([self.word1.flip(), self.word2.flip()],129 first_voc.words)130 new_session = self.db.create_new_session(self.user, first_voc)131 self.assertIn(new_session.current_word,132 {self.word1.flip(), self.word2.flip()})133 self.assertTrue(new_session.is_flipped)134 self.assertTrue(first_voc.is_flipped)135 session_fetched = self.db.last_session(self.user, first_voc)136 self.assertTrue(session_fetched.is_flipped)137 self.assertIn(session_fetched.current_word,138 {self.word1.flip(), self.word2.flip()})139 session_fetched2 = self.db.load_session(session_fetched.id)140 self.assertIn(session_fetched2.current_word,141 {self.word1.flip(), self.word2.flip()})142 current_word = session_fetched.current_word143 attempt = session_fetched.guess(current_word, current_word.word_input)144 self.db.add_word_attempt(session_fetched, attempt)145 def test_list_vocabulary(self):146 self._create_vocabulary()147 self._create_user()148 vocs = self.db.list_vocabularies_for(None)149 self.assertEqual({1}, vocs.keys())150 voc = next(iter(vocs.values()))151 self.assertEqual(self.new_voc.words, voc.words)152 self.assertIsNone(self.db.get_vocabulary(None, 2))153 self.assertEqual([self.word1, self.word2],154 self.db.get_vocabulary(None, 1).words)155 def test_same_name_several_times(self):156 word1 = Word(word_input='fr_1',157 word_output='de_1',158 directive=None)159 word2 = Word(word_input='fr_1',160 word_output='de_1',161 directive='#name')162 words = [word1, word2]163 new_voc = Vocabulary(word1, words,164 input_language='fr',165 output_language='de')166 self._create_user()167 self.db.create_vocabulary(new_voc)168 self.db.create_new_session(self.user, new_voc)169 session = self.db.last_session(self.user, new_voc)170 word_attempt = session.guess(word2, word2.word_output)171 self.db.add_word_attempt(session, word_attempt)172 self.assertTrue(word_attempt.success)173 self.db.last_session(self.user, new_voc)174 def test_remove_vocabulary(self):175 self._create_vocabulary()176 self._create_user()177 self.db.create_new_session(self.user, self.new_voc)178 session = self.db.last_session(self.user, self.new_voc)179 session.guess(self.word1, self.word1.word_output)180 self.db.remove_vocabulary(self.new_voc)181 self.assertEqual({}, self.db.list_vocabularies(None))182 def test_add_word(self):183 self._create_vocabulary()184 self._create_user()185 self.word3 = Word(word_input='fr_3',186 word_output='de_3',187 directive=None)188 self.db.add_word(self.new_voc, self.word3)189 self.db.update_word(self.new_voc, self.word3,190 word_input='fr_4',191 word_output='de_4',192 directive='#name')193 vocs = self.db.list_vocabularies(None)194 new_word = Word(word_input='fr_4',195 word_output='de_4',196 directive='#name')197 self.assertIn(new_word, vocs[self.new_voc.id].words)198 def test_save_same_words_twice(self):199 self._create_vocabulary()200 self._create_user()201 session_id = self.db.create_new_session(self.user, self.new_voc)202 self.assertIsNotNone(session_id)203 session = self.db.last_session(self.user, self.new_voc)204 self.assertEqual(session_id.id, session.id)205 first_word = session.current_word206 word_attempt = session.guess(session.current_word,207 session.current_word.word_output)...

Full Screen

Full Screen

lx.py

Source:lx.py Github

copy

Full Screen

1import requests2url = 'https://www.shanbay.com/api/v1/vocabtest/category/'3headers = {'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}4# 0: ["GMAT", "GMAT"]5# 1: ["NGEE", "考研"]6# 2: ["NCEE", "高考"]7# 3: ["CET4", "四级"]8# 4: ["CET6", "六级"]9# 5: ["TEM", "英专"]10# 6: ["TOEFL", "托福"]11# 7: ["GRE", "GRE"]12# 8: ["IELTS", "雅思"]13# 9: ["NONE", "任意"]14res = requests.get(url, headers=headers)15res_json = res.json()16datas = res_json['data']17i = 018for data in datas:19 print(str(i) + '--' + str(data))20 i = i + 1 21choice = int(input('请输入你的选择:'))22url1 = 'https://www.shanbay.com/api/v1/vocabtest/vocabularies/?' + datas[choice][0]23res = requests.get(url1, headers=headers)24#print(res.status_code)25voc_json = res.json()26vocabularies = voc_json['data']27list_vocabularies = []28for v in vocabularies:29 list_vocabularies.append(v['content'])30words_knows = []31not_knows = []32for i in range(50):33 print( str(i) + ' ' + list_vocabularies[i] + '\n')34 x = input('认识输入1,不认识输入0:')35 if x == '1':36 words_knows.append(list_vocabularies[i])37 else:38 not_knows.append(list_vocabularies[i])39print('你认识' + str(len(words_knows)) + '个单词\n分别是:')40for i in range(len(words_knows)):41 print(words_knows[i])42 43# 参考答案 44"""45import requests46link = requests.get('https://www.shanbay.com/api/v1/vocabtest/category/')47#先用requests下载链接。48js_link = link.json()49#解析下载得到的内容。50bianhao = int(input('''请输入你选择的词库编号,按Enter确认511,GMAT 2,考研 3,高考 4,四级 5,六级526,英专 7,托福 8,GRE 9,雅思 10,任意53>'''))54#让用户选择自己想测的词库,输入数字编号。int()来转换数据类型55ciku = js_link['data'][bianhao-1][0]56#利用用户输入的数字编号,获取题库的代码。如果以输入“高考”的编号“3”为例,那么ciku的值就是,在字典js_link中查找data的值,data是一个list,查找它的第bianhao-1,也就是第2个元素,得到的依然是一个list,再查找该list的第0个元素。最后得到的就是我们想要的NCEE。57test = requests.get('https://www.shanbay.com/api/v1/vocabtest/vocabularies/?category='+ciku)58#下载用于测试的50个单词。59words = test.json()60#对test进行解析。61danci = []62#新增一个list,用于统计用户认识的单词63words_knows = []64#创建一个空的列表,用于记录用户认识的单词。65not_knows = []66#创建一个空的列表,用于记录用户不认识的单词。67print ('测试现在开始。如果你认识这个单词,请输入Y,否则直接敲Enter:')68n=069for x in words['data']:70#启动一个循环,循环的次数等于单词的数量。71 n=n+172 print ("\n第"+str(n)+'个:'+x['content'])73 #加一个\n,用于换行。74 answer = input('认识请敲Y,否则敲Enter:')75 #让用户输入自己是否认识。76 if answer == 'Y':77 #如果用户认识:78 danci.append(x['content'])79 words_knows.append(x)80 #就把这个单词,追加进列表words_knows。81 else:82 #否则83 not_knows.append(x)84 #就把这个单词,追加进列表not_knows。85print ('\n在上述'+str(len(words['data']))+'个单词当中,有'+str(len(danci))+'个是你觉得自己认识的,它们是:')86print(danci)87print ('现在我们来检测一下,你有没有真正掌握它们:')88wrong_words = []89right_num = 090for y in words_knows:91 print('\n\n'+'A:'+y['definition_choices'][0]['definition'])92 #我们改用A、B、C、D,不再用rank值,下同93 print('B:'+y['definition_choices'][1]['definition'])94 print('C:'+y['definition_choices'][2]['definition'])95 print('D:'+y['definition_choices'][3]['definition'])96 xuanze = input('请选择单词\"'+y['content']+'\"的正确翻译(填写数字即可):')97 dic = {'A':y['definition_choices'][0]['rank'],'B':y['definition_choices'][1]['rank'],'C':y['definition_choices'][2]['rank'],'D':y['definition_choices'][3]['rank']} 98 #我们创建一个字典,搭建起A、B、C、D和四个rank值的映射关系。99 if dic[xuanze] == y['rank']:100 #此时dic[xuanze]的内容,其实就是rank值,此时的代码含义已经和之前的版本相同了。101 right_num += 1102 else:103 wrong_words.append(y)104print ('现在,到了公布成绩的时刻:')105print ('在'+str(len(words['data']))+'个'+js_link['data'][bianhao-1][1]+'词汇当中,你认识其中'+str(len(danci))+'个,实际掌握'+str(right_num)+'个,错误'+str(len(wrong_words))+'个。')106#这是句蛮复杂的话,对照前面的代码和json文件你才能理解它。一个运行示例是:在50个高考词汇当中,你认识其中30个,实际掌握25个,错误5个。107save = input ('是否打印并保存你的错词集?填入Y或N: ')108#询问用户,是否要打印并保存错题集。109if save == 'Y':110#如果用户说是:111 f = open('错题集.txt', 'a+')112 #在当前目录下,创建一个错题集.txt的文档。 113 print ('你记错的单词有:')114 f.write('你记错的单词有:\n')115 #写入"你记错的单词有:\n"116 m=0117 for z in wrong_words:118 #启动一个循环,循环的次数等于,用户的错词数:119 m=m+1120 print (z['content'])121 #打印每一个错词。122 f.write(str(m+1) +'. '+ z['content']+'\n')123 #写入序号,写入错词。 124 print ('你不认识的单词有:')125 f.write('你没记住的单词有:\n')126 #写入"你没记住的单词有:\n"127 s=0128 for x in not_knows:129 #启动一个循环,循环的次数等于,用户不认识的单词数。130 print (x['content'])131 #打印每一个不认识的单词。132 f.write(str(s+1) +'. '+ x['content']+'\n')133 #写入序号,写入用户不认识的词汇。 134 print ('错词和没记住的词已保存至当前文件目录下,下次见!')135 #告诉用户,文件已经保存好。136 #在网页版终端运行时,文件会被写在课程的服务器上,你看不到,但它的确已经存在。137else:138#如果用户不想保存:139 print('下次见!')140 #输出“下次见!”141 ...

Full Screen

Full Screen

list_vocabs.py

Source:list_vocabs.py Github

copy

Full Screen

1import boto32from .basics import list_vocabularies3def main():4 transcribe_client = boto3.client('transcribe')5 print("Vocabs: ", list_vocabularies(transcribe_client))6if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful