def test_deleting_an_article(self, persisted_article): command = UserAuthenticationCommand(email='*****@*****.**', password='******') authenticated_user = UserAuthenticationService.authenticate_user( command) assert ArticleService.get_article( GetArticleCommand(slug=persisted_article.slug)) is not None command = DeleteArticleCommand(token=authenticated_user['token'], slug=persisted_article.slug) ArticleService.delete_article(command) assert ArticleService.get_article( GetArticleCommand(slug=persisted_article.slug)) is None
def delete_article(slug): if not slug: return '', 400 auth_header = request.headers.get('Authorization') if auth_header: auth_token = auth_header.split(" ")[1] else: auth_token = None if not auth_token: return '', 401 kwargs = {'token': auth_token, 'slug': slug} command = DeleteArticleCommand(**kwargs) ArticleService.delete_article(command) return '', 204