Skip to content

Commit

Permalink
Fixed tests and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
$MYNAME authored and $MYNAME committed Mar 3, 2021
1 parent 62c1c37 commit 9e17ea3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
21 changes: 12 additions & 9 deletions chatbot/app/handlers/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def view_my_profile(update, context):
return

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

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


Expand Down Expand Up @@ -356,7 +358,8 @@ def _get_real_post_id(context, user_choice):

def _show_user_single_post(update, context, post_id):
post = fpapi.get_post(post_id)
_assert_not_error(post)
if _is_error(post):
raise ConnectionError("Could not get post") # TODO handle errors better
reply_text = views.Post(post_json=post).display()
util.reply(
update=update,
Expand All @@ -366,9 +369,8 @@ def _show_user_single_post(update, context, post_id):
)


def _assert_not_error(post):
if isinstance(post, fpapi.Error): # TODO handle error better
raise ConnectionError("Could not get post")
def _is_error(post):
return isinstance(post, fpapi.Error)


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



def view_author_profile(update, context):
post_id = context.user_data.get(user_data.VIEW_POST_ID)
if post_id is None:
Expand All @@ -409,10 +410,12 @@ def handle_go_back_view_author(update, context):

def _get_author_profile_from_post_id(post_id):
raw_post = fpapi.get_post(post_id)
_assert_not_error(raw_post)
if _is_error(raw_post):
raise ConnectionError("Could not get post") # TODO handle errors better
post = views.Post(post_json=raw_post)
response = fpapi.get_user_profile(user_id=post.author_id)
_assert_not_error(response)
if _is_error(response):
raise ConnectionError("Could not get user profile") # TODO handle errors better
return views.UserProfile(response)


Expand Down
1 change: 0 additions & 1 deletion chatbot/app/keyboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def view_author():
]])



def no_location():
return InlineKeyboardMarkup([[
InlineKeyboardButton('I don\'t want to share my location right now', callback_data='view_posts'),
Expand Down
2 changes: 1 addition & 1 deletion chatbot/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, post_json):

self.title = self._extract_field(user_data.POST_TITLE)
self.author_data = self._extract_field(user_data.AUTHOR)
self.author_id = self.author_data[user_data.AUTHOR_ID]
self.author_id = self.author_data.get(user_data.AUTHOR_ID)
self.author = self.author_data[user_data.AUTHOR_NAME]
self.categories = self._extract_field(user_data.POST_CATEGORIES)
self.content = self._extract_field(user_data.POST_DESCRIPTION)
Expand Down
2 changes: 1 addition & 1 deletion token_data.default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Base URL
FP_BASE_URL: "https://fightpandemics.com/api/"
FP_BASE_URL: "http://127.0.0.1:8000/api/"

#################
# Access tokens #
Expand Down

0 comments on commit 9e17ea3

Please sign in to comment.