<s> from collections import OrderedDict <EOL> import tempfile <EOL> from bs4 import BeautifulSoup <EOL> import mock <EOL> import testtools <EOL> import bandit <EOL> from bandit . core import config <EOL> from bandit . core import issue <EOL> from bandit . core import manager <EOL> from bandit . formatters import html as b_html <EOL> class HtmlFormatterTests ( testtools . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( HtmlFormatterTests , self ) . setUp ( ) <EOL> conf = config . BanditConfig ( ) <EOL> self . manager = manager . BanditManager ( conf , '<STR_LIT:file>' ) <EOL> ( tmp_fd , self . tmp_fname ) = tempfile . mkstemp ( ) <EOL> self . manager . out_file = self . tmp_fname <EOL> def test_report_with_skipped ( self ) : <EOL> self . manager . skipped = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> b_html . report ( <EOL> self . manager , self . tmp_fname , bandit . LOW , bandit . LOW ) <EOL> with open ( self . tmp_fname ) as f : <EOL> soup = BeautifulSoup ( f . read ( ) , '<STR_LIT>' ) <EOL> skipped_span = soup . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <NUM_LIT:1> , len ( soup . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) ) ) <EOL> self . assertIn ( '<STR_LIT>' , skipped_span . text ) <EOL> self . assertIn ( '<STR_LIT>' , skipped_span . text ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_report_contents ( self , get_issue_list , get_code ) : <EOL> self . manager . metrics . data [ '<STR_LIT>' ] = { '<STR_LIT>' : <NUM_LIT:1000> , '<STR_LIT>' : <NUM_LIT:50> } <EOL> issue_a = _get_issue_instance ( severity = bandit . LOW ) <EOL> issue_a . fname = '<STR_LIT>' <EOL> issue_a . test = '<STR_LIT>' <EOL> issue_a . text = '<STR_LIT>' <EOL> issue_a . confidence = '<STR_LIT>' <EOL> issue_b = _get_issue_instance ( severity = bandit . MEDIUM ) <EOL> issue_c = _get_issue_instance ( severity = bandit . HIGH ) <EOL> issue_x = _get_issue_instance ( ) <EOL> get_code . return_value = '<STR_LIT>' <EOL> issue_y = _get_issue_instance ( ) <EOL> get_issue_list . return_value = OrderedDict ( [ ( issue_a , [ issue_x , <EOL> issue_y ] ) , <EOL> ( issue_b , [ issue_x ] ) , <EOL> ( issue_c , [ issue_y ] ) ] ) <EOL> b_html . report ( <EOL> self . manager , self . tmp_fname , bandit . LOW , bandit . LOW ) <EOL> with open ( self . tmp_fname ) as f : <EOL> soup = BeautifulSoup ( f . read ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , soup . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) [ <NUM_LIT:0> ] . text ) <EOL> self . assertEqual ( '<STR_LIT>' , soup . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) [ <NUM_LIT:0> ] . text ) <EOL> issue1 = soup . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> issue2 = soup . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> issue3 = soup . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <NUM_LIT:1> , len ( issue1 . find_all ( <EOL> '<STR_LIT>' , { '<STR_LIT:class>' : '<STR_LIT>' } ) ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( issue2 . find_all ( <EOL> '<STR_LIT>' , { '<STR_LIT:class>' : '<STR_LIT>' } ) ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( issue3 . find_all ( <EOL> '<STR_LIT>' , { '<STR_LIT:class>' : '<STR_LIT>' } ) ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( issue1 . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( issue1 . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( issue2 . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( issue2 . find_all ( '<STR_LIT>' , id = '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( issue1 . find_all ( '<STR_LIT>' , id = '<STR_LIT:code>' ) ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( issue2 . find_all ( '<STR_LIT>' , id = '<STR_LIT:code>' ) ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( issue3 . find_all ( '<STR_LIT>' , id = '<STR_LIT:code>' ) ) ) <EOL> self . assertIn ( '<STR_LIT>' , issue1 . find_all ( '<STR_LIT>' , <EOL> id = '<STR_LIT>' ) [ <NUM_LIT:0> ] . text ) <EOL> self . assertIn ( '<STR_LIT>' , issue2 . find_all ( '<STR_LIT>' , <EOL> id = '<STR_LIT:code>' ) [ <NUM_LIT:0> ] . text ) <EOL> self . assertIn ( '<STR_LIT>' , issue1 . text ) <EOL> self . assertIn ( '<STR_LIT>' , issue1 . text ) <EOL> self . assertIn ( '<STR_LIT>' , issue1 . text ) <EOL> self . assertIn ( '<STR_LIT>' , issue1 . text ) <EOL> def _get_issue_instance ( severity = bandit . MEDIUM , confidence = bandit . MEDIUM ) : <EOL> new_issue = issue . Issue ( severity , confidence , '<STR_LIT>' ) <EOL> new_issue . fname = '<STR_LIT>' <EOL> new_issue . test = '<STR_LIT>' <EOL> new_issue . lineno = <NUM_LIT:1> <EOL> return new_issue </s>
