Best Python code snippet using localstack_python
ses_service.py
Source:ses_service.py
...148 Returns:149 bool: True, for when account sending is enabled.150 '''151 self._log_enable_account_sending_request()152 self.client.update_account_sending_enabled(Enabled=True)153 self._log_enable_account_sending_response()154 return True155 def disable_account_sending(self):156 '''157 Disable account sending.158 Returns:159 bool: False, for when account sending is disabled.160 '''161 self._log_disable_account_sending_request()162 self.client.update_account_sending_enabled(Enabled=False)163 self._log_disable_account_sending_response()164 return False165 def _build_logger(self):166 '''167 Builds a logger instance.168 Returns:169 obj (logging.Logger): The Logger instance.170 '''171 logger = logging.getLogger(self.__module__)172 logger.addHandler(logging.NullHandler())173 return logger174 def _log_enable_account_sending_request(self):175 '''176 Log the enable account sending request....
test_ses_service.py
Source:test_ses_service.py
1# -*- coding: utf-8 -*-2from datetime import (3 datetime,4 timezone)5import boto36import pytest7from botocore.stub import Stubber8from ses_account_monitor.services.ses_service import SesService9@pytest.fixture10def client():11 return boto3.client('ses',12 aws_access_key_id='a',13 aws_secret_access_key='b',14 region_name='us-west-2')15@pytest.fixture16def service(client):17 return SesService(client=client)18@pytest.fixture19def ses_quota_responses():20 return (({21 'Max24HourSend': 123.0,22 'MaxSendRate': 523.0,23 'SentLast24Hours': 0.024 }, 90, False), ({25 'Max24HourSend': 123.0,26 'MaxSendRate': 523.0,27 'SentLast24Hours': 123.028 }, 80, True), ({29 'Max24HourSend': 123.0,30 'MaxSendRate': 523.0,31 'SentLast24Hours': 150.032 }, 100, True), ({33 'Max24HourSend': 123.0,34 'MaxSendRate': 523.0,35 'SentLast24Hours': 123.036 }, None, True))37@pytest.fixture38def datetime_utc():39 dt = datetime(2018, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc)40 return dt41@pytest.fixture42def iso8601_date(datetime_utc):43 return datetime_utc.isoformat()44def test_get_account_sending_quota(client, service, ses_quota_responses):45 stubber = Stubber(client)46 stubber.add_response('get_send_quota',47 ses_quota_responses[0][0],48 {})49 with stubber:50 result = service.get_account_sending_quota()51 assert result == {52 'Max24HourSend': 123.0,53 'MaxSendRate': 523.0,54 'SentLast24Hours': 0.055 }56def test_is_account_sending_rate_over(client, service, ses_quota_responses):57 stubber = Stubber(client)58 for response, percentage, expected_result in ses_quota_responses:59 stubber.add_response('get_send_quota',60 response,61 {})62 stubber.activate()63 result = service.is_account_sending_rate_over(percentage)64 stubber.deactivate()65 assert result == expected_result66def test_toggle_account_sending(client, service):67 stubber = Stubber(client)68 stubber.add_response('get_account_sending_enabled',69 {'Enabled': True},70 {})71 stubber.add_response('update_account_sending_enabled',72 {},73 {'Enabled': False})74 stubber.add_response('get_account_sending_enabled',75 {'Enabled': False},76 {})77 stubber.add_response('update_account_sending_enabled',78 {},79 {'Enabled': True})80 with stubber:81 disable_result = service.toggle_account_sending()82 assert disable_result is False83 enable_result = service.toggle_account_sending()84 assert enable_result is True85def test_enable_account_sending(client, service):86 stubber = Stubber(client)87 stubber.add_response('update_account_sending_enabled',88 {},89 {'Enabled': True})90 with stubber:91 result = service.enable_account_sending()92 assert result is True93def test_disable_account_sending(client, service):94 stubber = Stubber(client)95 stubber.add_response('update_account_sending_enabled',96 {},97 {'Enabled': False})98 with stubber:99 result = service.disable_account_sending()100 assert result is False101def test_get_account_sending_current_percentage(client, service):102 stubber = Stubber(client)103 stubber.add_response('get_send_quota',104 {105 'Max24HourSend': 10.0,106 'MaxSendRate': 50.0,107 'SentLast24Hours': 0.0108 },109 {})110 stubber.add_response('get_send_quota',111 {112 'Max24HourSend': 123.0,113 'MaxSendRate': 523.0,114 'SentLast24Hours': 150.0115 },116 {})117 with stubber:118 zero_result = service.get_account_sending_current_percentage()119 assert zero_result == 0120 hundred_result = service.get_account_sending_current_percentage()121 assert hundred_result > 100122def test_get_account_sending_remaining_percentage(client, service):123 stubber = Stubber(client)124 stubber.add_response('get_send_quota',125 {126 'Max24HourSend': 10.0,127 'MaxSendRate': 50.0,128 'SentLast24Hours': 0.0129 },130 {})131 stubber.add_response('get_send_quota',132 {133 'Max24HourSend': 123.0,134 'MaxSendRate': 523.0,135 'SentLast24Hours': 150.0136 },137 {})138 with stubber:139 hundred_result = service.get_account_sending_remaining_percentage()140 assert hundred_result == 100141 zero_result = service.get_account_sending_remaining_percentage()142 assert zero_result == 0143def test_get_account_sending_stats(client, service, iso8601_date):144 stubber = Stubber(client)145 stubber.add_response('get_send_quota',146 {147 'Max24HourSend': 50.0,148 'MaxSendRate': 50.0,149 'SentLast24Hours': 10.0150 },151 {})152 with stubber:153 result = service.get_account_sending_stats(event_iso_ts=iso8601_date)...
handler.py
Source:handler.py
...45 }],46 }47 return send_message(body)48def update_account_seding(is_enabled):49 response = ses_client.update_account_sending_enabled(Enabled=is_enabled)50def send_message(msg):51 req = Request(SLACK_WEBHOOK_URL, json.dumps(msg).encode('utf-8'))52 try:53 response = urlopen(req)54 response.read()55 log.info("Message posted to %s", msg['channel'])56 except HTTPError as e:57 log.debug("Request failed: %d %s", e.code, e.reason)58 except URLError as e:...
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!!