<s> """<STR_LIT>""" <EOL> from flask import url_for , json , current_app <EOL> from py . test import mark , raises <EOL> from werkzeug . exceptions import NotFound <EOL> from tentd . documents . entity import Post <EOL> from tentd . lib . flask import jsonify <EOL> from tentd . tests import response_has_link_header <EOL> from tentd . tests . http import * <EOL> from tentd . utils import time_to_string <EOL> from tentd . utils . exceptions import APIBadRequest <EOL> def test_link_header ( post ) : <EOL> """<STR_LIT>""" <EOL> assert response_has_link_header ( SHEAD ( '<STR_LIT>' ) ) <EOL> def test_create_post ( entity ) : <EOL> """<STR_LIT>""" <EOL> data = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : { <EOL> '<STR_LIT:text>' : "<STR_LIT>" <EOL> } , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : '<STR_LIT>' } <EOL> ] , <EOL> } <EOL> response = SPOST ( '<STR_LIT>' , data = data ) <EOL> assert '<STR_LIT:text>' in response . json ( ) [ '<STR_LIT:content>' ] <EOL> post_id = response . json ( ) [ '<STR_LIT:id>' ] <EOL> created_post = entity . posts . get ( id = post_id ) <EOL> assert created_post . schema == data [ '<STR_LIT:type>' ] <EOL> assert created_post . latest . content == data [ '<STR_LIT:content>' ] <EOL> response = GET ( '<STR_LIT>' , secure = True ) <EOL> assert '<STR_LIT:text>' in response . json ( ) [ <NUM_LIT:0> ] [ '<STR_LIT:content>' ] <EOL> def test_create_invalid_post ( entity ) : <EOL> """<STR_LIT>""" <EOL> with raises ( APIBadRequest ) : <EOL> SPOST ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_get_post ( post ) : <EOL> """<STR_LIT>""" <EOL> assert SGET ( '<STR_LIT>' , post_id = post . id ) . data == jsonify ( post ) . data <EOL> def test_get_post_version ( post ) : <EOL> posts_json = SGET ( '<STR_LIT>' , post_id = post . id ) . json ( ) <EOL> posts_db = [ v . to_json ( ) for v in post . versions ] <EOL> assert posts_json == posts_db <EOL> def test_get_post_mentions ( post ) : <EOL> """<STR_LIT>""" <EOL> response = SGET ( '<STR_LIT>' , post_id = post . id ) <EOL> assert response . json ( ) == post . versions [ <NUM_LIT:0> ] . mentions <EOL> def test_get_posts ( entity , post ) : <EOL> """<STR_LIT>""" <EOL> response = GET ( '<STR_LIT>' , secure = True ) <EOL> posts = jsonify ( [ p . to_json ( ) for p in entity . posts ] ) <EOL> assert response . data == posts . data <EOL> def test_get_empty_posts ( entity ) : <EOL> """<STR_LIT>""" <EOL> assert SGET ( '<STR_LIT>' ) . json ( ) == list ( ) <EOL> def test_update_post ( post ) : <EOL> """<STR_LIT>""" <EOL> response = SPUT ( '<STR_LIT>' , post_id = post . id , <EOL> data = { '<STR_LIT:content>' : { '<STR_LIT:text>' : '<STR_LIT>' , '<STR_LIT:location>' : None } } ) <EOL> post = Post . objects . get ( id = post . id ) <EOL> assert response . data == jsonify ( post ) . data <EOL> def test_update_post_with_invalid_data ( post ) : <EOL> """<STR_LIT>""" <EOL> with raises ( APIBadRequest ) : <EOL> SPUT ( '<STR_LIT>' , '<STR_LIT>' , post_id = post . id ) <EOL> def test_update_missing_post ( entity ) : <EOL> """<STR_LIT>""" <EOL> with raises ( NotFound ) : <EOL> SPUT ( '<STR_LIT>' , { } , post_id = '<STR_LIT>' ) <EOL> def test_delete_post ( entity , post ) : <EOL> """<STR_LIT>""" <EOL> SDELETE ( '<STR_LIT>' , post_id = post . id ) <EOL> assert entity . posts . count ( ) == <NUM_LIT:0> <EOL> def test_delete_post_version ( entity , post ) : <EOL> SDELETE ( '<STR_LIT>' , post_id = post . id , version = <NUM_LIT:0> ) <EOL> SDELETE ( '<STR_LIT>' , post_id = post . id , version = <NUM_LIT:0> ) <EOL> assert len ( entity . posts . get ( id = post . id ) . versions ) == <NUM_LIT:1> <EOL> with raises ( APIBadRequest ) : <EOL> SDELETE ( '<STR_LIT>' , post_id = post . id , version = <NUM_LIT:0> ) <EOL> def test_delete_invalid_post ( entity ) : <EOL> """<STR_LIT>""" <EOL> with raises ( NotFound ) : <EOL> SDELETE ( '<STR_LIT>' , post_id = '<STR_LIT>' ) </s>
