def on_buttonBox_accepted(self): """ Add new record """ if self.comboBox_Name.currentText() == '' \ or self.comboBox_Category.currentText() == '': return record = records.Record() record.number = self.spinBox_Number.value() record.name = unicode(self.comboBox_Name.currentText().toUtf8(),'utf8', 'ignore') record.income = self.doubleSpinBox_InCome.value() record.outcome = self.doubleSpinBox_OutCome.value() record.category = unicode(self.comboBox_Category.currentText().toUtf8(), 'utf8', 'ignore') record.date = self.dateEdit_Date.date().toPyDate() record.total = self.doubleSpinBox_Total.value() row = self.model.rowCount() self.model.insertRows(row, record) self.model.save() self.categoryModel.updateCategorys(record.category) self.update_count_result() self.reset_control_data()
def test_record_dir(self): keys, values = ['id', 'name', 'email'], [1, '', ''] record = records.Record(keys, values) _dir = dir(record) for key in keys: assert key in _dir for key in dir(object): assert key in _dir
def test_load_existent(self): db = Mock() query = Mock() query.all.return_value = [records.Record(['id'], [1])] db.query.return_value = query check_results_postgres.Postgres(db).load(2057736, [{ 'statusdesclong': 'OK', 'responsetime': 582, 'probeid': 50, 'status': 'up', 'statusdesc': 'OK', 'time': 1458376174 }, { 'statusdesclong': 'OK', 'responsetime': 1420, 'probeid': 34, 'status': 'up', 'statusdesc': 'OK', 'time': 1458376114 }]) assert 4 == db.query.call_count args = db.query.call_args_list arg1 = call( 'SELECT id FROM pingdom_check_result WHERE check_id = :check_id AND at = to_timestamp(:at) AND probe_id = :probe_id', check_id=2057736, at=1458376174, probe_id=50) arg2 = call( 'UPDATE pingdom_check_result SET check_id=:check_id, at=to_timestamp(:at), probe_id=:probe_id, status=:status, status_desc=:status_desc, status_desc_long=:status_desc_long, response_time=:response_time WHERE id=:id', check_id=2057736, at=1458376174, probe_id=50, status='up', status_desc='OK', status_desc_long='OK', response_time=582, id=1) arg3 = call( 'SELECT id FROM pingdom_check_result WHERE check_id = :check_id AND at = to_timestamp(:at) AND probe_id = :probe_id', check_id=2057736, at=1458376114, probe_id=34) arg4 = call( 'UPDATE pingdom_check_result SET check_id=:check_id, at=to_timestamp(:at), probe_id=:probe_id, status=:status, status_desc=:status_desc, status_desc_long=:status_desc_long, response_time=:response_time WHERE id=:id', check_id=2057736, at=1458376114, probe_id=34, status='up', status_desc='OK', status_desc_long='OK', response_time=1420, id=1) assert args == [arg1, arg2, arg3, arg4]
def test_load_existent(self): db = Mock() query = Mock() query.all.return_value = [records.Record(['id'], [2057736])] db.query.return_value = query checks_postgres.Postgres(db).load([{ 'hostname': 'www.a.com', 'use_legacy_notifications': True, 'lastresponsetime': 411, 'ipv6': False, 'type': 'http', 'name': 'A', 'resolution': 1, 'created': 1458372620, 'lasttesttime': 1459005934, 'status': 'up', 'id': 2057736 }, { 'lasterrortime': 1458938840, 'type': 'http', 'hostname': 'b.a.com', 'lastresponsetime': 827, 'created': 1458398619, 'lasttesttime': 1459005943, 'status': 'up', 'ipv6': False, 'use_legacy_notifications': True, 'resolution': 1, 'name': 'B', 'id': 2057910 }]) assert 4 == db.query.call_count args = db.query.call_args_list arg1 = call('SELECT id FROM pingdom_check WHERE id = :id', id=2057736) arg2 = call( 'UPDATE pingdom_check SET name=:name, created_at=to_timestamp(:created_at), status=:status, hostname=:hostname, type=:type WHERE id=:id', id=2057736, name='A', created_at=1458372620, status='up', hostname='www.a.com', type='http') arg3 = call('SELECT id FROM pingdom_check WHERE id = :id', id=2057910) arg4 = call( 'UPDATE pingdom_check SET name=:name, created_at=to_timestamp(:created_at), status=:status, hostname=:hostname, type=:type WHERE id=:id', id=2057910, name='B', created_at=1458398619, status='up', hostname='b.a.com', type='http') assert args == [arg1, arg2, arg3, arg4]
def test_record_duplicate_column(self): keys, values = ['id', 'name', 'email', 'email'], [1, '', '', ''] record = records.Record(keys, values) with raises(KeyError): record['email']