コード例 #1
0
def test_update_by_imei(client, app):
    assert client.get(
        '/shipment-info/imei/358711099663452/update').status_code == 200
    assert client.get('/shipment-info/imei/1/update').status_code == 404

    client.post('/shipment-info/imei/358711099663452/update',
                data={
                    'delivery_status': 'D',
                    'is_received': 'received'
                })
    with app.app_context():
        db = get_db_raw()
        shipment = db.execute(
            'SELECT DeliveryStatus, IsReceived'
            ' FROM ATT_ShipmentDetailReport'
            ' WHERE IMEI = ?', '358711099663452').fetchone()
        assert shipment[0] == 'D'
        assert shipment[1]

    client.post('/shipment-info/imei/358711099663452/update',
                data={
                    'delivery_status': '',
                    'is_received': 'received'
                })
    with app.app_context():
        db = get_db_raw()
        shipment = db.execute(
            'SELECT DeliveryStatus, IsReceived'
            ' FROM ATT_ShipmentDetailReport'
            ' WHERE IMEI = ?', '358711099663452').fetchone()
        assert not shipment[0]
        assert shipment[1]

    client.post('/shipment-info/imei/358711099663452/update',
                data={'delivery_status': ''})
    with app.app_context():
        db = get_db_raw()
        shipment = db.execute(
            'SELECT DeliveryStatus, IsReceived'
            ' FROM ATT_ShipmentDetailReport'
            ' WHERE IMEI = ?', '358711099663452').fetchone()
        assert not shipment[0]
        assert not shipment[1]

    client.post('/shipment-info/imei/358711099663452/update',
                data={'delivery_status': 'D'})
    with app.app_context():
        db = get_db_raw()
        shipment = db.execute(
            'SELECT DeliveryStatus, IsReceived'
            ' FROM ATT_ShipmentDetailReport'
            ' WHERE IMEI = ?', '358711099663452').fetchone()
        assert shipment[0] == 'D'
        assert not shipment[1]
コード例 #2
0
ファイル: shipment_info.py プロジェクト: carloandaya/mwhqweb
def update_by_tracking_number(id):
    shipments = get_shipment_by_tracking_number(id)

    if request.method == 'POST':
        delivery_status = request.form['delivery_status']

        if not delivery_status:
            delivery_status = None

        if 'is_received' in request.form:
            is_received = True
        else:
            is_received = False

        db = get_db_raw()
        db.execute(
            'UPDATE ATT_ShipmentDetailReport'
            ' SET DeliveryStatus = ?, IsReceived = ?'
            ' WHERE TrackingNumber = ?', (delivery_status, is_received, id))
        db.commit()

        if 'shipment_referrer' in session:
            return redirect(url_for(session['shipment_referrer']))
        else:
            return redirect(url_for('shipment_info.index'))

    return render_template('shipment_info/update_by_tracking_number.html',
                           shipments=shipments)
コード例 #3
0
ファイル: shipment_info.py プロジェクト: carloandaya/mwhqweb
def get_delivered_not_received():
    shipments = get_db_raw().execute(
        'SELECT PONumber, ActualShipDate, ItemNumber, ItemDescription,'
        ' ExtdPrice, QuantityShipped, IMEI, TrackingNumber'
        ' FROM ATT_ShipmentDetailReport'
        ' WHERE DeliveryStatus = ? AND IsReceived = ?', ('D', 0)).fetchall()
    return shipments
コード例 #4
0
ファイル: shipment_info.py プロジェクト: carloandaya/mwhqweb
def shipped_not_received():
    db = get_db_raw()
    shipments = db.execute(
        'SELECT PONumber, ActualShipDate, ItemNumber, ItemDescription,'
        ' ExtdPrice, QuantityShipped, IMEI, TrackingNumber'
        ' FROM ATT_ShipmentDetailReport'
        ' WHERE IsReceived = ?', 0).fetchall()
    return render_template('shipment_info/shipped_not_received.html',
                           shipments=shipments)
