Best Python code snippet using tempest_python
webserv.py
Source:webserv.py
...51 webserv = self._factory.new(self._repository_id)52 webserv.add_credentials("lxnay", "test")53 self.assertEqual(webserv.get_credentials(), "lxnay")54 self.assertEqual(webserv.credentials_available(), True)55 self.assertTrue(webserv.remove_credentials())56 self.assertEqual(webserv.credentials_available(), False)57 def test_credentials_utf8(self):58 user = const_convert_to_unicode("lxnà y")59 password = const_convert_to_unicode("pà à à à ss")60 webserv = self._factory.new(self._repository_id)61 self.assertTrue(webserv.service_available(cache = False))62 webserv.add_credentials(user, password)63 self.assertEqual(webserv.get_credentials(), user)64 self.assertEqual(webserv.credentials_available(), True)65 self.assertTrue(webserv.remove_credentials())66 self.assertEqual(webserv.credentials_available(), False)67 def test_validate_credentials(self):68 webserv = self._factory.new(self._repository_id)69 webserv.remove_credentials()70 webserv.add_credentials(self._fake_user, self._fake_pass)71 try:72 self.assertTrue(webserv.credentials_available())73 self.assertEqual(webserv.get_credentials(), self._fake_user)74 # credentials must be valid75 webserv.validate_credentials()76 finally:77 webserv.remove_credentials()78 def test_validate_credentials_error(self):79 webserv = self._factory.new(self._repository_id)80 webserv.remove_credentials()81 user = const_convert_to_unicode("lxnay")82 password = const_convert_to_unicode("paasssdsss")83 webserv.add_credentials(user, password)84 try:85 self.assertTrue(webserv.credentials_available())86 self.assertEqual(webserv.get_credentials(), user)87 # credentials must be INVALID88 self.assertRaises(WebService.AuthenticationFailed,89 webserv.validate_credentials)90 finally:91 webserv.remove_credentials()92 def test_validate_credentials_utf8(self):93 webserv = self._factory.new(self._repository_id)94 webserv.remove_credentials()95 webserv.add_credentials(self._fake_unicode_user,96 self._fake_unicode_pass)97 try:98 self.assertTrue(webserv.credentials_available())99 self.assertEqual(webserv.get_credentials(), self._fake_unicode_user)100 # credentials must be valid101 webserv.validate_credentials()102 finally:103 webserv.remove_credentials()104 def test_query_utf8(self):105 webserv = self._factory.new(self._repository_id)106 # this must raise WebService.MethodResponseError107 self.assertRaises(WebService.MethodResponseError,108 webserv.get_votes, (self._fake_package_name_utf8,))109 def test_get_votes(self):110 webserv = self._factory.new(self._repository_id)111 # this must return valid data112 vote_data = webserv.get_votes([self._fake_package_name], cache = False)113 self.assertTrue(isinstance(vote_data, dict))114 self.assertTrue(self._fake_package_name in vote_data)115 if vote_data[self._fake_package_name] is not None:116 self.assertTrue(isinstance(vote_data[self._fake_package_name], float))117 else:118 self.assertTrue(vote_data[self._fake_package_name] is None)119 def test_get_available_votes(self):120 webserv = self._factory.new(self._repository_id)121 # this must return valid data122 vote_data = webserv.get_available_votes(cache = False)123 self.assertTrue(isinstance(vote_data, dict))124 self.assertTrue(self._real_package_name in vote_data)125 self.assertTrue(isinstance(vote_data[self._real_package_name], float))126 for key, val in vote_data.items():127 self.assertTrue(entropy.tools.validate_package_name(key))128 self.assertTrue(isinstance(val, float))129 self.assertTrue(int(val) in ClientWebService.VALID_VOTES)130 def test_get_votes_cannot_exists(self):131 webserv = self._factory.new(self._repository_id)132 key = "app-doesntexistforsure/asdweasfoo"133 # this must return valid data134 vote_data = webserv.get_votes([key], cache = False)135 self.assertTrue(isinstance(vote_data, dict))136 self.assertTrue(key in vote_data)137 self.assertTrue(vote_data[key] is None)138 def test_add_vote(self):139 webserv = self._factory.new(self._repository_id)140 self.assertTrue(webserv.service_available(cache = False))141 # try with success142 webserv.remove_credentials()143 try:144 webserv.add_vote(self._fake_package_name, 4)145 # webserv.AuthenticationRequired should be raised146 self.assertTrue(False)147 except webserv.AuthenticationRequired:148 webserv.add_credentials(self._fake_user, self._fake_pass)149 self.assertTrue(webserv.credentials_available())150 self.assertEqual(webserv.get_credentials(), self._fake_user)151 # credentials must be valid152 webserv.validate_credentials()153 # now it should not crash154 webserv.add_vote(self._fake_package_name, 4)155 finally:156 webserv.remove_credentials()157 # now check back if average vote is still 4.0158 vote = webserv.get_votes(159 [self._fake_package_name])[self._fake_package_name]160 self.assertEqual(vote, 4.0)161 def test_add_vote_failure(self):162 webserv = self._factory.new(self._repository_id)163 self.assertTrue(webserv.service_available(cache = False))164 # try with success165 webserv.remove_credentials()166 invalid_package_name = self._fake_package_name + "'''"167 try:168 webserv.add_credentials(self._fake_user, self._fake_pass)169 self.assertTrue(webserv.credentials_available())170 self.assertEqual(webserv.get_credentials(), self._fake_user)171 # credentials must be valid172 webserv.validate_credentials()173 webserv.add_vote(invalid_package_name, 4)174 self.assertTrue(False)175 except webserv.MethodResponseError:176 self.assertTrue(True) # valid177 finally:178 webserv.remove_credentials()179 # now check back if average vote is still 4.0180 try:181 vote = webserv.get_votes(182 [invalid_package_name])[invalid_package_name]183 self.assertTrue(False)184 except webserv.MethodResponseError:185 self.assertTrue(True) # valid186 def test_get_available_downloads(self):187 webserv = self._factory.new(self._repository_id)188 # this must return valid data189 down_data = webserv.get_available_downloads(cache = False)190 self.assertTrue(isinstance(down_data, dict))191 self.assertTrue(self._real_package_name in down_data)192 self.assertTrue(isinstance(down_data[self._real_package_name], int))193 for key, val in down_data.items():194 self.assertTrue(entropy.tools.validate_package_name(key))195 self.assertTrue(isinstance(val, int))196 self.assertTrue(val >= 0)197 def test_add_downloads(self):198 webserv = self._factory.new(self._repository_id)199 self.assertTrue(webserv.service_available(cache = False))200 pk = self._fake_package_name201 pkg_list = [pk]202 cur_downloads = webserv.get_downloads(pkg_list, cache = False)[pk]203 if cur_downloads is None:204 cur_downloads = 0205 # can be False if the test is run repeatedly, due to the anti-flood206 # protection207 added = webserv.add_downloads([self._fake_package_name])208 self.assertTrue(isinstance(added, bool))209 # expect (cur_downloads + 1) now, use cache, so to check if cache210 # is cleared correctly211 expected_downloads = cur_downloads212 if added:213 expected_downloads += 1214 new_downloads = webserv.get_downloads(pkg_list)[pk]215 self.assertEqual(expected_downloads, new_downloads)216 def test_add_icon(self):217 webserv = self._factory.new(self._repository_id)218 self.assertTrue(webserv.service_available(cache = False))219 doc_factory = webserv.document_factory()220 keywords = "keyword1 keyword2"221 description = const_convert_to_unicode("descrìption")222 title = const_convert_to_unicode("tìtle")223 tmp_fd, tmp_path = tempfile.mkstemp()224 with open(tmp_path, "ab+") as tmp_f:225 tmp_f.write(const_convert_to_rawstring('\x89PNG\x00\x00'))226 tmp_f.flush()227 tmp_f.seek(0)228 doc = doc_factory.icon(self._fake_user, tmp_f, title,229 description, keywords)230 webserv.remove_credentials()231 try:232 webserv.add_document(self._fake_package_name, doc)233 # webserv.AuthenticationRequired should be raised234 self.assertTrue(False)235 except webserv.AuthenticationRequired:236 webserv.add_credentials(self._fake_user, self._fake_pass)237 self.assertTrue(webserv.credentials_available())238 self.assertEqual(webserv.get_credentials(), self._fake_user)239 # credentials must be valid240 webserv.validate_credentials()241 # now it should not crash242 new_doc = webserv.add_document(self._fake_package_name, doc)243 # got the new document back, which is the same plus document_id244 finally:245 webserv.remove_credentials()246 # now check back if document is there247 doc_id = new_doc[Document.DOCUMENT_DOCUMENT_ID]248 remote_doc = webserv.get_documents_by_id([doc_id],249 cache = False)[doc_id]250 self.assertTrue(new_doc.is_icon())251 self.assertTrue(remote_doc.is_icon())252 self.assertTrue(not remote_doc.is_comment())253 self.assertTrue(not remote_doc.is_image())254 self.assertTrue(not remote_doc.is_video())255 self.assertTrue(not remote_doc.is_file())256 self.assertEqual(new_doc.repository_id(), self._repository_id)257 self.assertEqual(new_doc.document_type(), remote_doc.document_type())258 self.assertEqual(new_doc.document_id(), remote_doc.document_id())259 self.assertEqual(new_doc.repository_id(), remote_doc.repository_id())260 self.assertEqual(new_doc.document_keywords(), keywords)261 self.assertEqual(new_doc[DocumentFactory.DOCUMENT_USERNAME_ID],262 remote_doc[DocumentFactory.DOCUMENT_USERNAME_ID])263 self.assertEqual(new_doc[Document.DOCUMENT_DOCUMENT_ID],264 remote_doc[Document.DOCUMENT_DOCUMENT_ID])265 self.assertEqual(new_doc[Document.DOCUMENT_DESCRIPTION_ID],266 remote_doc[Document.DOCUMENT_DESCRIPTION_ID])267 self.assertEqual(remote_doc[Document.DOCUMENT_DESCRIPTION_ID],268 description)269 self.assertEqual(new_doc[Document.DOCUMENT_TITLE_ID],270 remote_doc[Document.DOCUMENT_TITLE_ID])271 self.assertEqual(remote_doc[Document.DOCUMENT_TITLE_ID], title)272 self.assertEqual(new_doc.document_timestamp(),273 remote_doc.document_timestamp())274 self.assertEqual(new_doc.document_keywords(),275 remote_doc.document_keywords())276 # now try to remove277 webserv.remove_credentials()278 try:279 webserv.remove_document(remote_doc[Document.DOCUMENT_DOCUMENT_ID])280 # webserv.AuthenticationRequired should be raised281 self.assertTrue(False)282 except webserv.AuthenticationRequired:283 webserv.add_credentials(self._fake_user, self._fake_pass)284 self.assertTrue(webserv.credentials_available())285 self.assertEqual(webserv.get_credentials(), self._fake_user)286 # credentials must be valid287 webserv.validate_credentials()288 # now it should not crash289 self.assertTrue(290 webserv.remove_document(291 remote_doc[Document.DOCUMENT_DOCUMENT_ID]))292 # got the new document back, which is the same plus document_id293 finally:294 webserv.remove_credentials()295 def test_add_icon_fail(self):296 webserv = self._factory.new(self._repository_id)297 self.assertTrue(webserv.service_available(cache = False))298 doc_factory = webserv.document_factory()299 keywords = "keyword1 keyword2"300 description = const_convert_to_unicode("descrìption")301 title = const_convert_to_unicode("tìtle")302 tmp_fd, tmp_path = tempfile.mkstemp()303 with open(tmp_path, "ab+") as tmp_f:304 img_dump = '\x89\xFF\x00\x00\x89\xFF\x89\xFF\x89\xFF'305 tmp_f.write(const_convert_to_rawstring(img_dump))306 tmp_f.flush()307 tmp_f.seek(0)308 doc = doc_factory.icon(self._fake_user, tmp_f, title,309 description, keywords)310 webserv.remove_credentials()311 try:312 webserv.add_document(self._fake_package_name, doc)313 # webserv.AuthenticationRequired should be raised314 self.assertTrue(False)315 except webserv.AuthenticationRequired:316 webserv.add_credentials(self._fake_user, self._fake_pass)317 self.assertTrue(webserv.credentials_available())318 self.assertEqual(webserv.get_credentials(), self._fake_user)319 # credentials must be valid320 webserv.validate_credentials()321 # now it should not crash322 self.assertRaises(WebService.MethodResponseError,323 webserv.add_document, self._fake_package_name, doc)324 # got the new document back, which is the same plus document_id325 finally:326 webserv.remove_credentials()327 def test_add_image_fail(self):328 webserv = self._factory.new(self._repository_id)329 self.assertTrue(webserv.service_available(cache = False))330 doc_factory = webserv.document_factory()331 keywords = "keyword1 keyword2"332 description = const_convert_to_unicode("descrìption")333 title = const_convert_to_unicode("tìtle")334 tmp_fd, tmp_path = tempfile.mkstemp()335 with open(tmp_path, "ab+") as tmp_f:336 img_dump = '\x89\xFF\x00\x00\x89\xFF\x89\xFF\x89\xFF'337 tmp_f.write(const_convert_to_rawstring(img_dump))338 tmp_f.flush()339 tmp_f.seek(0)340 doc = doc_factory.image(self._fake_user, tmp_f, title,341 description, keywords)342 webserv.remove_credentials()343 try:344 webserv.add_document(self._fake_package_name, doc)345 # webserv.AuthenticationRequired should be raised346 self.assertTrue(False)347 except webserv.AuthenticationRequired:348 webserv.add_credentials(self._fake_user, self._fake_pass)349 self.assertTrue(webserv.credentials_available())350 self.assertEqual(webserv.get_credentials(), self._fake_user)351 # credentials must be valid352 webserv.validate_credentials()353 # now it should not crash354 self.assertRaises(WebService.MethodResponseError,355 webserv.add_document, self._fake_package_name, doc)356 # got the new document back, which is the same plus document_id357 finally:358 webserv.remove_credentials()359 def test_add_image(self):360 webserv = self._factory.new(self._repository_id)361 self.assertTrue(webserv.service_available(cache = False))362 doc_factory = webserv.document_factory()363 keywords = "keyword1 keyword2"364 description = const_convert_to_unicode("descrìption")365 title = const_convert_to_unicode("tìtle")366 tmp_fd, tmp_path = tempfile.mkstemp()367 with open(tmp_path, "ab+") as tmp_f:368 tmp_f.write(const_convert_to_rawstring('\x89PNG\x00\x00'))369 tmp_f.flush()370 tmp_f.seek(0)371 doc = doc_factory.image(self._fake_user, tmp_f, title,372 description, keywords)373 webserv.remove_credentials()374 try:375 webserv.add_document(self._fake_package_name, doc)376 # webserv.AuthenticationRequired should be raised377 self.assertTrue(False)378 except webserv.AuthenticationRequired:379 webserv.add_credentials(self._fake_user, self._fake_pass)380 self.assertTrue(webserv.credentials_available())381 self.assertEqual(webserv.get_credentials(), self._fake_user)382 # credentials must be valid383 webserv.validate_credentials()384 # now it should not crash385 new_doc = webserv.add_document(self._fake_package_name, doc)386 # got the new document back, which is the same plus document_id387 finally:388 webserv.remove_credentials()389 # now check back if document is there390 doc_id = new_doc[Document.DOCUMENT_DOCUMENT_ID]391 remote_doc = webserv.get_documents_by_id([doc_id],392 cache = False)[doc_id]393 self.assertTrue(new_doc.is_image())394 self.assertTrue(remote_doc.is_image())395 self.assertTrue(not remote_doc.is_comment())396 self.assertTrue(not remote_doc.is_icon())397 self.assertTrue(not remote_doc.is_video())398 self.assertTrue(not remote_doc.is_file())399 self.assertEqual(new_doc.document_type(), remote_doc.document_type())400 self.assertEqual(new_doc.document_id(), remote_doc.document_id())401 self.assertEqual(new_doc.repository_id(), self._repository_id)402 self.assertEqual(new_doc.repository_id(), remote_doc.repository_id())403 self.assertEqual(new_doc.document_keywords(), keywords)404 self.assertEqual(new_doc[DocumentFactory.DOCUMENT_USERNAME_ID],405 remote_doc[DocumentFactory.DOCUMENT_USERNAME_ID])406 self.assertEqual(new_doc[Document.DOCUMENT_DOCUMENT_ID],407 remote_doc[Document.DOCUMENT_DOCUMENT_ID])408 self.assertEqual(new_doc[Document.DOCUMENT_DESCRIPTION_ID],409 remote_doc[Document.DOCUMENT_DESCRIPTION_ID])410 self.assertEqual(remote_doc[Document.DOCUMENT_DESCRIPTION_ID],411 description)412 self.assertEqual(new_doc[Document.DOCUMENT_TITLE_ID],413 remote_doc[Document.DOCUMENT_TITLE_ID])414 self.assertEqual(remote_doc[Document.DOCUMENT_TITLE_ID], title)415 self.assertEqual(new_doc.document_timestamp(),416 remote_doc.document_timestamp())417 self.assertEqual(new_doc.document_keywords(),418 remote_doc.document_keywords())419 # now try to remove420 webserv.remove_credentials()421 try:422 webserv.remove_document(remote_doc[Document.DOCUMENT_DOCUMENT_ID])423 # webserv.AuthenticationRequired should be raised424 self.assertTrue(False)425 except webserv.AuthenticationRequired:426 webserv.add_credentials(self._fake_user, self._fake_pass)427 self.assertTrue(webserv.credentials_available())428 self.assertEqual(webserv.get_credentials(), self._fake_user)429 # credentials must be valid430 webserv.validate_credentials()431 # now it should not crash432 self.assertTrue(433 webserv.remove_document(434 remote_doc[Document.DOCUMENT_DOCUMENT_ID]))435 # got the new document back, which is the same plus document_id436 finally:437 webserv.remove_credentials()438 def test_add_comment(self):439 webserv = self._factory.new(self._repository_id)440 self.assertTrue(webserv.service_available(cache = False))441 doc_factory = webserv.document_factory()442 keywords = "keyword1 keyword2"443 comment = const_convert_to_unicode("comment hellò")444 title = const_convert_to_unicode("tìtle")445 doc = doc_factory.comment(self._fake_user, comment, title, keywords)446 webserv.remove_credentials()447 try:448 webserv.add_document(self._fake_package_name, doc)449 # webserv.AuthenticationRequired should be raised450 self.assertTrue(False)451 except webserv.AuthenticationRequired:452 webserv.add_credentials(self._fake_user, self._fake_pass)453 self.assertTrue(webserv.credentials_available())454 self.assertEqual(webserv.get_credentials(), self._fake_user)455 # credentials must be valid456 webserv.validate_credentials()457 # now it should not crash458 new_doc = webserv.add_document(self._fake_package_name, doc)459 self.assertTrue(new_doc is not None)460 # got the new document back, which is the same plus document_id461 finally:462 webserv.remove_credentials()463 # now check back if document is there464 doc_id = new_doc[Document.DOCUMENT_DOCUMENT_ID]465 remote_doc = webserv.get_documents_by_id([doc_id],466 cache = False)[doc_id]467 self.assertTrue(remote_doc is not None)468 self.assertTrue(new_doc.is_comment())469 self.assertTrue(remote_doc.is_comment())470 self.assertTrue(not remote_doc.is_image())471 self.assertTrue(not remote_doc.is_icon())472 self.assertTrue(not remote_doc.is_video())473 self.assertTrue(not remote_doc.is_file())474 self.assertEqual(new_doc.repository_id(), self._repository_id)475 self.assertEqual(new_doc.document_type(), remote_doc.document_type())476 self.assertEqual(new_doc.document_id(), remote_doc.document_id())477 self.assertEqual(new_doc.repository_id(), remote_doc.repository_id())478 self.assertEqual(new_doc.document_keywords(), keywords)479 self.assertEqual(new_doc[DocumentFactory.DOCUMENT_USERNAME_ID],480 remote_doc[DocumentFactory.DOCUMENT_USERNAME_ID])481 self.assertEqual(new_doc[Document.DOCUMENT_DOCUMENT_ID],482 remote_doc[Document.DOCUMENT_DOCUMENT_ID])483 self.assertEqual(remote_doc[Document.DOCUMENT_DATA_ID], comment)484 self.assertEqual(new_doc[Document.DOCUMENT_TITLE_ID],485 remote_doc[Document.DOCUMENT_TITLE_ID])486 self.assertEqual(remote_doc[Document.DOCUMENT_TITLE_ID], title)487 self.assertEqual(new_doc.document_timestamp(),488 remote_doc.document_timestamp())489 self.assertEqual(new_doc.document_keywords(),490 remote_doc.document_keywords())491 # now try to remove492 webserv.remove_credentials()493 try:494 webserv.remove_document(remote_doc[Document.DOCUMENT_DOCUMENT_ID])495 # webserv.AuthenticationRequired should be raised496 self.assertTrue(False)497 except webserv.AuthenticationRequired:498 webserv.add_credentials(self._fake_user, self._fake_pass)499 self.assertTrue(webserv.credentials_available())500 self.assertEqual(webserv.get_credentials(), self._fake_user)501 # credentials must be valid502 webserv.validate_credentials()503 # now it should not crash504 self.assertTrue(505 webserv.remove_document(506 remote_doc[Document.DOCUMENT_DOCUMENT_ID]))507 # got the new document back, which is the same plus document_id508 finally:509 webserv.remove_credentials()510 def test_add_file(self):511 webserv = self._factory.new(self._repository_id)512 self.assertTrue(webserv.service_available())513 doc_factory = webserv.document_factory()514 keywords = "keyword1 keyword2"515 description = const_convert_to_unicode("descrìption")516 title = const_convert_to_unicode("tìtle")517 tmp_fd, tmp_path = tempfile.mkstemp()518 with open(tmp_path, "ab+") as tmp_f:519 tmp_f.write(const_convert_to_rawstring('BZ2\x00\x00'))520 tmp_f.flush()521 tmp_f.seek(0)522 doc = doc_factory.file(self._fake_user, tmp_f, title,523 description, keywords)524 webserv.remove_credentials()525 try:526 webserv.add_document(self._fake_package_name, doc)527 # webserv.AuthenticationRequired should be raised528 self.assertTrue(False)529 except webserv.AuthenticationRequired:530 webserv.add_credentials(self._fake_user, self._fake_pass)531 self.assertTrue(webserv.credentials_available())532 self.assertEqual(webserv.get_credentials(), self._fake_user)533 # credentials must be valid534 webserv.validate_credentials()535 # now it should not crash536 new_doc = webserv.add_document(self._fake_package_name, doc)537 self.assertTrue(new_doc is not None)538 # got the new document back, which is the same plus document_id539 finally:540 webserv.remove_credentials()541 # now check back if document is there542 doc_id = new_doc[Document.DOCUMENT_DOCUMENT_ID]543 remote_doc = webserv.get_documents_by_id([doc_id],544 cache = False)[doc_id]545 self.assertTrue(new_doc.is_file())546 self.assertTrue(remote_doc.is_file())547 self.assertTrue(not remote_doc.is_comment())548 self.assertTrue(not remote_doc.is_icon())549 self.assertTrue(not remote_doc.is_video())550 self.assertTrue(not remote_doc.is_image())551 self.assertEqual(new_doc.document_type(), remote_doc.document_type())552 self.assertEqual(new_doc.document_id(), remote_doc.document_id())553 self.assertEqual(new_doc.repository_id(), self._repository_id)554 self.assertEqual(new_doc.repository_id(), remote_doc.repository_id())555 self.assertEqual(new_doc.document_keywords(), keywords)556 self.assertEqual(new_doc[DocumentFactory.DOCUMENT_USERNAME_ID],557 remote_doc[DocumentFactory.DOCUMENT_USERNAME_ID])558 self.assertEqual(new_doc[Document.DOCUMENT_DOCUMENT_ID],559 remote_doc[Document.DOCUMENT_DOCUMENT_ID])560 self.assertEqual(new_doc[Document.DOCUMENT_DESCRIPTION_ID],561 remote_doc[Document.DOCUMENT_DESCRIPTION_ID])562 self.assertEqual(remote_doc[Document.DOCUMENT_DESCRIPTION_ID],563 description)564 self.assertEqual(new_doc[Document.DOCUMENT_TITLE_ID],565 remote_doc[Document.DOCUMENT_TITLE_ID])566 self.assertEqual(remote_doc[Document.DOCUMENT_TITLE_ID], title)567 self.assertEqual(new_doc.document_timestamp(),568 remote_doc.document_timestamp())569 self.assertEqual(new_doc.document_keywords(),570 remote_doc.document_keywords())571 # now try to remove572 webserv.remove_credentials()573 try:574 webserv.remove_document(remote_doc[Document.DOCUMENT_DOCUMENT_ID])575 # webserv.AuthenticationRequired should be raised576 self.assertTrue(False)577 except webserv.AuthenticationRequired:578 webserv.add_credentials(self._fake_user, self._fake_pass)579 self.assertTrue(webserv.credentials_available())580 self.assertEqual(webserv.get_credentials(), self._fake_user)581 # credentials must be valid582 webserv.validate_credentials()583 # now it should not crash584 self.assertTrue(585 webserv.remove_document(586 remote_doc[Document.DOCUMENT_DOCUMENT_ID]))587 # got the new document back, which is the same plus document_id588 finally:589 webserv.remove_credentials()590 def test_add_video(self):591 webserv = self._factory.new(self._repository_id)592 self.assertTrue(webserv.service_available())593 doc_factory = webserv.document_factory()594 keywords = "keyword1 keyword2"595 description = const_convert_to_unicode("descrìption")596 title = const_convert_to_unicode("tìtle")597 test_video_file = _misc.get_test_video_file()598 with open(test_video_file, "rb") as tmp_f:599 doc = doc_factory.video(self._fake_user, tmp_f, title,600 description, keywords)601 # do not actually publish the video602 doc['pretend'] = 1603 webserv.remove_credentials()604 try:605 webserv.add_document(self._fake_package_name, doc)606 # webserv.AuthenticationRequired should be raised607 self.assertTrue(False)608 except webserv.AuthenticationRequired:609 webserv.add_credentials(self._fake_user, self._fake_pass)610 self.assertTrue(webserv.credentials_available())611 self.assertEqual(webserv.get_credentials(), self._fake_user)612 # credentials must be valid613 webserv.validate_credentials()614 # now it should not crash615 new_doc = webserv.add_document(self._fake_package_name, doc)616 self.assertTrue(new_doc is not None)617 # got the new document back, which is the same plus document_id618 finally:619 webserv.remove_credentials()620 # now check back if document is there621 doc_id = new_doc[Document.DOCUMENT_DOCUMENT_ID]622 remote_doc = webserv.get_documents_by_id([doc_id],623 cache = False)[doc_id]624 self.assertTrue(new_doc.is_video())625 self.assertTrue(remote_doc.is_video())626 self.assertTrue(not remote_doc.is_comment())627 self.assertTrue(not remote_doc.is_icon())628 self.assertTrue(not remote_doc.is_file())629 self.assertTrue(not remote_doc.is_image())630 self.assertEqual(new_doc.document_type(), remote_doc.document_type())631 self.assertEqual(new_doc.document_id(), remote_doc.document_id())632 self.assertEqual(new_doc.repository_id(), self._repository_id)633 self.assertEqual(new_doc.repository_id(), remote_doc.repository_id())634 self.assertEqual(new_doc.document_keywords(), keywords)635 self.assertEqual(new_doc[DocumentFactory.DOCUMENT_USERNAME_ID],636 remote_doc[DocumentFactory.DOCUMENT_USERNAME_ID])637 self.assertEqual(new_doc[Document.DOCUMENT_DOCUMENT_ID],638 remote_doc[Document.DOCUMENT_DOCUMENT_ID])639 self.assertEqual(new_doc[Document.DOCUMENT_DESCRIPTION_ID],640 remote_doc[Document.DOCUMENT_DESCRIPTION_ID])641 self.assertEqual(remote_doc[Document.DOCUMENT_DESCRIPTION_ID],642 description)643 self.assertEqual(new_doc[Document.DOCUMENT_TITLE_ID],644 remote_doc[Document.DOCUMENT_TITLE_ID])645 self.assertEqual(remote_doc[Document.DOCUMENT_TITLE_ID], title)646 self.assertEqual(new_doc.document_timestamp(),647 remote_doc.document_timestamp())648 self.assertEqual(new_doc.document_keywords(),649 remote_doc.document_keywords())650 # now try to remove651 webserv.remove_credentials()652 try:653 webserv.remove_document(remote_doc[Document.DOCUMENT_DOCUMENT_ID])654 # webserv.AuthenticationRequired should be raised655 self.assertTrue(False)656 except webserv.AuthenticationRequired:657 webserv.add_credentials(self._fake_user, self._fake_pass)658 self.assertTrue(webserv.credentials_available())659 self.assertEqual(webserv.get_credentials(), self._fake_user)660 # credentials must be valid661 webserv.validate_credentials()662 # now it should not crash663 self.assertTrue(664 webserv.remove_document(665 remote_doc[Document.DOCUMENT_DOCUMENT_ID]))666 # got the new document back, which is the same plus document_id667 finally:668 webserv.remove_credentials()669 def test_get_documents(self):670 webserv = self._factory.new(self._repository_id)671 self.assertTrue(webserv.service_available(cache = False))672 pk = self._real_package_name673 return self._test_get_documents(pk, webserv.get_documents)674 def test_get_documents_comments(self):675 webserv = self._factory.new(self._repository_id)676 self.assertTrue(webserv.service_available(cache = False))677 pk = self._real_package_name678 return self._test_get_documents(pk, webserv.get_comments)679 def test_get_documents_icons(self):680 webserv = self._factory.new(self._repository_id)681 self.assertTrue(webserv.service_available(cache = False))682 pk = self._real_package_name...
_credentials_preferences.py
Source:_credentials_preferences.py
...37 try:38 dict = read_credentials_from_qiskitrc()39 if dict is not None:40 for credentials in dict.values():41 remove_credentials(credentials)42 except:43 self._credentials = OrderedDict()44 for credentials in self._credentials.values():45 store_credentials(credentials, overwrite=True)46 self._credentials_changed = False47 @property48 def credentials_changed(self):49 return self._credentials_changed50 @property51 def selected_credentials(self):52 return self._selected_credentials53 def get_all_credentials(self):54 return list(self._credentials.values())55 def get_credentials_with_same_key(self, url):56 if url is not None:57 credentials = Credentials('', url)58 return self._credentials.get(credentials.unique_id())59 return False60 def get_credentials(self, url):61 for credentials in self.get_all_credentials():62 if credentials.url == url:63 return credentials64 return None65 def set_credentials(self, token, url, proxy_urls=None):66 if url is not None and token is not None:67 proxies = {} if proxy_urls is None else {'urls': proxy_urls}68 credentials = Credentials(token, url, proxies=proxies)69 self._credentials[credentials.unique_id()] = credentials70 self._credentials_changed = True71 return credentials72 return None73 def select_credentials(self, url):74 if url is not None:75 credentials = Credentials('', url)76 if credentials.unique_id() in self._credentials:77 self._selected_credentials = self._credentials[credentials.unique_id()]78 return self._selected_credentials79 def remove_credentials(self, url):80 if url is not None:81 credentials = Credentials('', url)82 if credentials.unique_id() in self._credentials:83 del self._credentials[credentials.unique_id()]84 self._credentials_changed = True85 if self._selected_credentials is not None and self._selected_credentials.unique_id() == credentials.unique_id():86 self._selected_credentials = None87 credentials = list(self._credentials.values())88 if len(credentials) > 0:89 self._selected_credentials = credentials[0]90 def get_token(self, default_value=None):91 if self._selected_credentials is not None:92 return self._selected_credentials.token93 return default_value...
config_setup.py
Source:config_setup.py
...13 """14 configuration = Configuration(args, method)15 config = configuration.get_config()16 # Ensure we do not use Exchange credentials17 remove_credentials(config)18 validate_config_consistency(config)...
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!!