def test_get_new_user(self): # user doesn't exist user_email = "*****@*****.**" result = get_user(user_email, self.session) user_list = self.session.query(User).all() self.assertEqual([result], user_list)
def add_user(insert): if isinstance(insert, dict): if 'user' not in insert.keys(): insert['user'] = get_user() elif isinstance(insert, list): for el in insert: el = add_user(el) return insert
def test_add_and_delete_user(self): user = {"name":"test","nick":"test_nick","avatar":None,"email":"*****@*****.**"} with app.app_context(): user_id = add_new_user(user["name"],user["nick"],user["avatar"],user["email"]) res = get_user(user_id) self.assertTrue(user,res) res = remove_user(user_id) self.assertTrue(res,True)
def test_user_parsing(self): # Setup detailsFile = open("data.txt", "w+") detailsFile.write("username:password") detailsFile.close() # Test self.assertEqual(get_user(), ["username", "password"]) # Delete data.txt file after text os.remove("data.txt")
def test_get_user_already_exists(self): # user already exists user = User("laura_miller", "laura", "miller") self.session.add(user) self.session.commit() user_email = "*****@*****.**" result = get_user(user_email, self.session) user_list = self.session.query(User).all() self.assertEqual(result, user) self.assertEqual([result], user_list)
def test_get_user(): get_user('U024SNTB4')['profile']['first_name'] == u'JC'
def test_get_user(fx_app): with fx_app.test_request_context(): get_user('U024SNTB4')['profile']['first_name'] == u'JC'
def download(): download_type = flask.request.args.get('type') strIO = io.BytesIO() if download_type == 'pdf': strIO = utils.download_as_buffer(config.tmp_bucket, config.files['explain_pdf']) send_info = dict( attachment_filename='Uitleg_{}.pdf'.format(str(dt.now())), mimetype='application/pdf', ) elif download_type == 'pdf_status': strIO = utils.download_as_buffer( config.tmp_bucket, config.files['explain_status_check_pdf']) send_info = dict( attachment_filename='Uitleg_statuscheck_{}.pdf'.format( str(dt.now())), mimetype='application/pdf', ) # Download connect orders elif download_type == 'hFwmotkaNo': value = flask.request.args.get('value') # create a dynamic csv or file here using `StringIO` excel_writer = pd.ExcelWriter(strIO, engine="xlsxwriter") yellow = excel_writer.book.add_format({'bg_color': '#F2DB09'}) df = get_con_df(value, short=False) df.to_excel(excel_writer, sheet_name=download_config[download_type]['sheetname'], index=False) ws = excel_writer.sheets[download_config[download_type]['sheetname']] ws.freeze_panes(1, 0) ws.set_column('A:AH', 22) ws.set_column('D:D', 22, yellow) ws.autofilter(0, 0, df.shape[0], df.shape[1] - 1) excel_writer.save() with Connection('w', 'log download') as session: czLog.insert([{ 'user': get_user(), 'action': 'download', 'description': 'conobjid-cpnr', 'parameter': value, }], session) send_info = dict(attachment_filename='{}_{}_{}.xlsx'.format( download_config[download_type]['filename'], str(value), str(dt.now()), ), ) # Download problem table elif download_type == 'problem': # Get values from url pr_dropdown_values = flask.request.args.get('problems').split('|') if pr_dropdown_values == ['']: pr_dropdown_values = [] category_values = flask.request.args.get('category').split('|') if category_values == ['']: category_values = [] with Connection('r', 'read overview: download_overview') as session: overview = read(session, 'projectstructure').fillna('') overview = overview[download_config[download_type]['col_order']] # Get status q_select = sa.select([czCleaning.key, czCleaning.status, czCleaning.updated]).\ where(czCleaning.versionEnd.is_(None)).\ where(czCleaning.kind == 'ln|cp|con') with Connection('r', 'read complete czCleaning') as session: status = pd.read_sql(q_select, session.bind).\ fillna("").\ rename(columns={'status': 'bewerkingsstatus'}) df = get_problem_table( overview, pr_dropdown_values, category_values, status)[download_config[download_type]['col_order2']] excel_writer = pd.ExcelWriter(strIO, engine="xlsxwriter") df.to_excel(excel_writer, sheet_name="overview", index=False) ws = excel_writer.sheets['overview'] ws.freeze_panes(1, 0) ws.set_column('A:AH', 22) ws.autofilter(0, 0, df.shape[0], df.shape[1] - 1) excel_writer.save() send_info = dict( attachment_filename='Overview_{}.xlsx'.format(str(dt.now()))) elif download_type == 'diff': old = flask.request.args.get('old') new = flask.request.args.get('new') with Connection('r', 'read_diff_download') as session: olddf = read(session, sourceTag='projectstructure', ts=old) newdf = read(session, sourceTag='projectstructure', ts=new) excel_writer = pd.ExcelWriter(strIO, engine="xlsxwriter") excel_writer = compare_download(newdf, olddf, excel_writer, new, old) excel_writer.save() send_info = dict( attachment_filename='Verschillen_vorig{}_nieuw{}_{}.xlsx'.format( old, new, str(dt.now()), ), ) elif download_type == 'status': intake_value = flask.request.args.get('intake') selected_cells = flask.request.args.get('cells') hist = flask.request.args.get('hist') excel_writer = pd.ExcelWriter(strIO, engine="xlsxwriter") excel_writer = status_download_file(excel_writer, intake_value, selected_cells, hist) excel_writer.save() send_info = dict( attachment_filename='Status_{}.xlsx'.format(str(dt.now()))) strIO.seek(0) return flask.send_file(strIO, as_attachment=True, **send_info)
def test_get_user(self): actual = app.get_user() self.assertEqual(actual, { "name" : "Sam" } )
def update_cleaning(system, value, set_state_dropdown): names = { 'ln': 'InforLN project', 'cp': 'ChangePoint bouwplannummer', 'con': 'Connect Opdracht ID' } if system in names: name = names[system] else: raise ValueError('No correct system in function update_cleaning') if value != '': try: if system == 'ln': df = get_table_partition_df(lnnr=[value]) elif system == 'con': df = get_table_partition_df(con_opdrachtid=[value]) elif system == 'cp': df = get_table_partition_df(bpnr=[value]) name = names[system] ts = dt.now().strftime("%Y-%m-%d %H:%M:%S") new_status = '' if set_state_dropdown != '': new_status = set_state_dropdown + ' ' + get_user().split( '@')[0] q_update = sa.update(czCleaning).\ where(czCleaning.versionEnd.is_(None)).\ where(czCleaning.kind == 'ln|cp|con').\ where(czCleaning.key.in_(df['key'].tolist())).\ values(status=new_status, updated=ts) with Connection('w', 'update czCleaning') as session: session.execute(q_update) czLog.insert([{ 'action': 'update', 'description': "cleaning-ln|cp|con, system: {}, status: '{}'".format( system, set_state_dropdown), 'parameter': value, 'created': ts, }], session) color = 'success' if set_state_dropdown == '': set_state_dropdown = 'Geen' message = 'Status voor projecten gerelateerd aan {} {} succesvol geüpdate naar {}'.format( name, value, set_state_dropdown) except Exception as e: print(e) color = 'danger' message = 'Foutmelding, status niet geüpdate' else: color = 'warning' message = 'Geen {} gegeven'.format(name) return [alert(message, color)]
def update_user_table(): q_select = sa.select([czCleaning.key, czCleaning.status, czCleaning.updated]).\ where(czCleaning.versionEnd.is_(None)).\ where(czCleaning.kind == 'ln|cp|con') with Connection('r', 'read complete czCleaning') as session: status = pd.read_sql(q_select, session.bind).\ fillna("").\ rename(columns={'status': 'bewerkingsstatus'}) user_title = html.Div( html.Div( html.H4("Door gebruiker '{}' in verschillende statussen geplaatst". format(get_user()), className='lead'), style={ 'margin-left': '10%', 'margin-right': '10%', 'margin-top': '2%', 'margin-bottom': '2%', }, ), style=styles['box_header'], ) df = status[status['bewerkingsstatus'].str.contains('Control')] df = df.append(status[status['bewerkingsstatus'].str.contains( get_user().split('@')[0])]) df['updated'] = df['updated'] + pd.DateOffset(hours=1) df = df.rename(columns={ 'updated': 'sinds', }) user_in_control = [user_title] if len(df) > 0: keys = df['key'].str.split('|', expand=True).rename(columns={ 0: 'ln_id', 1: 'bpnr', 2: 'con_opdrachtid', }) with Connection('r', 'read overview: update_user_table') as session: overview = read(session, 'projectstructure', key=df['key'].tolist()) if len(overview) > 0: overview = overview[[ 'ln_id', 'bpnr', 'con_opdrachtid', 'categorie', 'Projectstructuur constateringen', 'koppeling' ]] dataframe = keys.join(df.drop('key', axis=1)) dataframe = dataframe.merge(overview, on=['ln_id', 'bpnr', 'con_opdrachtid']) for status in ['In behandeling', 'Afgerond', 'Niet af te ronden']: temp = dataframe[dataframe['bewerkingsstatus'].str.contains( status)].drop('bewerkingsstatus', axis=1) if len(temp) > 0: user_in_control.append( html.Div(html.H4( "Status: {} [{}]".format(status, len(temp)), className="lead", ), style={ 'margin-left': '10%', 'margin-right': '10%', 'margin-top': '1%', 'margin-bottom': '1%', 'textAlign': 'center', })) user_in_control.append(html.P('')) user_in_control.append( html.Div( children=dash_table.DataTable( columns=[{ "name": i, "id": i } for i in temp.columns], data=temp.to_dict("rows"), navigation="page", sorting=True, sort_by=[ dict(column_id='sinds', direction='desc') ], filtering=True, css=[{ 'selector': '.dash-cell div.dash-cell-value', 'rule': 'display: inline; white-space: inherit; \ overflow: inherit; text-overflow: inherit;' }], style_data={'whiteSpace': 'normal'}, style_table={'overflowX': 'scroll'}, style_as_list_view=True, style_header=table_styles['header'], style_cell=table_styles['cell']['problem'], style_filter=table_styles['filter'], style_cell_conditional=table_styles['cell'] ['conditional'], ), style=styles['table_page'], )) user_in_control.append(html.Br()) control = dataframe[dataframe['bewerkingsstatus'].str.contains( 'Control')] if len(control) > 0: user_in_control.append( html.Div(html.Div( html.H4( "Status: Control [{}]".format(len(control)), className="lead", ), style={ 'margin-left': '10%', 'margin-right': '10%', 'margin-top': '2%', 'margin-bottom': '2%', }, ), style=styles['box_header'])) user_in_control.append(html.P("")) user_in_control.append( html.Div( children=dash_table.DataTable( columns=[{ "name": i, "id": i } for i in control.columns], data=control.to_dict("rows"), navigation="page", sorting=True, sort_by=[ dict(column_id='sinds', direction='desc') ], filtering=True, css=[{ 'selector': '.dash-cell div.dash-cell-value', 'rule': 'display: inline; white-space: inherit; overflow: inherit; \ text-overflow: inherit;' }], style_data={'whiteSpace': 'normal'}, style_table={'overflowX': 'scroll'}, style_as_list_view=True, style_header=table_styles['header'], style_cell=table_styles['cell']['problem'], style_filter=table_styles['filter'], style_cell_conditional=table_styles['cell'] ['conditional'], ), style=styles['table_page'], )) user_in_control.append(html.Br()) return user_in_control
def test_get_user_invalid_email(self): # email doesn't match user_email = "*****@*****.**" with self.assertRaises(BadRequest): get_user(user_email, self.session)