How to use assert_starts_with method in Testify

Best Python code snippet using Testify_python

test_wanda.py

Source: test_wanda.py Github

copy

Full Screen

...8class SimpleTest(unittest.TestCase):9 good_search = "nature"10 bad_search = "foobarxyzzy"11 artstation_cdn = "https:/​/​cdn(.).artstation.com/​"12 def assert_starts_with(self, response, url):13 self.assertTrue(response.startswith(url), response)14 def assertNotNone(self, response, url):15 self.assertIsNotNone(re.search(url, response), response)16 def test_conn_test(self):17 self.assertTrue(wanda.is_connected())18 def test_local(self):19 self.assertRaises(SystemExit, wanda.local, None)20 self.assertRaises(SystemExit, wanda.local, "")21 def test_wallhaven(self):22 url = "https:/​/​w.wallhaven.cc/​full/​"23 response = wanda.wallhaven(None)24 self.assert_starts_with(response, url)25 response = wanda.wallhaven("")26 self.assert_starts_with(response, url)27 response = wanda.wallhaven(self.good_search)28 self.assert_starts_with(response, url)29 self.assertRaises(SystemExit, wanda.wallhaven, self.bad_search)30 def test_unsplash(self):31 url = "https:/​/​images.unsplash.com/​photo-"32 response = wanda.unsplash(None)33 self.assert_starts_with(response, url)34 response = wanda.unsplash("")35 self.assert_starts_with(response, url)36 response = wanda.unsplash(self.good_search)37 self.assert_starts_with(response, url)38 self.assertRaises(SystemExit, wanda.unsplash, self.bad_search)39 def test_reddit(self):40 url = "https:/​/​i.redd.it/​"41 self.assertIn("wallpaper", wanda.suggested_subreddits())42 response = wanda.reddit(search=None)43 self.assert_starts_with(response, url)44 response = wanda.reddit("")45 self.assert_starts_with(response, url)46 response = wanda.reddit(self.good_search)47 self.assertNotNone(response, "^https?:/​/​")48 response = wanda.reddit("wallpaper@halflife")49 self.assertNotNone(response, "^https?:/​/​")50 self.assertRaises(SystemExit, wanda.reddit, search=self.bad_search)51 def test_imgur(self):52 url = "https:/​/​rimgo.pussthecat.org/​"53 response = wanda.imgur(None)54 self.assert_starts_with(response, url)55 response = wanda.imgur("")56 self.assert_starts_with(response, url)57 response = wanda.imgur("jmVC8")58 self.assert_starts_with(response, url)59 self.assertRaises(SystemExit, wanda.imgur, self.bad_search)60 def test_fourchan(self):61 url = "^(https?:/​/​s1.alice.al|https?:/​/​i.4cdn.org)"62 response = wanda.fourchan(None)63 self.assertNotNone(response, url)64 response = wanda.fourchan("")65 self.assertNotNone(response, url)66 response = wanda.fourchan("phone")67 self.assertNotNone(response, url)68 self.assertRaises(SystemExit, wanda.fourchan, self.bad_search)69 def test_fivehundredpx(self):70 url = "https:/​/​drscdn.500px.org/​photo/​"71 response = wanda.fivehundredpx(None)72 self.assertTrue(response.startswith(url))73 response = wanda.fivehundredpx("")74 self.assert_starts_with(response, url)75 response = wanda.fivehundredpx(self.good_search)76 self.assert_starts_with(response, url)77 self.assertRaises(SystemExit, wanda.fivehundredpx, self.bad_search)78 def test_artstation_any(self):79 url = self.artstation_cdn80 response = wanda.artstation_any(None)81 self.assertNotNone(response, url)82 response = wanda.artstation_any("")83 self.assertNotNone(response, url)84 response = wanda.artstation_any(self.good_search)85 self.assertNotNone(response, url)86 self.assertRaises(SystemExit, wanda.artstation_any, self.bad_search)87 def test_artstation_prints(self):88 url = self.artstation_cdn89 response = wanda.artstation_prints(None)90 self.assertNotNone(response, url)91 response = wanda.artstation_prints("")92 self.assertNotNone(response, url)93 response = wanda.artstation_prints(self.good_search)94 self.assertNotNone(response, url)95 self.assertRaises(SystemExit, wanda.artstation_prints, self.bad_search)96 def test_artstation_artist(self):97 url = self.artstation_cdn98 self.assertRaises(SystemExit, wanda.artstation_artist, None)99 self.assertRaises(SystemExit, wanda.artstation_artist, "")100 self.assertRaises(SystemExit, wanda.artstation_artist, self.bad_search)101 response = wanda.artstation_artist("tohad")102 self.assertNotNone(response, url)103 def test_earthview(self):104 url = "https:/​/​www.gstatic.com/​prettyearth/​assets/​full/​"105 response = wanda.earthview(None)106 self.assert_starts_with(response, url)107 def test_waifuim(self):108 url = "https:/​/​cdn.waifu.im/​"109 response = wanda.waifuim(None)110 self.assert_starts_with(response, url)111 response = wanda.waifuim("")112 self.assert_starts_with(response, url)113 response = wanda.waifuim("uniform")114 self.assert_starts_with(response, url)115 self.assertRaises(SystemExit, wanda.waifuim, self.bad_search)116# These tests would need actual device117@pytest.mark.skip118class AdvancedTest(unittest.TestCase):119 good_search = "nature"120 def test_size(self):121 self.assertEqual(type(wanda.size()), tuple)122 def test_set_local(self):123 folder = f"{str(Path.home())}/​wanda"124 path = wanda.get_dl_path()125 path = wanda.download(path, "https:/​/​i.imgur.com/​bBNy18H.jpeg")126 self.assertTrue(os.path.exists(path))127 wanda.set_wp(wanda.local(folder), True, True)128 def test_set_wallhaven(self):...

