def test_add_false_positive(self):
        # Add a false positive to database and check that all fields
        # get populated and can be compared back originals
        issue = {'scenario_id': '1',
                 'url': 'testurl',
                 'severity': 'testseverity',
                 'issuetype': 'testissuetype',
                 'issuename': 'testissuename',
                 'issuedetail': 'testissuedetail',
                 'confidence': 'testconfidence',
                 'host': 'testhost',
                 'port': 'testport',
                 'protocol': 'testprotocol',
                 'messages': '{foo=bar}'}

        dbtools.add_false_positive(self.context, issue)

        # Connect directly to the database and check the data is there
        db_engine = sqlalchemy.create_engine(self.context.dburl)
        dbconn = db_engine.connect()
        db_metadata = sqlalchemy.MetaData()
        headlessscanner_issues = Table('headlessscanner_issues',
                                       db_metadata,
                                       Column('new_issue', types.Boolean),
                                       Column('issue_no', types.Integer, primary_key=True, nullable=False),  # Implicit autoincrement
                                       Column('timestamp', types.DateTime(timezone=True)),
                                       Column('test_runner_host', types.Text),
                                       Column('scenario_id', types.Text),
                                       Column('url', types.Text),
                                       Column('severity', types.Text),
                                       Column('issuetype', types.Text),
                                       Column('issuename', types.Text),
                                       Column('issuedetail', types.Text),
                                       Column('confidence', types.Text),
                                       Column('host', types.Text),
                                       Column('port', types.Text),
                                       Column('protocol', types.Text),
                                       Column('messages', types.LargeBinary))
        db_select = sqlalchemy.sql.select([headlessscanner_issues])
        db_result = dbconn.execute(db_select)
        result = db_result.fetchone()
        for key, value in issue.iteritems():
            if key == 'messages':
                self.assertEqual(result[key], json.dumps(value))
            else:
                self.assertEqual(result[key], value,
                                 '%s not found in database after add' % key)
        self.assertEqual(result['test_runner_host'], socket.gethostbyname(socket.getfqdn()),
                         'Test runner host name not correct in database')
        self.assertLessEqual(result['timestamp'], datetime.datetime.utcnow(),
                             'Timestamp not correctly stored in database')
        dbconn.close()
dataset/ETHPy150Open F-Secure/mittn/mittn/headlessscanner/test_dbtools.py/dbtools_test_case.test_add_false_positive/original