Skip to content

Commit 9e17ea3

Browse files
$MYNAME$MYNAME
$MYNAME
authored and
$MYNAME
committed
Fixed tests and linting
1 parent 62c1c37 commit 9e17ea3

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

chatbot/app/handlers/view.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def view_my_profile(update, context):
3434
return
3535

3636
response = fpapi.get_current_user_profile(token=token)
37-
_assert_not_error(response)
37+
if _is_error(response):
38+
raise ConnectionError("Could not get current profile") # TODO handle errors better
3839
user_info_view = views.UserProfile(response).display()
3940
update.effective_message.reply_text(text=user_info_view)
4041

@@ -187,7 +188,8 @@ def _get_posts(context, payload):
187188
# keep a copy of post_payload in user_data for future calls - TODO is it used?
188189
context.user_data[user_data.VIEW_POST_PAYLOAD] = payload
189190
posts = fpapi.get_posts(payload)
190-
_assert_not_error(posts)
191+
if _is_error(posts):
192+
raise ConnectionError("Could not get posts") # TODO handle errors better
191193
return posts
192194

193195

@@ -356,7 +358,8 @@ def _get_real_post_id(context, user_choice):
356358

357359
def _show_user_single_post(update, context, post_id):
358360
post = fpapi.get_post(post_id)
359-
_assert_not_error(post)
361+
if _is_error(post):
362+
raise ConnectionError("Could not get post") # TODO handle errors better
360363
reply_text = views.Post(post_json=post).display()
361364
util.reply(
362365
update=update,
@@ -366,9 +369,8 @@ def _show_user_single_post(update, context, post_id):
366369
)
367370

368371

369-
def _assert_not_error(post):
370-
if isinstance(post, fpapi.Error): # TODO handle error better
371-
raise ConnectionError("Could not get post")
372+
def _is_error(post):
373+
return isinstance(post, fpapi.Error)
372374

373375

374376
def _get_header_message_with_categories(context):
@@ -383,7 +385,6 @@ def _get_header_message_user_posts(context):
383385
return f"Page {page} of your posts"
384386

385387

386-
387388
def view_author_profile(update, context):
388389
post_id = context.user_data.get(user_data.VIEW_POST_ID)
389390
if post_id is None:
@@ -409,10 +410,12 @@ def handle_go_back_view_author(update, context):
409410

410411
def _get_author_profile_from_post_id(post_id):
411412
raw_post = fpapi.get_post(post_id)
412-
_assert_not_error(raw_post)
413+
if _is_error(raw_post):
414+
raise ConnectionError("Could not get post") # TODO handle errors better
413415
post = views.Post(post_json=raw_post)
414416
response = fpapi.get_user_profile(user_id=post.author_id)
415-
_assert_not_error(response)
417+
if _is_error(response):
418+
raise ConnectionError("Could not get user profile") # TODO handle errors better
416419
return views.UserProfile(response)
417420

418421

chatbot/app/keyboards.py

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def view_author():
125125
]])
126126

127127

128-
129128
def no_location():
130129
return InlineKeyboardMarkup([[
131130
InlineKeyboardButton('I don\'t want to share my location right now', callback_data='view_posts'),

chatbot/app/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, post_json):
1313

1414
self.title = self._extract_field(user_data.POST_TITLE)
1515
self.author_data = self._extract_field(user_data.AUTHOR)
16-
self.author_id = self.author_data[user_data.AUTHOR_ID]
16+
self.author_id = self.author_data.get(user_data.AUTHOR_ID)
1717
self.author = self.author_data[user_data.AUTHOR_NAME]
1818
self.categories = self._extract_field(user_data.POST_CATEGORIES)
1919
self.content = self._extract_field(user_data.POST_DESCRIPTION)

token_data.default.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Base URL
2-
FP_BASE_URL: "https://fightpandemics.com/api/"
2+
FP_BASE_URL: "http://127.0.0.1:8000/api/"
33

44
#################
55
# Access tokens #

0 commit comments

Comments
 (0)