You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
5.0 KiB
136 lines
5.0 KiB
# coding: utf-8
|
|
|
|
from flask import url_for
|
|
from datetime import datetime
|
|
|
|
class TestArticleViews:
|
|
|
|
def test_get_articles_by_author(self, testapp, user):
|
|
user = user.get()
|
|
resp = testapp.post_json(url_for('user.login_user'), {'user': {
|
|
'email': user.email,
|
|
'password': 'myprecious'
|
|
}})
|
|
|
|
token = str(resp.json['user']['token'])
|
|
for _ in range(2):
|
|
testapp.post_json(url_for('articles.make_article'), {
|
|
"article": {
|
|
"title": "How to train your dragon {}".format(_),
|
|
"description": "Ever wonder how?",
|
|
"body": "You have to believe",
|
|
"tagList": ["reactjs", "angularjs", "dragons"]
|
|
}
|
|
}, headers={
|
|
'Authorization': 'Token {}'.format(token)
|
|
})
|
|
|
|
resp = testapp.get(url_for('articles.get_articles', author=user.username))
|
|
assert len(resp.json['articles']) == 2
|
|
|
|
def test_favorite_an_article(self, testapp, user):
|
|
user = user.get()
|
|
resp = testapp.post_json(url_for('user.login_user'), {'user': {
|
|
'email': user.email,
|
|
'password': 'myprecious'
|
|
}})
|
|
|
|
token = str(resp.json['user']['token'])
|
|
resp1 = testapp.post_json(url_for('articles.make_article'), {
|
|
"article": {
|
|
"title": "How to train your dragon",
|
|
"description": "Ever wonder how?",
|
|
"body": "You have to believe",
|
|
"tagList": ["reactjs", "angularjs", "dragons"]
|
|
}
|
|
}, headers={
|
|
'Authorization': 'Token {}'.format(token)
|
|
})
|
|
|
|
resp = testapp.post(url_for('articles.favorite_an_article',
|
|
slug=resp1.json['article']['slug']),
|
|
headers={
|
|
'Authorization': 'Token {}'.format(token)
|
|
}
|
|
)
|
|
assert resp.json['article']['favorited']
|
|
|
|
def test_get_articles_by_favoriter(self, testapp, user):
|
|
user = user.get()
|
|
resp = testapp.post_json(url_for('user.login_user'), {'user': {
|
|
'email': user.email,
|
|
'password': 'myprecious'
|
|
}})
|
|
|
|
token = str(resp.json['user']['token'])
|
|
for _ in range(2):
|
|
testapp.post_json(url_for('articles.make_article'), {
|
|
"article": {
|
|
"title": "How to train your dragon {}".format(_),
|
|
"description": "Ever wonder how?",
|
|
"body": "You have to believe",
|
|
"tagList": ["reactjs", "angularjs", "dragons"]
|
|
}
|
|
}, headers={
|
|
'Authorization': 'Token {}'.format(token)
|
|
})
|
|
|
|
resp = testapp.get(url_for('articles.get_articles', author=user.username))
|
|
assert len(resp.json['articles']) == 2
|
|
|
|
def test_make_article(self, testapp, user):
|
|
user = user.get()
|
|
resp = testapp.post_json(url_for('user.login_user'), {'user': {
|
|
'email': user.email,
|
|
'password': 'myprecious'
|
|
}})
|
|
|
|
token = str(resp.json['user']['token'])
|
|
resp = testapp.post_json(url_for('articles.make_article'), {
|
|
"article": {
|
|
"title": "How to train your dragon",
|
|
"description": "Ever wonder how?",
|
|
"body": "You have to believe",
|
|
"tagList": ["reactjs", "angularjs", "dragons"]
|
|
}
|
|
}, headers={
|
|
'Authorization': 'Token {}'.format(token)
|
|
})
|
|
assert resp.json['article']['author']['email'] == user.email
|
|
assert resp.json['article']['body'] == 'You have to believe'
|
|
|
|
def test_make_comment_correct_schema(self, testapp, user):
|
|
from conduit.profile.serializers import profile_schema
|
|
user = user.get()
|
|
resp = testapp.post_json(url_for('user.login_user'), {'user': {
|
|
'email': user.email,
|
|
'password': 'myprecious'
|
|
}})
|
|
|
|
token = str(resp.json['user']['token'])
|
|
resp = testapp.post_json(url_for('articles.make_article'), {
|
|
"article": {
|
|
"title": "How to train your dragon",
|
|
"description": "Ever wonder how?",
|
|
"body": "You have to believe",
|
|
"tagList": ["reactjs", "angularjs", "dragons"]
|
|
}
|
|
}, headers={
|
|
'Authorization': 'Token {}'.format(token)
|
|
})
|
|
slug = resp.json['article']['slug']
|
|
# make a comment
|
|
resp = testapp.post_json(url_for('articles.make_comment_on_article', slug=slug), {
|
|
"comment": {
|
|
"createdAt": datetime.now().isoformat(),
|
|
"body": "You have to believe",
|
|
}
|
|
}, headers={
|
|
'Authorization': 'Token {}'.format(token)
|
|
})
|
|
|
|
# check
|
|
authorp = resp.json['comment']['author']
|
|
del authorp['following']
|
|
# assert profile_schema.dump(user).data['profile'] == authorp
|
|
assert profile_schema.dump(user)['profile'] == authorp
|