How to use check_messages method in localstack

Best Python code snippet using localstack_python

test_logger.py

Source:test_logger.py Github

copy

Full Screen

...57 self.handler.setFormatter(mozlog.JSONFormatter())58 self.logger = mozlog.MozLogger('test.Logger')59 self.logger.addHandler(self.handler)60 self.logger.setLevel(mozlog.DEBUG)61 def check_messages(self, expected, actual):62 """Checks actual for equality with corresponding fields in actual.63 The actual message should contain all fields in expected, and64 should be identical, with the exception of the timestamp field.65 The actual message should contain no fields other than the timestamp66 field and those present in expected."""67 self.assertTrue(isinstance(actual['_time'], six.integer_types))68 for k, v in expected.items():69 self.assertEqual(v, actual[k])70 for k in actual.keys():71 if k != '_time':72 self.assertTrue(expected.get(k) is not None)73 def test_structured_output(self):74 self.logger.log_structured('test_message',75 {'_level': mozlog.INFO,76 '_message': 'message one'})77 self.logger.log_structured('test_message',78 {'_level': mozlog.INFO,79 '_message': 'message two'})80 self.logger.log_structured('error_message',81 {'_level': mozlog.ERROR,82 'diagnostic': 'unexpected error'})83 message_one_expected = {'_namespace': 'test.Logger',84 '_level': 'INFO',85 '_message': 'message one',86 'action': 'test_message'}87 message_two_expected = {'_namespace': 'test.Logger',88 '_level': 'INFO',89 '_message': 'message two',90 'action': 'test_message'}91 message_three_expected = {'_namespace': 'test.Logger',92 '_level': 'ERROR',93 'diagnostic': 'unexpected error',94 'action': 'error_message'}95 message_one_actual = json.loads(self.handler.messages[0])96 message_two_actual = json.loads(self.handler.messages[1])97 message_three_actual = json.loads(self.handler.messages[2])98 self.check_messages(message_one_expected, message_one_actual)99 self.check_messages(message_two_expected, message_two_actual)100 self.check_messages(message_three_expected, message_three_actual)101 def test_unstructured_conversion(self):102 """ Tests that logging to a logger with a structured formatter103 via the traditional logging interface works as expected. """104 self.logger.info('%s %s %d', 'Message', 'number', 1)105 self.logger.error('Message number 2')106 self.logger.debug('Message with %s', 'some extras',107 extra={'params': {'action': 'mozlog_test_output',108 'is_failure': False}})109 message_one_expected = {'_namespace': 'test.Logger',110 '_level': 'INFO',111 '_message': 'Message number 1'}112 message_two_expected = {'_namespace': 'test.Logger',113 '_level': 'ERROR',114 '_message': 'Message number 2'}115 message_three_expected = {'_namespace': 'test.Logger',116 '_level': 'DEBUG',117 '_message': 'Message with some extras',118 'action': 'mozlog_test_output',119 'is_failure': False}120 message_one_actual = json.loads(self.handler.messages[0])121 message_two_actual = json.loads(self.handler.messages[1])122 message_three_actual = json.loads(self.handler.messages[2])123 self.check_messages(message_one_expected, message_one_actual)124 self.check_messages(message_two_expected, message_two_actual)125 self.check_messages(message_three_expected, message_three_actual)126 def message_callback(self):127 if len(self.handler.messages) == 3:128 message_one_expected = {'_namespace': 'test.Logger',129 '_level': 'DEBUG',130 '_message': 'socket message one',131 'action': 'test_message'}132 message_two_expected = {'_namespace': 'test.Logger',133 '_level': 'DEBUG',134 '_message': 'socket message two',135 'action': 'test_message'}136 message_three_expected = {'_namespace': 'test.Logger',137 '_level': 'DEBUG',138 '_message': 'socket message three',139 'action': 'test_message'}140 message_one_actual = json.loads(self.handler.messages[0])141 message_two_actual = json.loads(self.handler.messages[1])142 message_three_actual = json.loads(self.handler.messages[2])143 self.check_messages(message_one_expected, message_one_actual)144 self.check_messages(message_two_expected, message_two_actual)145 self.check_messages(message_three_expected, message_three_actual)146 def test_log_listener(self):147 connection = '127.0.0.1', 0148 self.log_server = mozlog.LogMessageServer(connection,149 self.logger,150 message_callback=self.message_callback,151 timeout=0.5)152 message_string_one = json.dumps({'_message': 'socket message one',153 'action': 'test_message',154 '_level': 'DEBUG'})155 message_string_two = json.dumps({'_message': 'socket message two',156 'action': 'test_message',157 '_level': 'DEBUG'})158 message_string_three = json.dumps({'_message': 'socket message three',159 'action': 'test_message',...

Full Screen

Full Screen

checks.py

Source:checks.py Github

copy

Full Screen

1import os2import shutil3from django.conf import settings4from django.core.checks import Error, Warning, register5@register()6def paths_check(app_configs, **kwargs):7 """8 Check the various paths for existence, readability and writeability9 """10 check_messages = []11 exists_message = "{} is set but doesn't exist."12 exists_hint = "Create a directory at {}"13 writeable_message = "{} is not writeable"14 writeable_hint = (15 "Set the permissions of {} to be writeable by the user running the "16 "Paperless services"17 )18 directory = os.getenv("PAPERLESS_DBDIR")19 if directory:20 if not os.path.exists(directory):21 check_messages.append(Error(22 exists_message.format("PAPERLESS_DBDIR"),23 exists_hint.format(directory)24 ))25 if not check_messages:26 if not os.access(directory, os.W_OK | os.X_OK):27 check_messages.append(Error(28 writeable_message.format("PAPERLESS_DBDIR"),29 writeable_hint.format(directory)30 ))31 directory = os.getenv("PAPERLESS_MEDIADIR")32 if directory:33 if not os.path.exists(directory):34 check_messages.append(Error(35 exists_message.format("PAPERLESS_MEDIADIR"),36 exists_hint.format(directory)37 ))38 if not check_messages:39 if not os.access(directory, os.W_OK | os.X_OK):40 check_messages.append(Error(41 writeable_message.format("PAPERLESS_MEDIADIR"),42 writeable_hint.format(directory)43 ))44 directory = os.getenv("PAPERLESS_STATICDIR")45 if directory:46 if not os.path.exists(directory):47 check_messages.append(Error(48 exists_message.format("PAPERLESS_STATICDIR"),49 exists_hint.format(directory)50 ))51 if not check_messages:52 if not os.access(directory, os.W_OK | os.X_OK):53 check_messages.append(Error(54 writeable_message.format("PAPERLESS_STATICDIR"),55 writeable_hint.format(directory)56 ))57 return check_messages58@register()59def binaries_check(app_configs, **kwargs):60 """61 Paperless requires the existence of a few binaries, so we do some checks62 for those here.63 """64 error = "Paperless can't find {}. Without it, consumption is impossible."65 hint = "Either it's not in your ${PATH} or it's not installed."66 binaries = (67 settings.CONVERT_BINARY,68 settings.OPTIPNG_BINARY,69 settings.UNPAPER_BINARY,70 "tesseract"71 )72 check_messages = []73 for binary in binaries:74 if shutil.which(binary) is None:75 check_messages.append(Warning(error.format(binary), hint))...

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