Full Screen

Full Screen

test_auth.py

Source: test_auth.py Github

copy

Full Screen

...370 0 already tested on other case380 139'''40def auth_basic(r):41 assert_starts_with('NOAUTH', str(retry_read(lambda : r.ping())))42 assert_starts_with('NOAUTH', str(retry_write(lambda : r.set('k', 'v'))))43 assert_starts_with('NOAUTH', str(retry_read(lambda : r.get('k'))))44 # bad passwd45 assert_equal('invalid password', str(retry_write(lambda : r.execute_command('AUTH', 'badpasswd'))))46 # everything is ok after auth47 retry_write(lambda : r.execute_command('AUTH', 'hellopasswd'))48 retry_write(lambda : r.set('k', 'v'))49 assert_equal(True, retry_read(lambda : r.ping()))50 assert_equal('v', retry_read(lambda : r.get('k')))51 # auth fail here, should we return ok or not => we will mark the conn state as not authed52 assert_equal('invalid password', str(retry_write(lambda : r.execute_command('AUTH', 'badpasswd'))))53 assert_starts_with('NOAUTH', str(retry_read(lambda : r.ping())))54 assert_starts_with('NOAUTH', str(retry_read(lambda : r.get('k'))))55def test_auth_basic_redis():56 r = redis.Redis(all_redis[0].host(), all_redis[0].port())57 prime_connection(r, all_redis[0])58 auth_basic(r)59def test_auth_basic_proxy():60 r = redis.Redis(nc.host(), nc.port())61 prime_connection(r, nc)62 auth_basic(r)63def test_nopass_on_proxy():64 r = redis.Redis(nc_nopass.host(), nc_nopass.port())65 prime_connection(r, nc_nopass)66 # if you config pass on redis but not on twemproxy,67 # twemproxy will reply ok for ping, but once you do get/​set, you will get errmsg from redis68 assert_equal(True, retry_read(lambda : r.ping()))69 assert_starts_with('NOAUTH', str(retry_write(lambda : r.set('k', 'v'))))70 assert_starts_with('NOAUTH', str(retry_read(lambda : r.get('k'))))71 # proxy has no pass, when we try to auth72 assert_starts_with('Client sent AUTH, but no password is set', str(retry_write(lambda : r.execute_command('AUTH', 'anypasswd'))))73def test_badpass_on_proxy():74 r = redis.Redis(nc_badpass.host(), nc_badpass.port())75 prime_connection(r, nc_badpass)76 assert_starts_with('NOAUTH', str(retry_read(lambda : r.ping())))77 assert_starts_with('NOAUTH', str(retry_write(lambda : r.set('k', 'v'))))78 assert_starts_with('NOAUTH', str(retry_read(lambda : r.get('k'))))79 # we can auth with bad pass (twemproxy will say ok for this)80 retry_write(lambda : r.execute_command('AUTH', 'badpasswd'))81 # after that, we still got NOAUTH for get/​set (return from redis-server)82 assert_equal(True, retry_read(lambda : r.ping()))83 assert_starts_with('NOAUTH', str(retry_write(lambda : r.set('k', 'v'))))84 assert_starts_with('NOAUTH', str(retry_read(lambda : r.get('k'))))85# NOTE: setup_and_wait was is/​was used in developing the nosetests, see:86# https:/​/​github.com/​idning/​test-twemproxy/​blob/​master/​Makefile#L1787def setup_and_wait():...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Assessing Risks in the Scrum Framework

Software Risk Management (SRM) combines a set of tools, processes, and methods for managing risks in the software development lifecycle. In SRM, we want to make informed decisions about what can go wrong at various levels within a company (e.g., business, project, and software related).

How To Use Playwright For Web Scraping with Python

In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.

Agile in Distributed Development – A Formula for Success

Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.

How To Handle Multiple Windows In Selenium Python

Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

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 Testify 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