Skip to content

Commit 156d659

Browse files
author
Axel Dahlberg
committed
Fix unit tests
1 parent 3f1681f commit 156d659

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

chatbot/app/handlers/create_post.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ def _format_preview(context):
254254
def _format_preview_from_data(title, description, categories, user_name, location=None):
255255
data = {
256256
"post": {
257-
"title": title,
258-
"author": {
259-
"name": user_name,
260-
"location": location,
257+
user_data.POST_TITLE: title,
258+
user_data.AUTHOR: {
259+
user_data.AUTHOR_NAME: user_name,
260+
user_data.LOCATION: location,
261261
},
262-
"categories": categories,
263-
"description": description,
262+
user_data.POST_CATEGORIES: categories,
263+
user_data.POST_DESCRIPTION: description,
264+
user_data.NUM_COMMENTS: 0,
264265
},
265-
"numComments": 0,
266266
}
267267
return views.Post(post_json=data).display()
268268

chatbot/app/user_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
POST_DURATION = "post_duration"
1616
POST_OBJECTIVE = "post_objective"
1717

18+
NUM_COMMENTS = "commentsCount"
19+
1820
VIEW_PAGE_ID = 'page_id'
1921
VIEW_POST_ID = 'post_id'
2022
VIEW_POST_IDS = 'post_ids'

chatbot/app/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, post_json):
1717
self.categories = self._extract_field(user_data.POST_CATEGORIES)
1818
self.content = self._extract_field(user_data.POST_DESCRIPTION)
1919
self.location = self._extract_location(author_data[user_data.LOCATION])
20-
self.num_comments = self._extract_field('commentsCount')
20+
self.num_comments = self._extract_field(user_data.NUM_COMMENTS)
2121

2222
def _extract_field(self, field):
2323
data = self._get_data_from_post_json()

tests/unit/test_login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import random
22

3-
from chatbot.app import keyboards
3+
from chatbot.app import keyboards, constants
44
from chatbot.app.fp_api_manager import VALID_STATUS_CODES
55

66
from .conversation import (
@@ -14,7 +14,7 @@
1414
ANY,
1515
)
1616

17-
LOGIN_URL = 'http://127.0.0.1:8000/api/auth/login'
17+
LOGIN_URL = f'{constants.FP_BASE_URL}auth/login'
1818

1919

2020
def test_correct_login(mock_bot, mock_requests):

tests/unit/test_view_posts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from chatbot.app import keyboards
3+
from chatbot.app import keyboards, user_data
44
from chatbot.app.fp_api_manager import VALID_STATUS_CODES
55
from .conversation import (
66
UserAction,
@@ -13,18 +13,18 @@
1313

1414
TEST_POST_DATA = {
1515
'_id': 0,
16-
'title': 'Test Post',
17-
'author': {
18-
'name': 'Test Name',
19-
'location': {
16+
user_data.POST_TITLE: 'Test Post',
17+
user_data.AUTHOR: {
18+
user_data.AUTHOR_NAME: 'Test Name',
19+
user_data.LOCATION: {
2020
'city': 'Test City',
2121
'state': 'Test State',
2222
'country': 'Test Country',
2323
},
2424
},
25-
'categories': ['category1'],
26-
'content': "This is my test post",
27-
'numComments': 10,
25+
user_data.POST_CATEGORIES: ['category1'],
26+
user_data.POST_DESCRIPTION: "This is my test post",
27+
user_data.NUM_COMMENTS: 10,
2828
}
2929

3030
EXPECTED_RESPONSE_HEADER = "Page {page_nr} of your posts\n\n"

0 commit comments

Comments
 (0)