def test_does_not_overwrite(self, users, existing_file): with pytest.raises(IOError) as err: export(existing_file, users, overwrite=False) assert err.match( r"'{}' already exists\.".format(existing_file) ) # let's also verify the file is still intact assert existing_file.read() == 'Please leave me alone...'
def test_export_quoting(self, min_user, csv_file): min_user['name'] = 'A name, with a comma' export(csv_file, [min_user]) lines = csv_file.readlines() assert [ 'email,name,age,role\n', '[email protected],"A name, with a comma",18,\n', ] == lines
def test_export(self, users, csv_file): export(csv_file, users) lines = csv_file.readlines() assert [ 'email,name,age,role\n', '[email protected],Primus Minimus,18,\n', '[email protected],Maximus Plenus,65,emperor\n', ] == lines
def export(clan, filename): output = BytesIO() api.export(clan, output) output.seek(0) return send_file(output, attachment_filename=filename, as_attachment=True)
user['cpu_cores'] = static_data['cpu_cores'] user['installed_ram'] = static_data['installed_ram'] user['data'] = { 'used_cpu': [], 'used_ram': [] } if discard: print('[Main] Discarding test for user:'******'slack']) print('[Main] Gathering device use each ' + str(test['sample_time']) + ' secs...') count = 0 while count < test['test_time']: print('[Main] Probing SNMP agents for variable data: step (' + str(round(count/test['sample_time'], 0)+1).split('.')[0] + '/' + str(round(test['test_time']/test['sample_time'], 0)).split('.')[0] + ')') for user in api.users: ip = user['ip'] domain = user['slack'] + '@' + user['ip'] variable_data = api.get_variable_data(ip) if api.trap_check(ip): print('[DISCARD] Trap received from ' + domain) user["discard"].append({"trap_received": True}) user["data"]["used_cpu"].append(variable_data["used_cpu"]) user["data"]["used_ram"].append(variable_data["used_ram"]) count += test['sample_time'] time.sleep(test['sample_time']) api.export(api.users, 'results.json') api.to_slack() api.running = False