<s> import re <EOL> import pytest <EOL> import urllib <EOL> import datetime <EOL> import mf2py <EOL> from redwind . models import User , Credential <EOL> from testutil import FakeResponse , assert_urls_match <EOL> def test_empty_db ( client ) : <EOL> """<STR_LIT>""" <EOL> rv = client . get ( '<STR_LIT:/>' ) <EOL> assert '<STR_LIT>' not in rv . get_data ( as_text = True ) <EOL> def test_create_post ( client , auth , mocker ) : <EOL> """<STR_LIT>""" <EOL> mocker . patch ( '<STR_LIT>' ) . return_value = FakeResponse ( ) <EOL> mocker . patch ( '<STR_LIT>' ) <EOL> rv = client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> } ) <EOL> assert <NUM_LIT> == rv . status_code <EOL> assert re . match ( '<STR_LIT>' , rv . location ) <EOL> rv = client . get ( rv . location ) <EOL> assert '<STR_LIT>' in rv . get_data ( as_text = True ) <EOL> @ pytest . fixture <EOL> def silly_posts ( client , auth , mocker ) : <EOL> mocker . patch ( '<STR_LIT>' ) . return_value = FakeResponse ( ) <EOL> mocker . patch ( '<STR_LIT>' ) <EOL> data = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> } , <EOL> ] <EOL> for datum in data : <EOL> datum [ '<STR_LIT:action>' ] = '<STR_LIT>' <EOL> rv = client . post ( '<STR_LIT>' , data = datum ) <EOL> assert <NUM_LIT> == rv . status_code <EOL> def test_tagged_posts ( client , silly_posts ) : <EOL> text = client . get ( '<STR_LIT>' ) . get_data ( as_text = True ) <EOL> assert '<STR_LIT>' in text <EOL> assert '<STR_LIT>' in text <EOL> def test_posts_by_type ( client , silly_posts ) : <EOL> text = client . get ( '<STR_LIT>' ) . get_data ( as_text = True ) <EOL> p = mf2py . parse ( doc = text ) <EOL> feed = p [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> for item , expected in zip ( feed , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) : <EOL> assert item [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] [ <NUM_LIT:0> ] == expected <EOL> def test_posts_everything ( client , silly_posts ) : <EOL> text = client . get ( '<STR_LIT>' ) . get_data ( as_text = True ) <EOL> assert '<STR_LIT>' in text <EOL> assert '<STR_LIT>' in text <EOL> def test_post_permalink ( client , silly_posts ) : <EOL> today = datetime . date . today ( ) <EOL> rv = client . get ( '<STR_LIT>' . format ( today . year , today . month , <EOL> '<STR_LIT>' ) ) <EOL> assert <NUM_LIT:200> == rv . status_code <EOL> content = rv . get_data ( as_text = True ) <EOL> assert '<STR_LIT>' in content <EOL> assert '<STR_LIT>' in content <EOL> assert re . search ( '<STR_LIT>' , content ) <EOL> def test_posts_atom ( client , silly_posts ) : <EOL> rv = client . get ( '<STR_LIT:/>' , query_string = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert <NUM_LIT:200> == rv . status_code <EOL> assert rv . content_type . startswith ( '<STR_LIT>' ) <EOL> content = rv . get_data ( as_text = True ) <EOL> assert '<STR_LIT>' in content <EOL> assert '<STR_LIT>' in content <EOL> rv = client . get ( '<STR_LIT>' , query_string = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert <NUM_LIT:200> == rv . status_code <EOL> assert rv . content_type . startswith ( '<STR_LIT>' ) <EOL> content = rv . get_data ( as_text = True ) <EOL> assert '<STR_LIT>' in content <EOL> assert '<STR_LIT>' in content <EOL> rv = client . get ( '<STR_LIT>' , query_string = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert <NUM_LIT:200> == rv . status_code <EOL> assert rv . content_type . startswith ( '<STR_LIT>' ) <EOL> content = rv . get_data ( as_text = True ) <EOL> assert '<STR_LIT>' in content <EOL> assert '<STR_LIT>' not in content <EOL> def test_tag_cloud ( client , silly_posts ) : <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert <NUM_LIT:200> == rv . status_code <EOL> content = rv . get_data ( as_text = True ) <EOL> print ( content ) <EOL> assert re . search ( '<STR_LIT>' , content , re . DOTALL ) <EOL> assert re . search ( '<STR_LIT>' , content , re . DOTALL ) <EOL> def test_atom_redirects ( client ) : <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert <NUM_LIT> == rv . status_code <EOL> assert rv . location . endswith ( '<STR_LIT>' ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert <NUM_LIT> == rv . status_code <EOL> assert rv . location . endswith ( '<STR_LIT>' ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert <NUM_LIT> == rv . status_code <EOL> assert rv . location . endswith ( '<STR_LIT>' ) <EOL> def test_upload_image ( client , mocker ) : <EOL> today = datetime . date . today ( ) <EOL> mocker . patch ( '<STR_LIT>' ) <EOL> mocker . patch ( '<STR_LIT>' ) <EOL> rv = client . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT>' : ( open ( '<STR_LIT>' , '<STR_LIT:rb>' ) , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> } ) <EOL> assert rv . status_code == <NUM_LIT> <EOL> assert ( rv . location == '<STR_LIT>' . format ( <EOL> today . year , today . month ) ) <EOL> permalink = rv . location <EOL> rv = client . get ( permalink ) <EOL> assert rv . status_code == <NUM_LIT:200> <EOL> content = rv . get_data ( as_text = True ) <EOL> assert '<STR_LIT>' in content <EOL> assert '<STR_LIT>' in content <EOL> rv = client . get ( permalink + '<STR_LIT>' ) <EOL> assert rv . status_code == <NUM_LIT:200> <EOL> def test_indieauth_login ( app , client , mocker ) : <EOL> mock_get = mocker . patch ( '<STR_LIT>' ) <EOL> mock_post = mocker . patch ( '<STR_LIT>' ) <EOL> mock_login = mocker . patch ( '<STR_LIT>' ) <EOL> mock_logout = mocker . patch ( '<STR_LIT>' ) <EOL> user_html = '<STR_LIT>' <EOL> mock_get . return_value = FakeResponse ( user_html ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> assert rv . status_code == <NUM_LIT> <EOL> assert_urls_match ( <EOL> rv . location , <EOL> '<STR_LIT>' + urllib . parse . urlencode ( { <EOL> '<STR_LIT:state>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) ) <EOL> mock_get . assert_called_once_with ( '<STR_LIT>' ) <EOL> mock_get . reset_mock ( ) <EOL> mock_post . return_value = FakeResponse ( urllib . parse . urlencode ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) ) <EOL> rv = client . get ( '<STR_LIT>' + urllib . parse . urlencode ( { <EOL> '<STR_LIT:code>' : '<STR_LIT>' <EOL> } ) ) <EOL> assert rv . status_code == <NUM_LIT> <EOL> assert rv . location == '<STR_LIT>' <EOL> mock_post . assert_called_once_with ( '<STR_LIT>' , data = { <EOL> '<STR_LIT:code>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:state>' : None , <EOL> } ) <EOL> mock_get . assert_called_once_with ( '<STR_LIT>' , headers = { '<STR_LIT>' : mf2py . Parser . useragent } ) <EOL> mock_login . assert_called_once_with ( <EOL> User ( id = <NUM_LIT:1> , name = '<STR_LIT>' ) , remember = True ) <EOL> cred = Credential . query . filter_by ( type = '<STR_LIT>' , <EOL> value = '<STR_LIT>' ) . first ( ) <EOL> assert cred <EOL> assert cred . user <EOL> assert cred . user . name == '<STR_LIT>' <EOL> client . get ( '<STR_LIT>' ) <EOL> mock_logout . assert_called_once_with ( ) </s>