コード例 #5
0
def test_get_close_db(app):
    with app.app_context():
        db = get_db()
        assert db is get_db()

    with pytest.raises(pyodbc.ProgrammingError) as e:
        db.execute('SELECT 1')

    assert 'closed' in str(e.value)

    with app.app_context():
        db_raw = get_db_raw()
        assert db_raw is get_db_raw()

    with pytest.raises(pyodbc.ProgrammingError) as e:
        db_raw.execute('SELECT 1')

    assert 'closed' in str(e.value)
コード例 #6
0
ファイル: shipment_info.py プロジェクト: carloandaya/mwhqweb
def shipped_not_delivered():
    db = get_db_raw()
    shipments = db.execute(
        'SELECT PONumber, ActualShipDate, ItemNumber, ItemDescription,'
        ' ExtdPrice, QuantityShipped, IMEI, TrackingNumber'
        ' FROM ATT_ShipmentDetailReport'
        ' WHERE DeliveryStatus != ? OR DeliveryStatus IS NULL',
        'D').fetchall()
    session['shipment_referrer'] = 'shipment_info.shipped_not_delivered'
    return render_template('shipment_info/shipped_not_delivered.html',
                           shipments=shipments)
コード例 #7
0
ファイル: shipment_info.py プロジェクト: carloandaya/mwhqweb
def get_shipment(id):
    shipment = get_db_raw().execute(
        'SELECT IMEI, '
        'DeliveryStatus, '
        'IsReceived '
        'FROM ATT_ShipmentDetailReport '
        'WHERE IMEI = ?', id).fetchone()

    if shipment is None:
        abort(404, "Shipment with IMEI {0} doesn't exist.".format(id))

    return shipment
コード例 #8
0
ファイル: shipment_info.py プロジェクト: carloandaya/mwhqweb
def get_shipment_by_tracking_number(id):
    shipments = get_db_raw().execute(
        'SELECT IMEI, '
        'TrackingNumber, '
        'DeliveryStatus, '
        'IsReceived '
        'FROM ATT_ShipmentDetailReport '
        'WHERE TrackingNumber = ?', id).fetchall()

    if shipments is None:
        abort(404,
              "Shipments with Tracking Number {0} doesn't exist.".format(id))

    return shipments
コード例 #9
0
def test_shipped_not_received(client, app):
    response = client.get('/shipment-info/shipped-not-received')
    assert b'Shipped Not Received' in response.data
    assert b'358711099663452' in response.data
    assert b'354834099171450' in response.data
    assert b'356172099533090' in response.data
    assert b'353094104750878' in response.data

    with app.app_context():
        db = get_db_raw()
        count = db.execute(
            'SELECT COUNT(IMEI)'
            ' FROM ATT_ShipmentDetailReport'
            ' WHERE IsReceived = ?', 0).fetchone()[0]
        assert count == 4
コード例 #10
0
ファイル: shipment_info.py プロジェクト: carloandaya/mwhqweb
def corrections_delivered_not_received():
    form = CorrectionSubmission()

    if form.validate_on_submit():
        corrections = form.items.data.splitlines()
        corrections = [i.strip() for i in corrections if i]
        placeholders = ",".join("?" * len(corrections))
        sql = 'UPDATE ATT_ShipmentDetailReport SET IsReceived = 1 WHERE IMEI IN ({})'.format(
            placeholders)
        db = get_db_raw()
        result = db.execute(sql, corrections)
        db.commit()
        flash("{} row(s) affected.".format(result.rowcount))
        return redirect(url_for('shipment_info.delivered_not_received'))

    return render_template(
        'shipment_info/correction_delivered_not_received.html', form=form)
コード例 #11
0
ファイル: conftest.py プロジェクト: carloandaya/mwhqweb
def app():
    app = create_app({
        'TESTING': True,
        'DW_DATABASE':
        'DRIVER={SQL Server};SERVER=localhost;DATABASE=Test_MyWirelessDW;Trusted_Connection=yes',
        'RAW_DATABASE':
        'DRIVER={SQL Server};SERVER=localhost;DATABASE=Test_MyWirelessRawData;Trusted_Connection=yes',
        'WTF_CSRF_ENABLED': False,
        'LOGIN_DISABLED': True,
    })

    with app.app_context():
        init_db()
        db = get_db()
        db.execute(_data_sql)
        db.commit()
        db_raw = get_db_raw()
        db_raw.execute(_data_raw_sql)
        db_raw.commit()

    yield app