Best Python code snippet using localstack_python
test_multi_language_vocabulary.py
Source:test_multi_language_vocabulary.py
...37def test_vocabulary_construction(multi_language_vocabulary):38 assert multi_language_vocabulary.total_token_count == 5 * 539 assert multi_language_vocabulary.language_count == 540 assert multi_language_vocabulary.metadata == {}41 assert multi_language_vocabulary.get_vocabulary("second").token_count() == 542 with pytest.raises(KeyError):43 multi_language_vocabulary.get_vocabulary("sixth")44def test_add_token(multi_language_vocabulary):45 multi_language_vocabulary.add_token(language="first", token="sixth")46 assert multi_language_vocabulary.get_vocabulary("first").index_to_token[5] == "sixth"47 multi_language_vocabulary.add_token(language="sixth", token="first")48 assert multi_language_vocabulary.language_count == 649 assert multi_language_vocabulary.total_token_count == 5 * 5 + 1 + 150 multi_language_vocabulary.add_tokens(language="seventh", tokens=["first", "second"])51 assert multi_language_vocabulary.language_count == 752 assert multi_language_vocabulary.total_token_count == 5 * 5 + 1 + 1 + 253def test_from_json(multi_language_vocabulary_json):54 token_list = ["first", "second", "third", "fourth", "fifth"]55 multi_language_vocabulary = MultiLanguageVocabulary.from_json(multi_language_vocabulary_json)56 assert multi_language_vocabulary.language_count == 557 assert multi_language_vocabulary.languages == token_list58 assert multi_language_vocabulary.metadata == {}59 assert multi_language_vocabulary.get_vocabulary("first").token_count() == 560 vocabulary_json = {"tokens": token_list, "metadata": {}}61 with pytest.raises(KeyError):62 Vocabulary.from_json(vocabulary_json)63def test_to_json(multi_language_vocabulary):64 token_list = ["first", "second", "third", "fourth", "fifth"]65 vocabulary_json = multi_language_vocabulary.to_json()66 assert vocabulary_json["language_count"] == 567 assert not vocabulary_json["vocabularies"]["third"]["contains_defaults"]68 assert vocabulary_json["metadata"] == {}69 assert vocabulary_json["languages"] == token_list70 assert vocabulary_json["token_count"] == 5 * 571def test_to_json_file(tmp_path, multi_language_vocabulary):72 multi_language_vocabulary.to_json_file(json_file_path=tmp_path / "test_vocabulary.json")73 reloaded_vocabulary = MultiLanguageVocabulary.from_json_file(json_file_path=tmp_path / "test_vocabulary.json")74 assert multi_language_vocabulary.total_token_count == reloaded_vocabulary.total_token_count75 assert multi_language_vocabulary.language_count == reloaded_vocabulary.language_count76 assert sorted(multi_language_vocabulary.languages) == reloaded_vocabulary.languages77 assert multi_language_vocabulary.metadata == reloaded_vocabulary.metadata78def test_from_json_file():79 multi_language_vocabulary = MultiLanguageVocabulary.from_json_file(80 parent_path / Path("test_files/test_multi_language_vocabulary.json")81 )82 assert multi_language_vocabulary.total_token_count == 5 * 583 assert multi_language_vocabulary.languages == ["first", "second", "third", "fourth", "fifth"]84 assert multi_language_vocabulary.language_count == 585 assert not multi_language_vocabulary.get_vocabulary("first").contains_defaults...
test_api.py
Source:test_api.py
...70 'missing', self.term.slug)71 with self.assertRaises(NotFound):72 get_term(self.repo.slug, self.user.id,73 self.vocabulary.slug, 'missing')74 def test_get_vocabulary(self):75 """76 Test get_vocabulary77 """78 actual_vocabulary = get_vocabulary(79 self.repo.slug, self.user.id, self.vocabulary.slug)80 self.assertEqual(self.vocabulary, actual_vocabulary)81 with self.assertRaises(NotFound):82 get_vocabulary("missing", self.user.id, self.vocabulary.slug)83 with self.assertRaises(PermissionDenied):84 get_vocabulary(self.repo.slug, -1, self.vocabulary.slug)85 with self.assertRaises(NotFound):...
mastertables.py
Source:mastertables.py
...15 self.host = host16 self.api_key = api_key1718 @vocabulary_cache19 def get_vocabulary(self, vocabulary, category=None):20 url = self.host21 url += "vocabularies/api/public_api/get_vocabulary/"22 querystring = {"api_key":self.api_key, "vocabulary": vocabulary}23 if category:24 querystring['category'] = category2526 headers = {27 'Content-Type': "application/json",28 'Cache-Control': "no-cache"29 }3031 response = requests.request("GET", url, headers=headers, params=querystring)3233 res = json.loads(response.text)34 if res.has_key('vocabulary'):35 res = res['vocabulary']36 detail = res.get('detail', '')37 if detail == 'Authentication credentials were not provided.':38 raise AttributeError39 return res4041 def get_vocabulary_reverse(self, vocabulary, category=None):42 res = self.get_vocabulary(vocabulary)43 res = dict((v,k) for k,v in res.iteritems())44 return res4546 def get_values(self, vocabulary):47 res = self.get_vocabulary(vocabulary)48 res = res.keys()49 return res5051 def get_value(self, vocabulary, key, index=0):52 res = self.get_vocabulary(vocabulary)53 try:54 res = res[key].split(',')[index]55 except Exception as e:56 res = 'Incorrect params (' + str(e.message) + ')'57
...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!