Skip to content

Commit

Permalink
feat: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinalbert committed May 20, 2024
1 parent 8dfd2cb commit 79afdb6
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 179 deletions.
26 changes: 13 additions & 13 deletions butter_cms/tests/test_author.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class TestListAuthor(unittest.TestCase):
def setUp(self):
self.token = os.getenv('DEMO_TOKEN')

@vcr.use_cassette('test_author_all_invalid_token.json')
@vcr.use_cassette('authors/test_author_all_invalid_token.json')
def test_invalid_token(self):
with self.assertRaises(HTTPError):
author = Author('invalid_token')
author.all()

@vcr.use_cassette('test_author_all.json')
@vcr.use_cassette('authors/test_author_all.json')
def test_all(self):
author = Author(self.token)
response = author.all()
Expand All @@ -30,10 +30,10 @@ def test_all(self):
self.assertGreater(len(data), 0)

author_data = data[0]
self.assertEqual('John', author_data.get('first_name'))
self.assertEqual('SDK', author_data.get('first_name'))
self.assertIsNone(author_data.get('recent_posts'))

@vcr.use_cassette('test_author_all_with_posts.json')
@vcr.use_cassette('authors/test_author_all_with_posts.json')
def test_all_include_recent_posts(self):
author = Author(self.token)
response = author.all(params={'include': 'recent_posts'})
Expand All @@ -47,44 +47,44 @@ def test_all_include_recent_posts(self):
self.assertGreater(len(data), 0)

author_data = data[0]
self.assertEqual('John', author_data.get('first_name'))
self.assertEqual('SDK', author_data.get('first_name'))
self.assertIn('recent_posts', author_data)
self.assertGreater(len(author_data['recent_posts']), 0)

class TestRetrieveAuthor(unittest.TestCase):
def setUp(self):
self.token = os.getenv('DEMO_TOKEN')

@vcr.use_cassette('test_author_get_invalid_token.json')
@vcr.use_cassette('authors/test_author_get_invalid_token.json')
def test_invalid_token(self):
with self.assertRaises(HTTPError):
author = Author('invalid_token')
author.get('john-doe')
author.get('sdk-tests')

@vcr.use_cassette('test_author_get.json')
@vcr.use_cassette('authors/test_author_get.json')
def test_get(self):
author = Author(self.token)
response = author.get('john-doe')
response = author.get('sdk-tests')

self.assertIsNotNone(response)
self.assertIn('data', response)

author_data = response['data']
self.assertIsNotNone(author_data)
self.assertEqual('John', author_data.get('first_name'))
self.assertEqual('SDK', author_data.get('first_name'))
self.assertIsNone(author_data.get('recent_posts'))

