How to use log_request method in locust

Best Python code snippet using locust

test_examples_app.py

Source:test_examples_app.py Github

copy

Full Screen

1#!/usr/bin/env python2import unittest3import remi.gui as gui4import sys5import os.path6import time7try:8 from mock_server_and_request import MockServer, MockRequest9 from html_validator import assertValidHTML10except ValueError:11 from .mock_server_and_request import MockServer, MockRequest12 from .html_validator import assertValidHTML13examples_dir = os.path.realpath(os.path.join(os.path.abspath(\14 os.path.dirname(__file__)), '../examples'))15sys.path.append(examples_dir)16class TestHelloWorldApp(unittest.TestCase):17 @classmethod18 def setUpClass(cls):19 import helloworld_app20 cls.AppClass = helloworld_app.MyApp21 def setUp(self):22 # silence request logging for testing23 self.AppClass.log_request = (lambda x,y:None)24 def tearDown(self):25 del self.AppClass.log_request26 self.app.on_close()27 def test_main(self):28 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())29 root_widget = self.app.main()30 html = root_widget.repr()31 assertValidHTML(html)32class TestTemplateApp(unittest.TestCase):33 @classmethod34 def setUpClass(cls):35 import template_app36 cls.AppClass = template_app.MyApp37 def setUp(self):38 self.AppClass.log_request = (lambda x,y:None)39 def tearDown(self):40 del self.AppClass.log_request41 self.app.on_close()42 def test_main(self):43 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())44 root_widget = self.app.main()45 html = root_widget.repr()46 assertValidHTML(html)47class TestAppendAndRemoveWidgetsApp(unittest.TestCase):48 @classmethod49 def setUpClass(cls):50 import append_and_remove_widgets_app51 cls.AppClass = append_and_remove_widgets_app.MyApp52 def setUp(self):53 self.AppClass.log_request = (lambda x,y:None)54 def tearDown(self):55 del self.AppClass.log_request56 self.app.on_close()57 def test_main(self):58 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())59 root_widget = self.app.main()60 html = root_widget.repr()61 assertValidHTML(html)62class TestCloseableApp(unittest.TestCase):63 @classmethod64 def setUpClass(cls):65 import closeable_app66 cls.AppClass = closeable_app.MyApp67 def setUp(self):68 self.AppClass.log_request = (lambda x,y:None)69 def tearDown(self):70 del self.AppClass.log_request71 self.app.on_close()72 def test_main(self):73 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())74 root_widget = self.app.main()75 html = root_widget.repr()76 assertValidHTML(html)77class TestGaugeApp(unittest.TestCase):78 @classmethod79 def setUpClass(cls):80 import gauge_app81 cls.AppClass = gauge_app.MyApp82 def setUp(self):83 self.AppClass.log_request = (lambda x,y:None)84 def tearDown(self):85 del self.AppClass.log_request86 self.app.on_close()87 def test_main(self):88 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())89 root_widget = self.app.main()90 html = root_widget.repr()91 assertValidHTML(html)92class TestGridLayoutApp(unittest.TestCase):93 @classmethod94 def setUpClass(cls):95 import grid_layout_app96 cls.AppClass = grid_layout_app.MyApp97 def setUp(self):98 self.AppClass.log_request = (lambda x,y:None)99 def tearDown(self):100 del self.AppClass.log_request101 self.app.on_close()102 def test_main(self):103 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())104 root_widget = self.app.main()105 html = root_widget.repr()106 assertValidHTML(html)107class TestLayoutApp(unittest.TestCase):108 @classmethod109 def setUpClass(cls):110 import layout_app111 cls.AppClass = layout_app.untitled112 def setUp(self):113 self.AppClass.log_request = (lambda x,y:None)114 def tearDown(self):115 del self.AppClass.log_request116 self.app.on_close()117 def test_main(self):118 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())119 root_widget = self.app.main()120 html = root_widget.repr()121 assertValidHTML(html)122class TestMatplotlibApp(unittest.TestCase):123 @classmethod124 def setUpClass(cls):125 import matplotlib_app126 cls.AppClass = matplotlib_app.MyApp127 def setUp(self):128 self.AppClass.log_request = (lambda x,y:None)129 def tearDown(self):130 del self.AppClass.log_request131 self.app.on_close()132 def test_main(self):133 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())134 root_widget = self.app.main()135 html = root_widget.repr()136 assertValidHTML(html)137class TestMinefieldApp(unittest.TestCase):138 @classmethod139 def setUpClass(cls):140 import minefield_app141 cls.AppClass = minefield_app.MyApp142 def setUp(self):143 self.AppClass.log_request = (lambda x,y:None)144 def tearDown(self):145 del self.AppClass.log_request146 self.app.on_close()147 def test_main(self):148 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())149 root_widget = self.app.main()150 html = root_widget.repr()151 assertValidHTML(html)152class TestNotificationApp(unittest.TestCase):153 @classmethod154 def setUpClass(cls):155 import notification_app156 cls.AppClass = notification_app.MyApp157 def setUp(self):158 self.AppClass.log_request = (lambda x,y:None)159 def tearDown(self):160 del self.AppClass.log_request161 self.app.on_close()162 def test_main(self):163 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())164 root_widget = self.app.main()165 html = root_widget.repr()166 assertValidHTML(html)167class TestOncloseWindowApp(unittest.TestCase):168 @classmethod169 def setUpClass(cls):170 import onclose_window_app171 cls.AppClass = onclose_window_app.MyApp172 def setUp(self):173 self.AppClass.log_request = (lambda x,y:None)174 def tearDown(self):175 del self.AppClass.log_request176 self.app.on_close()177 def test_main(self):178 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())179 root_widget = self.app.main()180 html = root_widget.repr()181 assertValidHTML(html)182class TestPageInternalsApp(unittest.TestCase):183 @classmethod184 def setUpClass(cls):185 import template_advanced_app186 cls.AppClass = template_advanced_app.MyApp187 def setUp(self):188 self.AppClass.log_request = (lambda x,y:None)189 def tearDown(self):190 del self.AppClass.log_request191 self.app.on_close()192 def test_main(self):193 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())194 root_widget = self.app.main()195 html = root_widget.repr()196 assertValidHTML(html)197class TestPilApp(unittest.TestCase):198 @classmethod199 def setUpClass(cls):200 import pil_app201 cls.AppClass = pil_app.MyApp202 def setUp(self):203 self.AppClass.log_request = (lambda x,y:None)204 def tearDown(self):205 del self.AppClass.log_request206 self.app.on_close()207 def test_main(self):208 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())209 root_widget = self.app.main()210 html = root_widget.repr()211 assertValidHTML(html)212class TestResizablePanes(unittest.TestCase):213 @classmethod214 def setUpClass(cls):215 import resizable_panes216 cls.AppClass = resizable_panes.MyApp217 def setUp(self):218 self.AppClass.log_request = (lambda x,y:None)219 def tearDown(self):220 del self.AppClass.log_request221 self.app.on_close()222 def test_main(self):223 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())224 root_widget = self.app.main()225 html = root_widget.repr()226 assertValidHTML(html)227class TestResourcesApp(unittest.TestCase):228 @classmethod229 def setUpClass(cls):230 import resources_app231 cls.AppClass = resources_app.MyApp232 def setUp(self):233 self.AppClass.log_request = (lambda x,y:None)234 self.previouse_dir = os.getcwd()235 os.chdir(examples_dir)236 def tearDown(self):237 del self.AppClass.log_request238 self.app.on_close()239 os.chdir(self.previouse_dir)240 def test_main(self):241 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())242 root_widget = self.app.main()243 html = root_widget.repr()244 assertValidHTML(html)245class TestRootWidgetChangeApp(unittest.TestCase):246 @classmethod247 def setUpClass(cls):248 import root_widget_change_app249 cls.AppClass = root_widget_change_app.MyApp250 def setUp(self):251 self.AppClass.log_request = (lambda x,y:None)252 def tearDown(self):253 del self.AppClass.log_request254 self.app.on_close()255 def test_main(self):256 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())257 root_widget = self.app.main()258 html = root_widget.repr()259 assertValidHTML(html)260class TestSessionApp(unittest.TestCase):261 @classmethod262 def setUpClass(cls):263 import session_app264 cls.AppClass = session_app.MyApp265 def setUp(self):266 self.AppClass.log_request = (lambda x,y:None)267 def tearDown(self):268 del self.AppClass.log_request269 self.app.on_close()270 def test_main(self):271 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())272 root_widget = self.app.main()273 html = root_widget.repr()274 assertValidHTML(html)275class TestStandaloneApp(unittest.TestCase):276 @classmethod277 def setUpClass(cls):278 import standalone_app279 cls.AppClass = standalone_app.MyApp280 def setUp(self):281 self.AppClass.log_request = (lambda x,y:None)282 def tearDown(self):283 del self.AppClass.log_request284 self.app.on_close()285 def test_main(self):286 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())287 root_widget = self.app.main()288 html = root_widget.repr()289 assertValidHTML(html)290class TestSvgplotApp(unittest.TestCase):291 @classmethod292 def setUpClass(cls):293 import svgplot_app294 cls.AppClass = svgplot_app.MyApp295 def setUp(self):296 self.AppClass.log_request = (lambda x,y:None)297 def tearDown(self):298 del self.AppClass.log_request299 self.app.on_close()300 def test_main(self):301 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())302 root_widget = self.app.main()303 html = root_widget.repr()304 assertValidHTML(html)305 time.sleep(1.0) # wait for some data to be generated306 html = root_widget.repr()307 assertValidHTML(html)308class TestTabboxApp(unittest.TestCase):309 @classmethod310 def setUpClass(cls):311 import tabbox312 cls.AppClass = tabbox.MyApp313 def setUp(self):314 self.AppClass.log_request = (lambda x,y:None)315 def tearDown(self):316 del self.AppClass.log_request317 self.app.on_close()318 def test_main(self):319 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())320 root_widget = self.app.main()321 html = root_widget.repr()322 assertValidHTML(html)323class TestTableWidgetApp(unittest.TestCase):324 @classmethod325 def setUpClass(cls):326 import table_widget_app327 cls.AppClass = table_widget_app.MyApp328 def setUp(self):329 self.AppClass.log_request = (lambda x,y:None)330 def tearDown(self):331 del self.AppClass.log_request332 self.app.on_close()333 def test_main(self):334 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())335 root_widget = self.app.main()336 html = root_widget.repr()337 assertValidHTML(html)338class TestTemplateAdvancedApp(unittest.TestCase):339 @classmethod340 def setUpClass(cls):341 import template_advanced_app342 cls.AppClass = template_advanced_app.MyApp343 def setUp(self):344 self.AppClass.log_request = (lambda x,y:None)345 def tearDown(self):346 del self.AppClass.log_request347 self.app.on_close()348 def test_main(self):349 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())350 root_widget = self.app.main()351 html = root_widget.repr()352 assertValidHTML(html)353class TestThreadedApp(unittest.TestCase):354 @classmethod355 def setUpClass(cls):356 import threaded_app357 cls.AppClass = threaded_app.MyApp358 def setUp(self):359 self.AppClass.log_request = (lambda x,y:None)360 def tearDown(self):361 del self.AppClass.log_request362 self.app.on_close()363 def test_main(self):364 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())365 root_widget = self.app.main()366 html = root_widget.repr()367 assertValidHTML(html)368 time.sleep(1)369 # click the button, which will stop the background thread so this can finish370 self.app.on_button_pressed(None)371class TestWebAPIApp(unittest.TestCase):372 @classmethod373 def setUpClass(cls):374 import webAPI_app375 cls.AppClass = webAPI_app.MyApp376 def setUp(self):377 self.AppClass.log_request = (lambda x,y:None)378 def tearDown(self):379 del self.AppClass.log_request380 self.app.on_close()381 def test_main(self):382 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())383 root_widget = self.app.main()384 html = root_widget.repr()385 assertValidHTML(html)386class TestWidgetOverviewApp(unittest.TestCase):387 @classmethod388 def setUpClass(cls):389 import widgets_overview_app390 cls.AppClass = widgets_overview_app.MyApp391 def setUp(self):392 self.AppClass.log_request = (lambda x,y:None)393 def tearDown(self):394 del self.AppClass.log_request395 self.app.on_close()396 def test_main(self):397 self.app = self.AppClass(MockRequest(), ('0.0.0.0', 8888), MockServer())398 root_widget = self.app.main()399 html = root_widget.repr()400 assertValidHTML(html)401if __name__ == '__main__':...

