Beispiel #1
0
 def test_attributes(self):
     first, last = fake.first_name(), fake.last_name()
     author = Author.create(first=first, last=last)
     assert author.first == first
     assert author.last == last
     assert author.full_name == '{last}, {first}'.format(**locals())
     assert hasattr(author, 'id')
     assert isinstance(author.id, int)
     assert hasattr(author, 'books')
Beispiel #2
0
 def test_put_update_name(self, wt):
     author = AuthorFactory()
     url = url_for('books.AuthorDetail:put', id=author.id)
     new_first, new_last = fake.first_name(), fake.last_name()
     payload = {'first': new_first, 'last': new_last}
     res = wt.put_json(url, payload)
     assert res.status_code == 200
     latest = Author.get_latest()
     # Name was updated
     assert latest.first == new_first
     assert latest.last == new_last
Beispiel #3
0
 def test_post_creates_author(self, wt, url):
     old_count = Author.query.count()
     first, last = fake.first_name(), fake.last_name()
     res = wt.post_json(url, {'first': first, 'last': last})
     assert res.status_code == http.CREATED
     data = res.json['result']
     assert data['first'] == first
     assert data['last'] == last
     assert res.json['message'] == 'Successfully created new author'
     assert Author.query.count() == old_count + 1
     latest = Author.get_latest()
     assert latest.first == first
     assert latest.last == last