<s> import datetime <EOL> import mock <EOL> from pyramid . testing import DummyRequest <EOL> import pytest <EOL> from h . api . models import elastic <EOL> from h . emails . reply_notification import generate <EOL> from h . models import Annotation <EOL> from h . models import Document , DocumentMeta <EOL> from h . models import User <EOL> from h . notification . reply_template import Notification <EOL> @ pytest . mark . usefixtures ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestGenerate ( object ) : <EOL> def test_calls_renderers_with_appropriate_context ( self , <EOL> req , <EOL> notification , <EOL> parent_user , <EOL> reply_user , <EOL> html_renderer , <EOL> text_renderer ) : <EOL> generate ( req , notification ) <EOL> expected_context = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : notification . parent , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : parent_user , <EOL> '<STR_LIT>' : notification . reply , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : reply_user , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> html_renderer . assert_ ( ** expected_context ) <EOL> text_renderer . assert_ ( ** expected_context ) <EOL> def test_falls_back_to_target_uri_for_document_title ( self , <EOL> req , <EOL> notification , <EOL> storage_driver , <EOL> html_renderer , <EOL> text_renderer ) : <EOL> if storage_driver == '<STR_LIT>' : <EOL> notification . document [ '<STR_LIT:title>' ] = [ ] <EOL> else : <EOL> notification . document . meta [ <NUM_LIT:0> ] . value = [ ] <EOL> generate ( req , notification ) <EOL> html_renderer . assert_ ( document_title = '<STR_LIT>' ) <EOL> text_renderer . assert_ ( document_title = '<STR_LIT>' ) <EOL> def test_returns_text_and_body_results_from_renderers ( self , <EOL> req , <EOL> notification , <EOL> html_renderer , <EOL> text_renderer ) : <EOL> html_renderer . string_response = '<STR_LIT>' <EOL> text_renderer . string_response = '<STR_LIT>' <EOL> _ , _ , text , html = generate ( req , notification ) <EOL> assert html == '<STR_LIT>' <EOL> assert text == '<STR_LIT>' <EOL> @ pytest . mark . usefixtures ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_returns_subject_with_reply_username ( self , req , notification ) : <EOL> _ , subject , _ , _ = generate ( req , notification ) <EOL> assert subject == '<STR_LIT>' <EOL> @ pytest . mark . usefixtures ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_returns_parent_email_as_recipients ( self , req , notification ) : <EOL> recipients , _ , _ , _ = generate ( req , notification ) <EOL> assert recipients == [ '<STR_LIT>' ] <EOL> @ pytest . mark . usefixtures ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_calls_token_serializer_with_correct_arguments ( self , <EOL> req , <EOL> notification , <EOL> token_serializer ) : <EOL> generate ( req , notification ) <EOL> token_serializer . dumps . assert_called_once_with ( { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> def test_jinja_templates_render ( self , config , req , notification ) : <EOL> """<STR_LIT>""" <EOL> config . include ( '<STR_LIT>' ) <EOL> config . add_jinja2_extension ( '<STR_LIT>' ) <EOL> generate ( req , notification ) <EOL> @ pytest . fixture <EOL> def routes ( self , config ) : <EOL> config . add_route ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> config . add_route ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> config . add_route ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def req ( self ) : <EOL> return DummyRequest ( auth_domain = '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def html_renderer ( self , config ) : <EOL> return config . testing_add_renderer ( '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def text_renderer ( self , config ) : <EOL> return config . testing_add_renderer ( '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def document ( self , storage_driver ) : <EOL> title = '<STR_LIT>' <EOL> if storage_driver == '<STR_LIT>' : <EOL> return elastic . Document ( title = [ title ] ) <EOL> else : <EOL> doc = Document ( ) <EOL> doc . meta . append ( DocumentMeta ( type = '<STR_LIT:title>' , value = [ title ] ) ) <EOL> return doc <EOL> @ pytest . fixture <EOL> def parent ( self , storage_driver ) : <EOL> common = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> } <EOL> uri = '<STR_LIT>' <EOL> if storage_driver == '<STR_LIT>' : <EOL> return elastic . Annotation ( uri = uri , ** common ) <EOL> else : <EOL> return Annotation ( target_uri = uri , ** common ) <EOL> @ pytest . fixture <EOL> def reply ( self , storage_driver ) : <EOL> common = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> } <EOL> uri = '<STR_LIT>' <EOL> if storage_driver == '<STR_LIT>' : <EOL> return elastic . Annotation ( uri = uri , ** common ) <EOL> else : <EOL> return Annotation ( target_uri = uri , ** common ) <EOL> @ pytest . fixture <EOL> def notification ( self , reply , reply_user , parent , parent_user , document ) : <EOL> return Notification ( reply = reply , <EOL> reply_user = reply_user , <EOL> parent = parent , <EOL> parent_user = parent_user , <EOL> document = document ) <EOL> @ pytest . fixture <EOL> def parent_user ( self ) : <EOL> return User ( username = '<STR_LIT>' , email = '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def reply_user ( self ) : <EOL> return User ( username = '<STR_LIT>' , email = '<STR_LIT>' ) <EOL> @ pytest . fixture ( params = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def storage_driver ( self , request ) : <EOL> return request . param <EOL> @ pytest . fixture <EOL> def token_serializer ( self , config ) : <EOL> serializer = mock . Mock ( spec_set = [ '<STR_LIT>' ] ) <EOL> serializer . dumps . return_value = '<STR_LIT>' <EOL> config . registry . notification_serializer = serializer <EOL> return serializer </s>
