[misc] Use single quotes when possible
This commit is contained in:
parent
d0fc51fd7e
commit
eba21e8409
|
@ -57,8 +57,8 @@ if argv[0].endswith('kibicara'):
|
|||
parser.add_argument(
|
||||
'-v',
|
||||
'--verbose',
|
||||
action="count",
|
||||
help="Raise verbosity level",
|
||||
action='count',
|
||||
help='Raise verbosity level',
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -72,7 +72,7 @@ if argv[0].endswith('kibicara_mda'):
|
|||
help='path to config file',
|
||||
)
|
||||
# the MDA passes the recipient address as command line argument
|
||||
parser.add_argument("recipient")
|
||||
parser.add_argument('recipient')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args is not None:
|
||||
|
|
|
@ -40,7 +40,7 @@ class Main:
|
|||
}
|
||||
basicConfig(
|
||||
level=LOGLEVELS.get(args.verbose, DEBUG),
|
||||
format="%(asctime)s %(name)s %(message)s",
|
||||
format='%(asctime)s %(name)s %(message)s',
|
||||
)
|
||||
getLogger('aiosqlite').setLevel(WARNING)
|
||||
Mapping.create_all()
|
||||
|
@ -71,8 +71,8 @@ class Main:
|
|||
CORSMiddleware,
|
||||
allow_origins=config['cors_allow_origin'],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
allow_methods=['*'],
|
||||
allow_headers=['*'],
|
||||
)
|
||||
if config['frontend_path'] is not None:
|
||||
app.mount(
|
||||
|
|
|
@ -51,11 +51,11 @@ class EmailBot(Censor):
|
|||
logger.debug('Trying to send: \n{0}'.format(body))
|
||||
email.send_email(
|
||||
subscriber.email,
|
||||
"Kibicara {0}".format(self.hood.name),
|
||||
'Kibicara {0}'.format(self.hood.name),
|
||||
body=body,
|
||||
)
|
||||
except (ConnectionRefusedError, SMTPException):
|
||||
logger.exception("Sending email to subscriber failed.")
|
||||
logger.exception('Sending email to subscriber failed.')
|
||||
|
||||
|
||||
spawner = Spawner(Hood, EmailBot)
|
||||
|
|
|
@ -202,17 +202,19 @@ async def email_subscribe(
|
|||
raise HTTPException(status_code=status.HTTP_409_CONFLICT)
|
||||
email.send_email(
|
||||
subscriber.email,
|
||||
"Subscribe to Kibicara {0}".format(hood.name),
|
||||
body='To confirm your subscription, follow this link: {0}'.format(confirm_link),
|
||||
'Subscribe to Kibicara {0}'.format(hood.name),
|
||||
body='To confirm your subscription, follow this link: {0}'.format(
|
||||
confirm_link
|
||||
),
|
||||
)
|
||||
return {}
|
||||
except ConnectionRefusedError:
|
||||
logger.info(token)
|
||||
logger.error("Sending subscription confirmation email failed.", exc_info=True)
|
||||
logger.error('Sending subscription confirmation email failed.', exc_info=True)
|
||||
raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY)
|
||||
except SMTPException:
|
||||
logger.info(token)
|
||||
logger.error("Sending subscription confirmation email failed.", exc_info=True)
|
||||
logger.error('Sending subscription confirmation email failed.', exc_info=True)
|
||||
raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY)
|
||||
|
||||
|
||||
|
@ -252,7 +254,7 @@ async def email_unsubscribe(token, hood=Depends(get_hood_unauthorized)):
|
|||
:param hood: Hood the Email bot belongs to.
|
||||
"""
|
||||
try:
|
||||
logger.warning("token is: {0}".format(token))
|
||||
logger.warning('token is: {0}'.format(token))
|
||||
payload = from_token(token)
|
||||
# If token.hood and url.hood are different, raise an error:
|
||||
if hood.id is not payload['hood']:
|
||||
|
@ -305,14 +307,14 @@ async def email_message_create(
|
|||
if message.secret == receiver.secret:
|
||||
# pass message.text to bot.py
|
||||
if await spawner.get(hood).publish(Message(message.text)):
|
||||
logger.warning("Message was accepted: {0}".format(message.text))
|
||||
logger.warning('Message was accepted: {0}'.format(message.text))
|
||||
return {}
|
||||
else:
|
||||
logger.warning("Message was't accepted: {0}".format(message.text))
|
||||
logger.warning('Message was\'t accepted: {0}'.format(message.text))
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS
|
||||
)
|
||||
logger.warning(
|
||||
"Someone is trying to submit an email without the correct API secret"
|
||||
'Someone is trying to submit an email without the correct API secret'
|
||||
)
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
|
|
|
@ -129,7 +129,7 @@ class TwitterBot(Censor):
|
|||
remove_indices.update(range(url.indices[0], url.indices[1] + 1))
|
||||
for symbol in entities.symbols:
|
||||
remove_indices.update(range(symbol.indices[0], symbol.indices[1] + 1))
|
||||
filtered_text = ""
|
||||
filtered_text = ''
|
||||
for index, character in enumerate(text):
|
||||
if index not in remove_indices:
|
||||
filtered_text += character
|
||||
|
|
|
@ -130,8 +130,8 @@ async def twitter_create(response: Response, hood=Depends(get_hood)):
|
|||
request_token = await get_oauth_token(
|
||||
config['twitter']['consumer_key'],
|
||||
config['twitter']['consumer_secret'],
|
||||
callback_uri="{0}/dashboard/twitter-callback?hood={1}".format(
|
||||
config["frontend_url"], hood.id
|
||||
callback_uri='{0}/dashboard/twitter-callback?hood={1}'.format(
|
||||
config['frontend_url'], hood.id
|
||||
),
|
||||
)
|
||||
if request_token['oauth_callback_confirmed'] != 'true':
|
||||
|
|
|
@ -111,7 +111,7 @@ async def admin_register(values: BodyAdmin):
|
|||
admin = await Admin.objects.filter(email=values.email).all()
|
||||
if admin:
|
||||
raise HTTPException(status_code=status.HTTP_409_CONFLICT)
|
||||
body = '{0}/confirm?token={1}'.format(config["frontend_url"], register_token)
|
||||
body = '{0}/confirm?token={1}'.format(config['frontend_url'], register_token)
|
||||
logger.debug(body)
|
||||
email.send_email(
|
||||
to=values.email,
|
||||
|
@ -183,7 +183,9 @@ async def admin_reset_password(values: BodyEmail):
|
|||
admin = await Admin.objects.filter(email=values.email).all()
|
||||
if not admin:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||
body = '{0}/password-reset?token={1}'.format(config["frontend_url"], register_token)
|
||||
body = '{0}/password-reset?token={1}'.format(
|
||||
config['frontend_url'], register_token
|
||||
)
|
||||
logger.debug(body)
|
||||
email.send_email(
|
||||
to=values.email,
|
||||
|
|
|
@ -9,7 +9,7 @@ from fastapi import status
|
|||
from pytest import fixture
|
||||
|
||||
|
||||
@fixture(scope="function")
|
||||
@fixture(scope='function')
|
||||
def email_row(client, hood_id, auth_header):
|
||||
response = client.post(
|
||||
'/api/hoods/{0}/email/'.format(hood_id),
|
||||
|
|
|
@ -41,8 +41,8 @@ def test_email_subscribe_unsubscribe(client, hood_id, receive_email):
|
|||
|
||||
def test_email_message(client, hood_id, trigger_id, email_row):
|
||||
body = {
|
||||
'text': "test",
|
||||
'author': "test@localhost",
|
||||
'text': 'test',
|
||||
'author': 'test@localhost',
|
||||
'secret': email_row['secret'],
|
||||
}
|
||||
response = client.post('/api/hoods/{0}/email/messages/'.format(hood_id), json=body)
|
||||
|
@ -78,6 +78,6 @@ test
|
|||
--AqNPlAX243a8sip3B7kXv8UKD8wuti--
|
||||
"""
|
||||
proc = subprocess.run(
|
||||
["kibicara_mda", "hood"], stdout=subprocess.PIPE, input=mail, encoding='ascii'
|
||||
['kibicara_mda', 'hood'], stdout=subprocess.PIPE, input=mail, encoding='ascii'
|
||||
)
|
||||
assert proc.returncode == 0
|
||||
|
|
|
@ -18,6 +18,6 @@ def test_email_delete_unauthorized(client, hood_id, email_row):
|
|||
|
||||
|
||||
def test_email_message_unauthorized(client, hood_id, email_row):
|
||||
body = {"text": "test", "author": "author", "secret": "wrong"}
|
||||
body = {'text': 'test', 'author': 'author', 'secret': 'wrong'}
|
||||
response = client.post('/api/hoods/{0}/email/messages/'.format(hood_id), json=body)
|
||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||
|
|
|
@ -32,8 +32,8 @@ def test_email_subscribe_confirm_wrong_hood(client):
|
|||
|
||||
def test_email_message_wrong(client, hood_id, email_row):
|
||||
body = {
|
||||
'text': "",
|
||||
'author': "test@localhost",
|
||||
'text': '',
|
||||
'author': 'test@localhost',
|
||||
'secret': email_row['secret'],
|
||||
}
|
||||
response = client.post('/api/hoods/{0}/email/messages/'.format(hood_id), json=body)
|
||||
|
|
Loading…
Reference in a new issue