-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_author.py
75 lines (58 loc) · 2.65 KB
/
test_author.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import unittest
from unittest.mock import patch
from butter_cms.author import Author
from butter_cms.tests.mocks.author_mocks import list_authors, list_authors_with_posts, get_author, get_author_with_posts
class TestListAuthor(unittest.TestCase):
@patch('butter_cms.author.Author.all')
def test_all(self, mock_all):
mock_all.return_value = list_authors()
author = Author('<demo-token>')
response = author.all()
self.assertIsNotNone(response)
self.assertIn('data', response)
data = response['data']
self.assertIsNotNone(data)
self.assertIsInstance(data, list)
self.assertGreater(len(data), 0)
author_data = data[0]
self.assertEqual('John', author_data.get('first_name'))
self.assertIsNone(author_data.get('recent_posts'))
@patch('butter_cms.author.Author.all')
def test_all_include_recent_posts(self, mock_all):
mock_all.return_value = list_authors_with_posts()
author = Author('<demo-token>')
response = author.all(params={'include': 'recent_posts'})
self.assertIsNotNone(response)
self.assertIn('data', response)
data = response['data']
self.assertIsNotNone(data)
self.assertIsInstance(data, list)
self.assertGreater(len(data), 0)
author_data = data[0]
self.assertEqual('John', author_data.get('first_name'))
self.assertIn('recent_posts', author_data)
self.assertGreater(len(author_data['recent_posts']), 0)
class TestRetrieveAuthor(unittest.TestCase):
@patch('butter_cms.author.Author.get')
def test_get(self, mock_get):
mock_get.return_value = get_author()
author = Author('<demo-token>')
response = author.get('john-doe')
self.assertIsNotNone(response)
self.assertIn('data', response)
author_data = response['data']
self.assertIsNotNone(author_data)
self.assertEqual('John', author_data.get('first_name'))
self.assertIsNone(author_data.get('recent_posts'))
@patch('butter_cms.author.Author.get')
def test_get_include_recent_posts(self, mock_get):
mock_get.return_value = get_author_with_posts()
author = Author('<demo-token>')
response = author.get('john-doe', params={'include': 'recent_posts'})
self.assertIsNotNone(response)
self.assertIn('data', response)
author_data = response['data']
self.assertIsNotNone(author_data)
self.assertEqual('John', author_data.get('first_name'))
self.assertIn('recent_posts', author_data)
self.assertGreater(len(author_data['recent_posts']), 0)