<s> from __future__ import absolute_import <EOL> from __future__ import unicode_literals <EOL> import contextlib <EOL> import flask <EOL> import pyquery <EOL> import staticconf . testing <EOL> from git_code_debt . server . metric_config import CONFIG_NAMESPACE <EOL> from testing . assertions . response import assert_no_response_errors <EOL> from tests import file_diff_stat_test <EOL> def test_widget_frame_loads ( server ) : <EOL> response = server . client . get ( flask . url_for ( '<STR_LIT>' ) ) <EOL> assert_no_response_errors ( response ) <EOL> assert response . pq . find ( '<STR_LIT>' ) <EOL> @ contextlib . contextmanager <EOL> def metrics_enabled ( widget_metrics ) : <EOL> config = { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : widget_metrics , <EOL> } <EOL> with staticconf . testing . MockConfiguration ( <EOL> config , <EOL> flatten = False , <EOL> namespace = CONFIG_NAMESPACE , <EOL> ) : <EOL> yield <EOL> def test_widget_data ( server ) : <EOL> with metrics_enabled ( { '<STR_LIT>' : { } } ) : <EOL> response = server . client . post ( <EOL> flask . url_for ( '<STR_LIT>' ) , <EOL> data = { <EOL> '<STR_LIT>' : file_diff_stat_test . SAMPLE_OUTPUT <EOL> } <EOL> ) <EOL> response_pq = pyquery . PyQuery ( response . json [ '<STR_LIT>' ] ) <EOL> assert '<STR_LIT>' in response_pq . text ( ) <EOL> assert not response_pq . find ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' not in response_pq . text ( ) <EOL> def test_widget_data_multiple_values ( server ) : <EOL> with metrics_enabled ( <EOL> { '<STR_LIT>' : { } , '<STR_LIT>' : { } } <EOL> ) : <EOL> response = server . client . post ( <EOL> flask . url_for ( '<STR_LIT>' ) , <EOL> data = { <EOL> '<STR_LIT>' : file_diff_stat_test . SAMPLE_OUTPUT , <EOL> } , <EOL> ) <EOL> response_pq = pyquery . PyQuery ( response . json [ '<STR_LIT>' ] ) <EOL> assert '<STR_LIT>' in response_pq . text ( ) </s>