@vcr.use_cassette('test_author_get_with_posts.json')
@vcr.use_cassette('authors/test_author_get_with_posts.json')
def test_get_include_recent_posts(self):
author = Author(self.token)
response = author.get('john-doe', params={'include': 'recent_posts'})
response = author.get('sdk-tests', 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.assertEqual('SDK', author_data.get('first_name'))
self.assertIn('recent_posts', author_data)
self.assertGreater(len(author_data['recent_posts']), 0)

Expand Down
30 changes: 0 additions & 30 deletions butter_cms/tests/test_author_3.py

This file was deleted.

26 changes: 13 additions & 13 deletions butter_cms/tests/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class TestListCategory(unittest.TestCase):
def setUp(self):
self.token = os.getenv('DEMO_TOKEN')

@vcr.use_cassette('test_category_all_invalid_token.json')
@vcr.use_cassette('categories/test_category_all_invalid_token.json')
def test_invalid_token(self):
with self.assertRaises(HTTPError):
category = Category('invalid_token')
category.all()

@vcr.use_cassette('test_category_all.json')
@vcr.use_cassette('categories/test_category_all.json')
def test_all(self):
category = Category(self.token)
response = category.all()
Expand All @@ -30,10 +30,10 @@ def test_all(self):
self.assertGreater(len(data), 0)

category_data = data[0]
self.assertEqual('Category 1', category_data.get('name'))
self.assertEqual('Example Category', category_data.get('name'))
self.assertIsNone(category_data.get('recent_posts'))

@vcr.use_cassette('test_category_all_with_recent_posts.json')
@vcr.use_cassette('categories/test_category_all_with_recent_posts.json')
def test_all_include_recent_posts(self):
category = Category(self.token)
response = category.all(params={'include': 'recent_posts'})
Expand All @@ -47,43 +47,43 @@ def test_all_include_recent_posts(self):
self.assertGreater(len(data), 0)

category_data = data[0]
self.assertEqual('Category 1', category_data.get('name'))
self.assertEqual('Example Category', category_data.get('name'))
self.assertIn('recent_posts', category_data)
self.assertGreater(len(category_data['recent_posts']), 0)

class TestRetrieveCategory(unittest.TestCase):
def setUp(self):
self.token = os.getenv('DEMO_TOKEN')

@vcr.use_cassette('test_category_get_invalid_token.json')
@vcr.use_cassette('categories/test_category_get_invalid_token.json')
def test_invalid_token(self):
with self.assertRaises(HTTPError):
category = Category('invalid_token')
category.get('beer')
category.get('example-category')

@vcr.use_cassette('test_category_get.json')
@vcr.use_cassette('categories/test_category_get.json')
def test_get(self):
category = Category(self.token)
response = category.get('beer')
response = category.get('example-category')

self.assertIsNotNone(response)
self.assertIn('data', response)

category_data = response['data']
self.assertIsNotNone(category_data)
self.assertEqual('Category 1', category_data.get('name'))
self.assertEqual('Example Category', category_data.get('name'))
self.assertIsNone(category_data.get('recent_posts'))

@vcr.use_cassette('test_category_get_with_recent_posts.json')
@vcr.use_cassette('categories/test_category_get_with_recent_posts.json')
def test_get_include_recent_posts(self):
category = Category(self.token)
response = category.get('beer', params={'include': 'recent_posts'})
response = category.get('example-category', params={'include': 'recent_posts'})

self.assertIsNotNone(response)
self.assertIn('data', response)

category_data = response['data']
self.assertIsNotNone(category_data)
self.assertEqual('Category 1', category_data.get('name'))
self.assertEqual('Example Category', category_data.get('name'))
self.assertIn('recent_posts', category_data)
self.assertGreater(len(category_data['recent_posts']), 0)
76 changes: 39 additions & 37 deletions butter_cms/tests/test_content_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,103 +10,105 @@ class TestListContentField(unittest.TestCase):
def setUp(self):
self.token = os.getenv('DEMO_TOKEN')

@vcr.use_cassette('test_content_field_all_invalid_token.json')
@vcr.use_cassette('content_fields/test_content_field_all_invalid_token.json')
def test_invalid_token(self):
with self.assertRaises(HTTPError):
content_field = ContentField('invalid_token')
content_field.get()
content_field.get(keys=[])

@vcr.use_cassette('test_content_field_all.json')
@vcr.use_cassette('content_fields/test_content_field_all.json')
def test_list_content_fields_without_filtering(self):
content_field = ContentField(self.token)
response = content_field.get()
response = content_field.get(keys=[])

self.assertIsNotNone(response)
self.assertNotIn('data', response)

@vcr.use_cassette('test_content_field_all_filtered.json')
@vcr.use_cassette('content_fields/test_content_field_all_filtered.json')
def test_list_filtered_content_fields(self):
content_field = ContentField(self.token)
response = content_field.get(keys=['key1', 'key2'])
response = content_field.get(keys=['navigation_menu', 'navigation_menu_item'])

self.assertIsNotNone(response)
self.assertIn('data', response)

data = response['data']
self.assertIsNotNone(data)
self.assertIn('key1', data)
self.assertIn('key2', data)
self.assertIn('navigation_menu', data)
self.assertIn('navigation_menu_item', data)

k1 = data['key1']
self.assertEqual(2, len(k1))
k1 = data['navigation_menu']
self.assertEqual(len(k1), 1)
self.assertIn('meta', k1[0])
self.assertIn('id', k1[0]['meta'])

k2 = data['key2']
self.assertEqual(1, len(k2))
k2 = data['navigation_menu_item']
self.assertGreater(len(k2), 1)
self.assertIn('meta', k2[0])
self.assertIn('id', k2[0]['meta'])

@vcr.use_cassette('test_content_field_non_existent_key.json')
@vcr.use_cassette('content_fields/test_content_field_all_non_existent_key.json')
def test_list_non_existent_content_field(self):
content_field = ContentField(self.token)
response = content_field.get(keys=['non-existent-key'])
with self.assertRaises(HTTPError):
content_field = ContentField(self.token)
response = content_field.get(keys=['non-existent-key'])

self.assertIsNotNone(response)
self.assertIn('detail', response)
self.assertEqual('Content key non-existent-key not found', response['detail'])
self.assertIsNotNone(response)
self.assertIn('detail', response)
self.assertEqual('Content key non-existent-key not found', response['detail'])

class TestRetrieveContentField(unittest.TestCase):
def setUp(self):
self.token = os.getenv('DEMO_TOKEN')

@vcr.use_cassette('test_content_field_get_invalid_token.json')
@vcr.use_cassette('content_fields/test_content_field_get_invalid_token.json')
def test_invalid_token(self):
with self.assertRaises(HTTPError):
content_field = ContentField('invalid_token')
content_field.get_collection('field')
content_field.get_collection('navigation_menu_item')

@vcr.use_cassette('test_content_field_get.json')
@vcr.use_cassette('content_fields/test_content_field_get.json')
def test_get_content_field_without_filtering(self):
content_field = ContentField(self.token)
response = content_field.get_collection('field')
response = content_field.get_collection('navigation_menu_item')

self.assertIsNotNone(response)
self.assertIn('data', response)

data = response['data']
self.assertIsNotNone(data)
self.assertIn('field', data)
self.assertIn('navigation_menu_item', data)

f = data['field']
self.assertEqual(2, len(f))
f = data['navigation_menu_item']
self.assertGreater(len(f), 1)
self.assertIn('meta', f[0])
self.assertIn('id', f[0]['meta'])

@vcr.use_cassette('test_content_field_get_filtered.json')
@vcr.use_cassette('content_fields/test_content_field_get_filtered.json')
def test_get_filtered_content_field(self):
content_field = ContentField(self.token)
response = content_field.get_collection('field', fields=[{'key': 'example'}])
response = content_field.get_collection('navigation_menu_item', fields=[{'label': 'Testimonials'}])

self.assertIsNotNone(response)
self.assertIn('data', response)

data = response['data']
self.assertIsNotNone(data)
self.assertIn('field', data)
self.assertIn('navigation_menu_item', data)

f = data['field']
f = data['navigation_menu_item']
self.assertEqual(1, len(f))
self.assertIn('meta', f[0])
self.assertIn('id', f[0]['meta'])
self.assertIn('key', f[0])
self.assertEqual('example', f[0]['key'])
self.assertIn('label', f[0])
self.assertEqual('Testimonials', f[0]['label'])

@vcr.use_cassette('test_content_field_get_non_existent_field.json')
@vcr.use_cassette('content_fields/test_content_field_get_non_existent_field.json')
def test_get_non_existent_content_field(self):
content_field = ContentField(self.token)
response = content_field.get_collection('not-existed-field')
with self.assertRaises(HTTPError):
content_field = ContentField(self.token)
response = content_field.get_collection('not-existent-field')

self.assertIsNotNone(response)
self.assertIn('detail', response)
self.assertEqual('Not found', response['detail'])
self.assertIsNotNone(response)
self.assertIn('detail', response)
self.assertEqual('Not found', response['detail'])
Loading

0 comments on commit 79afdb6

Please sign in to comment.