Full Screen

Full Screen

test_nutrition.py

Source:test_nutrition.py Github

copy

Full Screen

1import pytest2import datetime3from actualizer.log.nutrition import NutritionLog4from actualizer.log.serializers import *5NOW_DT = datetime.datetime.now()6def test_nutrition_parsing():7 log_request = {8 'username': 'jordan',9 'message': 'ate a 100 cal apple 20 min ago',10 'request_time': NOW_DT11 }12 log = NutritionLog(log_request)13 assert log.datetime == NOW_DT - datetime.timedelta(minutes = 20)14 assert log.username == 'jordan'15 assert log.calories == 10016 assert log.nutrition_substr == 'ate a 100 cal apple'17 assert log.food == 'apple'18def test_nutrition_serialization():19 log_request = {20 'username': 'jordan',21 'message': 'ate a 100 cal apple 20 min ago',22 'request_time': NOW_DT23 }24 log = NutritionLog(log_request)25 serialized_dict = log.to_serialized_dict()26 assert serialized_dict['datetime'] == serialize_datetime(NOW_DT - datetime.timedelta(minutes = 20))27 assert serialized_dict['message'] == serialize_message(log_request['message'])28 assert serialized_dict['request_time'] == serialize_request_time(log_request['request_time'])29 assert serialized_dict['food'] == serialize_food('apple')30 assert serialized_dict['calories'] == serialize_calories('100')31 assert serialized_dict['username'] == serialize_username(log_request['username'])32 assert serialized_dict['logtype'] == serialize_logtype('NutritionLog')33def test_nutrition_serialization_with_of_clause():34 log_request = {35 'username': 'jordan',36 'message': 'ate 900 cals of pad kee mao 2 hours ago',37 'request_time': NOW_DT38 }39 log = NutritionLog(log_request)40 serialized_dict = log.to_serialized_dict()41 assert serialized_dict['datetime'] == serialize_datetime(NOW_DT - datetime.timedelta(hours = 2))42 assert serialized_dict['message'] == 'ate 900 cals of pad kee mao 2 hours ago'43 assert serialized_dict['request_time'] == serialize_request_time(log_request['request_time'])44 assert serialized_dict['food'] == 'pad kee mao'45 assert serialized_dict['calories'] == '900'46 assert serialized_dict['username'] == 'jordan'47 assert serialized_dict['logtype'] == 'NutritionLog'48def test_nutrition_serialization_with_today_approx_time():49 log_request = {50 'username': 'special@username',51 'message': 'ate 400 cals of korean appetizers today at noon',52 'request_time': NOW_DT53 }54 log = NutritionLog(log_request)55 serialized_dict = log.to_serialized_dict()56 assert serialized_dict['datetime'] == serialize_datetime(NOW_DT.replace(hour = 12, minute = 0, second = 0, microsecond = 0))57 assert serialized_dict['message'] == 'ate 400 cals of korean appetizers today at noon'58 assert serialized_dict['request_time'] == serialize_request_time(log_request['request_time'])59 assert serialized_dict['food'] == 'korean appetizers'60 assert serialized_dict['calories'] == '400'61 assert serialized_dict['username'] == 'special@username'62def test_nutrition_serialization_with_today_datetime():63 log_request = {64 'username': 'special@username',65 'message': 'ate 600 cals of Korean Beef Tofu Soup today at 12:15',66 'request_time': NOW_DT67 }68 log = NutritionLog(log_request)69 serialized_dict = log.to_serialized_dict()70 assert serialized_dict['datetime'] == serialize_datetime(NOW_DT.replace(hour = 12, minute = 15, second = 0, microsecond = 0))71 assert serialized_dict['message'] == 'ate 600 cals of Korean Beef Tofu Soup today at 12:15'72 assert serialized_dict['request_time'] == serialize_request_time(log_request['request_time'])73 assert serialized_dict['food'] == 'Korean Beef Tofu Soup'74 assert serialized_dict['calories'] == '600'75 assert serialized_dict['username'] == 'special@username'76def test_nutrition_serialization_with_yesterday_datetime():77 log_request = {78 'username': 'jordan',79 'message': 'ate 900 cals of thai food yesterday at 7:00PM',80 'request_time': NOW_DT81 }82 log = NutritionLog(log_request)83 serialized_dict = log.to_serialized_dict()84 assert serialized_dict['datetime'] == serialize_datetime(NOW_DT.replace(minute = 0, second = 0, microsecond = 0, hour = 19) - datetime.timedelta(days = 1))85 assert serialized_dict['message'] == 'ate 900 cals of thai food yesterday at 7:00PM'86 assert serialized_dict['request_time'] == serialize_request_time(log_request['request_time'])87 assert serialized_dict['food'] == 'thai food'88 assert serialized_dict['calories'] == '900'89 assert serialized_dict['username'] == 'jordan'90 assert serialized_dict['logtype'] == 'NutritionLog'91def test_nutrition_serialization_with_yesterday_approxtime():92 log_request = {93 'username': 'jordan',94 'message': 'ate 900 cals of thai food yesterday evening',95 'request_time': NOW_DT,96 }97 log = NutritionLog(log_request)98 serialized_dict = log.to_serialized_dict()99 assert serialized_dict['datetime'] == serialize_datetime(NOW_DT.replace(hour = 18, minute = 0, second = 0, microsecond = 0) - datetime.timedelta(days = 1))100 assert serialized_dict['message'] == 'ate 900 cals of thai food yesterday evening'101 assert serialized_dict['request_time'] == serialize_request_time(log_request['request_time'])102 assert serialized_dict['food'] == 'thai food'103 assert serialized_dict['calories'] == '900'104 assert serialized_dict['username'] == 'jordan'105 assert serialized_dict['logtype'] == 'NutritionLog'106def test_food_regex():107 assert NutritionLog.PARSING_PATTERN108 matches = NutritionLog.PARSING_PATTERN.search('ate 100 cal apple').groupdict()109 assert matches['food'] == 'apple'110 assert matches['calories'] == '100'111 matches = NutritionLog.PARSING_PATTERN.search('ate 10 cal candy bar').groupdict()112 assert matches['food'] == 'candy bar'113 assert matches['calories'] == '10'114 matches = NutritionLog.PARSING_PATTERN.search('ate 0 cal orange').groupdict()115 assert matches['food'] == 'orange'116 assert matches['calories'] == '0'117 matches = NutritionLog.PARSING_PATTERN.search('ate 560 cals of chips').groupdict()118 assert matches['food'] == 'chips'119 assert matches['calories'] == '560'120 matches = NutritionLog.PARSING_PATTERN.search('ate 900 cals of pad kee mao').groupdict()121 assert matches['food'] == 'pad kee mao'122 assert matches['calories'] == '900'123 matches = NutritionLog.PARSING_PATTERN.search('drank 300 calorie latte').groupdict()124 assert matches['food'] == 'latte'125 assert matches['calories'] == '300'126 matches = NutritionLog.PARSING_PATTERN.search('ate 400 cals of korean appetizers').groupdict()127 assert matches['food'] == 'korean appetizers'...

