Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Dahlberg committed Feb 19, 2021
1 parent 3f1681f commit 156d659
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
14 changes: 7 additions & 7 deletions chatbot/app/handlers/create_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions chatbot/app/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion chatbot/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_login.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_view_posts.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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"
Expand Down

0 comments on commit 156d659

Please sign in to comment.