Commit 2b43d96b authored by Carlos Natalino's avatar Carlos Natalino
Browse files

Advancing on the device workflow and improving tests.

parent 3aa1e063
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ flask
flask-wtf
flask-healthz
grpcio
grpcio-health-checking
prometheus-client
pytest
pytest-benchmark
+24 −2
Original line number Diff line number Diff line
@@ -78,9 +78,8 @@ def add():
            client.close()

            flash(f'New device was created with ID "{response.device_uuid.uuid}".', 'success')
            redirect('/device/')
            return redirect('/device/')
        except Exception as e:
            print(e)
            flash(f'Problem adding the device. {e.details()}', 'danger')
        
    return render_template('device/add.html', form=form,
@@ -95,3 +94,26 @@ def detail(device_uuid: str):
    response: Device = client.GetDevice(request)
    client.close()
    return render_template('device/detail.html', device=response)

@device.get('<device_uuid>/delete')
def delete(device_uuid):
    try:
        client: DeviceClient = DeviceClient(DEVICE_SERVICE_ADDRESS, DEVICE_SERVICE_PORT)

        # first, check if device exists!
        # request: DeviceId = DeviceId()
        # request.device_uuid.uuid = device_uuid
        # response: Device = client.GetDevice(request)
        # TODO: finalize implementation

        request: DeviceId = DeviceId()
        request.device_uuid.uuid = device_uuid
        response = client.DeleteDevice(request)

        client.close()

        flash('Device deleted successfully!', 'success')
    except Exception as e:
        flash(f'Problem deleting the device. {e.details()}', 'danger')

    return redirect('/device/')
+33 −1
Original line number Diff line number Diff line
@@ -3,6 +3,21 @@
{% block content %}
    <h1>Device {{ device.device_id.device_uuid.uuid }}</h1>

    <div class="row mb-3">
        <div class="col-sm-3">
            <button type="button" class="btn btn-success" onclick="window.location.href = '/device/'"><i class="bi bi-box-arrow-in-left"></i>Back to device list</button>
        </div>
        <div class="col-sm-3">
            <a id="update" class="btn btn-secondary" href="#"><i class="bi bi-pencil-square"></i>Update</a>
        </div>
        <div class="col-sm-3">
            <!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete device</button> -->
            <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
                <i class="bi bi-x-square"></i>Delete device
              </button>
        </div>
    </div>

    <div class="row mb-3">
        <b>UUID:</b>
        <div class="col-sm-10">
@@ -36,6 +51,23 @@
        </div>
    </div>

    <div class="row mb-3"><button type="button" class="btn btn-success" onclick="window.location.href = '/device/'"><i class="bi bi-box-arrow-in-left"></i>Back to device list</button></div>
    <!-- Modal -->
<div class="modal fade" id="deleteModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="staticBackdropLabel">Delete device?</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          Are you sure you want to delete the device "{{ device.device_id.device_uuid.uuid }}"?
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button>
          <a type="button" class="btn btn-danger" href="{{ url_for('device.delete', device_uuid=device.device_id.device_uuid.uuid) }}"><i class="bi bi-exclamation-diamond"></i>Yes</a>
        </div>
      </div>
    </div>
  </div>

{% endblock %}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -96,3 +96,9 @@ def test_device_add_action(client):
    }
    rw = client.post('/device/add', data=DEVICE_EMU, follow_redirects=True)
    assert b'success' in rw.data

def test_device_delete_action(client):
    with client.session_transaction() as sess:
        sess['context_uuid'] = 'admin'
    rw = client.get('/device/EMULATED/delete', follow_redirects=True)
    assert b'success' in rw.data