def import_certs(collab_url, username, password): """Import national CERTs information from AbuseHelper collab wiki.""" if click.confirm("This command should be run only once, on install", abort=True): ah_resp = requests.get(collab_url, auth=(username, password), verify=False) if ah_resp.status_code != 200: current_app.log.error(ah_resp.reason) raise click.Abort data = json.loads(ah_resp.text) for country, details in data.items(): org = Organization(abbreviation=country, group_id=2, full_name='National CERT of ' + country) try: org.mail_times = details['Mail times'][0] except IndexError: current_app.log.debug('Using default mail times...') try: org.mail_template = details['Mail template'][0] except IndexError: current_app.log.debug('Using default template...') org.abuse_emails = details['Abuse email'] click.echo("Adding {}...".format(country)) db.session.add(org) db.session.commit() click.echo('Done')
def test_create_organization(client): neworg = Organization(full_name=TAU.orgname, display_name=TAU.orgname) neworg.abuse_emails = ['*****@*****.**'] db.session.add(neworg) db.session.commit() assert Organization.query.filter_by( full_name=TAU.orgname).first(), 'Organization not inserted.' assert TAU.testOneOrganization(), 'Organization exists multible times'