Best Python code snippet using tempest_python
test_openpost.py
Source:test_openpost.py
...110 poster._validate_data(1)111 with self.assertRaises(ValueError):112 with suppress_allout():113 poster._validate_data(1.5)114 def test_validate_url(self):115 poster = test_module.OpenPost()116 self.assertEqual(poster._validate_url('localhost'), 'localhost')117 self.assertEqual(poster._validate_url('https://some.test.url'), 'https://some.test.url')118 with self.assertRaises(ValueError):119 with suppress_allout():120 poster._validate_url(None)121 with self.assertRaises(ValueError):122 with suppress_allout():123 poster._validate_url('')124 with self.assertRaises(ValueError):125 with suppress_allout():126 poster._validate_url(' ')127 with self.assertRaises(ValueError):128 with suppress_allout():129 poster._validate_url('contains space')130 with self.assertRaises(ValueError):131 with suppress_allout():132 poster._validate_url({'one': 1})133 with self.assertRaises(ValueError):134 with suppress_allout():135 poster._validate_url(['one'])136 with self.assertRaises(ValueError):137 with suppress_allout():138 poster._validate_url(1)139 with self.assertRaises(ValueError):140 with suppress_allout():141 poster._validate_url(1.5)142 def test_make_filename(self):143 poster = test_module.OpenPost()144 self.assertEqual(poster._make_filename(None), 'OpenPost.html')145 self.assertEqual(poster._make_filename(''), 'OpenPost.html')146 self.assertEqual(poster._make_filename(' '), 'OpenPost.html')147 with self.assertRaises(AttributeError):148 with suppress_allout():149 poster._make_filename(-1)150 with self.assertRaises(AttributeError):151 with suppress_allout():152 poster._make_filename(10.50)153 with self.assertRaises(AttributeError):154 with suppress_allout():155 poster._make_filename({'a': 'b'})...
test_shorten.py
Source:test_shorten.py
...12 json={"error": "No data exists for US zip code 90210"},13 status=40414 )15 sh = Shorten()16 resp = sh._validate_url('http://api.zippopotam.us/us/90210')17 assert resp == False18@responses.activate19def test_validate_url_succes():20 responses.add(21 responses.GET,22 "http://api.zippopotam.us/us/90210",23 json={"success": "zip code 90210"},24 status=20025 )26 sh = Shorten()27 resp = sh._validate_url('http://api.zippopotam.us/us/90210')28 assert resp == True29def test_validate_shortcode_success():30 shortcode = 'test12'31 sh = Shorten()32 response = sh._validate_shortcode(shortcode)33 assert response == True34def test_validate_shortcode_failure():35 shortcode = 'test'36 sh = Shorten()37 response = sh._validate_shortcode(shortcode)38 assert response == False39def test_shorcode_exist_false():40 with mock.patch("app.database.Database.get_shortcode") as complex_function_mock:41 complex_function_mock.return_value = False...
redirects.py
Source:redirects.py
...27logger = logging.getLogger(__name__)28class R(BaseSupersetView): # pylint: disable=invalid-name29 """used for short urls"""30 @staticmethod31 def _validate_url(url: Optional[str] = None) -> bool:32 if url and (33 url.startswith("//superset/dashboard/")34 or url.startswith("//superset/explore/")35 ):36 return True37 return False38 @event_logger.log_this39 @expose("/<int:url_id>")40 def index(self, url_id: int) -> FlaskResponse: # pylint: disable=no-self-use41 url = db.session.query(models.Url).get(url_id)42 if url and url.url:43 explore_url = "//superset/explore/?"44 if url.url.startswith(explore_url):45 explore_url += f"r={url_id}"46 return redirect(explore_url[1:])47 if self._validate_url(url.url):48 return redirect(url.url[1:])49 return redirect("/")50 flash("URL to nowhere...", "danger")51 return redirect("/")52 @event_logger.log_this53 @has_access_api54 @expose("/shortner/", methods=["POST"])55 def shortner(self) -> FlaskResponse: # pylint: disable=no-self-use56 url = request.form.get("data")57 if not self._validate_url(url):58 logger.warning("Invalid URL: %s", url)59 return Response(f"Invalid URL: {url}", 400)60 obj = models.Url(url=url)61 db.session.add(obj)62 db.session.commit()63 return Response(64 "{scheme}://{request.headers[Host]}/r/{obj.id}".format(65 scheme=request.scheme, request=request, obj=obj66 ),67 mimetype="text/plain",...
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!!