How to use decorator_test method in locust

Best Python code snippet using locust

caching.py

Source:caching.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from dp_tornado.engine.controller import Controller3class CachingController(Controller):4 def get(self):5 foo = 'foo'6 bar = 'bar'7 baz = 'baz'8 # cache9 a1 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)10 b1 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)11 c1 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)12 d1 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)13 assert a1 == b114 assert a1 != c115 assert a1 != d116 assert c1 != d117 self.model.tests.model_test.decorator_test.clear_cached_method_multiple_drivers()18 # after clear cached19 a2 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)20 b2 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)21 c2 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)22 d2 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)23 assert a1 != a224 assert b1 != b225 assert c1 != c226 assert d1 != d227 assert a2 == b228 assert a2 != c229 assert a2 != d230 assert c2 != d231 ar = self.model.tests.model_test.decorator_test.renew_cached_method_multiple_drivers(foo, bar)32 a3 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)33 b3 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)34 c3 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)35 d3 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)36 assert ar == a337 assert ar == b338 assert a3 == b339 assert a3 != c340 assert a3 != d341 assert c3 != d342 assert a2 != a343 assert b2 != b344 assert c2 == c345 assert d2 == d346 # cache (flush each redis db)47 a4 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)48 b4 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)49 c4 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)50 d4 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)51 self.model.tests.model_test.decorator_test.flush_db_1()52 a5 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)53 b5 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)54 c5 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)55 d5 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)56 assert a4 == a557 assert b4 == b558 assert c4 == c559 assert d4 == d560 a6 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)61 b6 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)62 c6 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)63 d6 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)64 self.model.tests.model_test.decorator_test.flush_db_2()65 a7 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)66 b7 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)67 c7 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)68 d7 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)69 assert a6 == a770 assert b6 == b771 assert c6 == c772 assert d6 == d773 a8 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)74 b8 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)75 c8 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)76 d8 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)77 self.model.tests.model_test.decorator_test.flush_db_1()78 self.model.tests.model_test.decorator_test.flush_db_2()79 a9 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)80 b9 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, bar)81 c9 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(foo, baz)82 d9 = self.model.tests.model_test.decorator_test.cached_method_multiple_drivers(bar, baz)83 assert a8 != a984 assert b8 != b985 assert c8 != c986 assert d8 != d987 self.model.tests.model_test.decorator_test.clear_cached_method_multiple_drivers()88 o = self.model.tests.model_test.decorator_test.cache_method_ignore_param(foo, bar)89 p = self.model.tests.model_test.decorator_test.cache_method_ignore_param(foo, bar)90 r = self.model.tests.model_test.decorator_test.cache_method_ignore_param(foo, param2=bar)91 s = self.model.tests.model_test.decorator_test.cache_method_ignore_param(foo, param2=baz)92 t = self.model.tests.model_test.decorator_test.cache_method_ignore_param(bar, param2=foo)93 u = self.model.tests.model_test.decorator_test.cache_method_ignore_param(bar, param2=baz)94 assert o == p95 assert o != r96 assert r == s97 assert s != u98 assert t == u...

Full Screen

Full Screen

test_auth.py

Source:test_auth.py Github

copy

Full Screen

...10invalid_base64_token = 'Basic Token'11valid_base64_not_basic = 'Basic dG9rZW4=' # token12valid_token = 'Basic dXNlcm5hbWU6cGFzcw==' # username:pass13@requires_authorization_header14def decorator_test():15 """ Dummy function for authorization header"""16 return True17@mock.patch("app.auth.request")18@mock.patch("app.models.User.query")19def test_auth_header_invalid_base64(mock_user, mock_request, test_app):20 """21 Testing authorization function22 """23 mock_request.headers.get.return_value = invalid_base64_token24 first = mock.Mock()25 first.first.return_value = None26 mock_user.filter_by.return_value = first27 with pytest.raises(Unauthorized, match="401 Unauthorized: Incorrect token value"):28 decorator_test()29@mock.patch("app.auth.request")30@mock.patch("app.models.User.query")31def test_auth_header_valid_base64_not_basic(mock_user, mock_request, test_app):32 """33 Testing authorization function34 """35 mock_request.headers.get.return_value = valid_base64_not_basic36 first = mock.Mock()37 first.first.return_value = None38 mock_user.filter_by.return_value = first39 with pytest.raises(Unauthorized, match="401 Unauthorized: Incorrect token value"):40 decorator_test()41@mock.patch("app.auth.request")42@mock.patch("app.models.User.query")43def test_auth_header_valid_token_user_not_exist(mock_user, mock_request, test_app):44 """45 Testing authorization function46 """47 mock_request.headers.get.return_value = valid_token48 first = mock.Mock()49 first.first.return_value = None50 mock_user.filter_by.return_value = first51 with pytest.raises(Unauthorized, match="401 Unauthorized: Invalid username or password"):52 decorator_test()53@mock.patch("app.auth.request")54@mock.patch("app.models.User.query")55def test_auth_header_valid_token_user_exists(mock_user, mock_request, test_app):56 """57 Testing authorization function58 """59 usr = User(username='username')60 usr.password = 'pass'61 mock_request.headers.get.return_value = valid_token62 first = mock.Mock()63 first.first.return_value = usr64 mock_user.filter_by.return_value = first...

Full Screen

Full Screen

decorator.py

Source:decorator.py Github

copy

Full Screen

1def decorator_test(func):2 def wraper(name):3 return "<p>{name}</p>".format(name=func(name))4 return wraper5@decorator_test6def get_text(name):7 return name...

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