Full Screen

Full Screen

test_base.py

Source:test_base.py Github

copy

Full Screen

1import datetime2from actualizer.log import base3def test_relative_datetime_regex():4 matches = base.DATETIME_PATTERN.search('ate a 500 cal sandwich 20 min ago').groupdict()5 assert matches['RELATIVE_DELTA'] == '20 min ago'6 assert matches['TIMEUNIT'] == 'min'7 assert matches['QUANTITY'] == '20'8 matches = base.DATETIME_PATTERN.search('ate 20 samosas 3 hours ago').groupdict()9 assert matches['RELATIVE_DELTA'] == '3 hours ago'10 assert matches['TIMEUNIT'] == 'hours'11 assert matches['QUANTITY'] == '3'12 matches = base.DATETIME_PATTERN.search('ate 20 samosas 3 hrs ago').groupdict()13 assert matches['RELATIVE_DELTA'] == '3 hrs ago'14 assert matches['TIMEUNIT'] == 'hrs'15 assert matches['QUANTITY'] == '3'16 matches = base.DATETIME_PATTERN.search('ate 20 samosas an hour ago').groupdict()17 assert matches['RELATIVE_DELTA'] == 'an hour ago'18 assert matches['TIMEUNIT'] == 'hour'19 assert matches['QUANTITY'] == 'an'20def test_absolute_datetime_regex_with_PM_AM():21 matches = base.DATETIME_PATTERN.search('ate a 100 cal candy bar at 5:00 PM').groupdict()22 assert matches['EXACT_TIME'] == '5:00 PM'23 matches = base.DATETIME_PATTERN.search('ate a 500 cal candy bar at 12:00 PM').groupdict()24 assert matches['EXACT_TIME'] == '12:00 PM'25 matches = base.DATETIME_PATTERN.search('ate a 100 cal candy bar this morning').groupdict()26 print(matches)27 assert matches['APPROX_TIME'] == 'morning'28 matches = base.DATETIME_PATTERN.search('ate a 100 cal candy bar at 11').groupdict()29 assert matches['EXACT_TIME'] == '11'30 matches = base.DATETIME_PATTERN.search('ate a 12300 cal candy bar at 5P').groupdict()31 assert matches['EXACT_TIME'] == '5P'32 matches = base.DATETIME_PATTERN.search('ate a 12300 cal candy bar at 1A').groupdict()33 assert matches['EXACT_TIME'] == '1A'34 matches = base.DATETIME_PATTERN.search('ate a 12300 cal candy bar at 1:00AM').groupdict()35 assert matches['EXACT_TIME'] == '1:00AM'36 matches = base.DATETIME_PATTERN.search('ate a 12300 cal candy bar at 3:00P').groupdict()37 assert matches['EXACT_TIME'] == '3:00P'38def test_exact_datetime_regex_with_modifier():39 matches = base.DATETIME_PATTERN.search('ate a 300 cal donut yesterday at 2:00PM').groupdict()40 assert matches['EXACT_TIME'] == '2:00PM'41 assert matches['MODIFIER'] == 'yesterday'42 matches = base.DATETIME_PATTERN.search('ate a 300 cal donut today at 2:00PM').groupdict()43 assert matches['EXACT_TIME'] == '2:00PM'44 matches = base.DATETIME_PATTERN.search('ate a 300 cal donut today at 2').groupdict()45 assert matches['EXACT_TIME'] == '2'46 matches = base.DATETIME_PATTERN.search('ate a 500 cal donut yesterday at 5:30PM').groupdict()47 assert matches['EXACT_TIME'] == '5:30PM'48 assert matches['MODIFIER'] == 'yesterday'49def test_approx_datetime_regex_with_yesterday():50 matches = base.DATETIME_PATTERN.search('ate a 300 cal donut yesterday morning').groupdict()51 assert matches['APPROX_TIME'] == 'morning'52 assert matches['APPROX_MODIFIER'] == 'yesterday'53 matches = base.DATETIME_PATTERN.search('ate a 300 cal donut this morning').groupdict()54 assert matches['APPROX_TIME'] == 'morning'55 assert matches['APPROX_MODIFIER'] == 'this'56 matches = base.DATETIME_PATTERN.search('ate a 300 cal donut yesterday evening').groupdict()57 assert matches['APPROX_TIME'] == 'evening'58 assert matches['APPROX_MODIFIER'] == 'yesterday'59def test_infer_datetime_relative():60 log_request = {61 'request_time': base.NOW_DT,62 'username': 'jordan',63 'message': 'ate 300 cal latte 20 min ago'64 }65 log = base.Log(log_request)66 assert log.datetime == base.NOW_DT - datetime.timedelta(minutes = 20)67 dt = datetime.datetime(2016, 11, 30, 10, 22, 21)68 log_request = {69 'request_time': dt,70 'username': 'jordan',71 'message': 'ate 300 cal latte 4 hours ago'72 }73 log = base.Log(log_request)74 assert log.datetime == dt - datetime.timedelta(hours = 4)75def test_infer_datetime_approx_with_modifier():76 dt = datetime.datetime.now()77 log_request = {78 'request_time': dt,79 'username': 'jordan',80 'message': 'drank 300 cal latte yesterday morning'81 }82 log = base.Log(log_request)83 assert log.datetime == (dt - datetime.timedelta(days = 1)).replace(hour = 9, minute = 0, second = 0, microsecond = 0)84 log_request = {85 'request_time': dt,86 'username': 'jordan',87 'message': 'ate 600 cal pizza yesterday evening'88 }89 log = base.Log(log_request)90 assert log.datetime == (dt - datetime.timedelta(days = 1)).replace(hour = 18, minute = 0, second = 0, microsecond = 0)91 log_request = {92 'request_time': dt,93 'username': 'jordan',94 'message': 'ate 600 cal pizza this morning'95 }96 log = base.Log(log_request)97 assert log.datetime == dt.replace(hour = 9, minute = 0, second = 0, microsecond = 0)98def test_infer_datetime_exact_time_with_modifier():99 dt = datetime.datetime.now()100 log_request = {101 'request_time': dt,102 'username': 'jordan',103 'message': 'drank 300 cal latte yesterday at 10:00AM'104 }105 log = base.Log(log_request)106 assert log.datetime == (dt - datetime.timedelta(days = 1)).replace(hour = 10, minute = 0, second = 0, microsecond = 0)107 log_request = {108 'request_time': dt,109 'username': 'jordan',110 'message': 'drank 300 cal latte yesterday at 5:30PM'111 }112 log = base.Log(log_request)113 assert log.datetime == (dt - datetime.timedelta(days = 1)).replace(hour = 17, minute = 30, second = 0, microsecond = 0)114 log_request = {115 'request_time': dt,116 'username': 'jordan',117 'message': 'drank 300 cal latte yesterday at 10'118 }119 log = base.Log(log_request)120 assert log.datetime == (dt - datetime.timedelta(days = 1)).replace(hour = 10, minute = 0, second = 0, microsecond = 0)121 log_request = {122 'request_time': dt,123 'username': 'jordan',124 'message': 'drank 300 cal latte today at 10:00AM'125 }126 log = base.Log(log_request)...

