diff --git a/chatbot/app/handlers/create_post.py b/chatbot/app/handlers/create_post.py index 23fa9a73..429a37b5 100644 --- a/chatbot/app/handlers/create_post.py +++ b/chatbot/app/handlers/create_post.py @@ -254,15 +254,15 @@ def _format_preview(context): def _format_preview_from_data(title, description, categories, user_name, location=None): data = { "post": { - "title": title, - "author": { - "name": user_name, - "location": location, + user_data.POST_TITLE: title, + user_data.AUTHOR: { + user_data.AUTHOR_NAME: user_name, + user_data.LOCATION: location, }, - "categories": categories, - "description": description, + user_data.POST_CATEGORIES: categories, + user_data.POST_DESCRIPTION: description, + user_data.NUM_COMMENTS: 0, }, - "numComments": 0, } return views.Post(post_json=data).display() diff --git a/chatbot/app/user_data.py b/chatbot/app/user_data.py index 6ef50563..3fe83950 100644 --- a/chatbot/app/user_data.py +++ b/chatbot/app/user_data.py @@ -15,6 +15,8 @@ POST_DURATION = "post_duration" POST_OBJECTIVE = "post_objective" +NUM_COMMENTS = "commentsCount" + VIEW_PAGE_ID = 'page_id' VIEW_POST_ID = 'post_id' VIEW_POST_IDS = 'post_ids' diff --git a/chatbot/app/views.py b/chatbot/app/views.py index b54ea5d1..072576c8 100644 --- a/chatbot/app/views.py +++ b/chatbot/app/views.py @@ -17,7 +17,7 @@ def __init__(self, post_json): self.categories = self._extract_field(user_data.POST_CATEGORIES) self.content = self._extract_field(user_data.POST_DESCRIPTION) self.location = self._extract_location(author_data[user_data.LOCATION]) - self.num_comments = self._extract_field('commentsCount') + self.num_comments = self._extract_field(user_data.NUM_COMMENTS) def _extract_field(self, field): data = self._get_data_from_post_json() diff --git a/tests/unit/test_login.py b/tests/unit/test_login.py index 46a26590..def723bf 100644 --- a/tests/unit/test_login.py +++ b/tests/unit/test_login.py @@ -1,6 +1,6 @@ import random -from chatbot.app import keyboards +from chatbot.app import keyboards, constants from chatbot.app.fp_api_manager import VALID_STATUS_CODES from .conversation import ( @@ -14,7 +14,7 @@ ANY, ) -LOGIN_URL = 'http://127.0.0.1:8000/api/auth/login' +LOGIN_URL = f'{constants.FP_BASE_URL}auth/login' def test_correct_login(mock_bot, mock_requests): diff --git a/tests/unit/test_view_posts.py b/tests/unit/test_view_posts.py index 8baa1cf0..54a3f595 100644 --- a/tests/unit/test_view_posts.py +++ b/tests/unit/test_view_posts.py @@ -1,6 +1,6 @@ import pytest -from chatbot.app import keyboards +from chatbot.app import keyboards, user_data from chatbot.app.fp_api_manager import VALID_STATUS_CODES from .conversation import ( UserAction, @@ -13,18 +13,18 @@ TEST_POST_DATA = { '_id': 0, - 'title': 'Test Post', - 'author': { - 'name': 'Test Name', - 'location': { + user_data.POST_TITLE: 'Test Post', + user_data.AUTHOR: { + user_data.AUTHOR_NAME: 'Test Name', + user_data.LOCATION: { 'city': 'Test City', 'state': 'Test State', 'country': 'Test Country', }, }, - 'categories': ['category1'], - 'content': "This is my test post", - 'numComments': 10, + user_data.POST_CATEGORIES: ['category1'], + user_data.POST_DESCRIPTION: "This is my test post", + user_data.NUM_COMMENTS: 10, } EXPECTED_RESPONSE_HEADER = "Page {page_nr} of your posts\n\n"