Full Screen

Full Screen

controllers.py

Source:controllers.py Github

copy

Full Screen

...5from flask import request6from redis_store import *7from .responders import *8from dataframes.filters import apply_params_filter9def log_request(path, params):10 app.logger.debug('Received request {} with params {}'.format(path, params))11@app.route('/pods', methods=['GET'])12def get_pods():13 log_request('/pods', request.args)14 pod_key = get_key('pod')15 pods_dataframe = retrieve_dataframe(pod_key)16 result = apply_params_filter(pods_dataframe, params=request.args)17 return api_respond(list(result['object']))18@app.route('/nodes', methods=['GET'])19def get_nodes():20 log_request('/nodes', request.args)21 pod_key = get_key('node')22 pods_dataframe = retrieve_dataframe(pod_key)23 result = apply_params_filter(pods_dataframe, params=request.args)24 return api_respond(list(result['object']))25@app.route('/services', methods=['GET'])26def get_services():27 log_request('/services', request.args)28 pod_key = get_key('service')29 pods_dataframe = retrieve_dataframe(pod_key)30 result = apply_params_filter(pods_dataframe, params=request.args)31 return api_respond(list(result['object']))32@app.route('/ingress', methods=['GET'])33def get_ingress():34 log_request('/ingress', request.args)35 pod_key = get_key('ingress')36 pods_dataframe = retrieve_dataframe(pod_key)37 result = apply_params_filter(pods_dataframe, params=request.args)38 return api_respond(list(result['object']))39@app.route('/pvcs', methods=['GET'])40def get_pvcs():41 log_request('/pvcs', request.args)42 pod_key = get_key('pvc')43 pods_dataframe = retrieve_dataframe(pod_key)44 result = apply_params_filter(pods_dataframe, params=request.args)45 return api_respond(list(result['object']))46@app.route('/deployments', methods=['GET'])47def get_deployments():48 log_request('/deployments', request.args)49 pod_key = get_key('deployment')50 pods_dataframe = retrieve_dataframe(pod_key)51 result = apply_params_filter(pods_dataframe, params=request.args)...

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