Example #1
0
def test_insert_into_stakeholders_table(db):
    db.insert_into_stakeholders_table(
        **{
            "name": "stakeholder #3",
            "role": "end-user",
            "sentiment": "😀",
            "power": "low",
            "interest": "high",
            "approach": "keep informed"
        })

    results = db.select_all_from_stakeholders_table()
    assert len(results) == 3
Example #2
0
    def show_stakeholders():
        """
        This is the endpoint for showing stakeholders.

        It accepts a `GET` request.

        It returns a status code (`200`) and records serialized as JSON.
        """

        # We open a connection to the database and create the
        # `stakeholders` table if it does not already exist.

        with stakeholders.db.Database(file=file) as db:
            db.create_stakeholders_table()

            # If it exists, then we obtain the value of the `id`
            # query parameter.

            id = flask.request.args.get("id")

            # If there is no `id`, then we select all records
            # from the `stakeholders` table.
            #
            # Otherwise, we select a single record
            # from the `stakeholders` table.

            if id is None:
                results = db.select_all_from_stakeholders_table()
            else:
                results = db.select_from_stakeholders_table(id=id)

            # We return a `200` status code and records serialized
            # as JSON.

            return (json.dumps(results), 200, {
                "Content-Type": "application/json"
            })
Example #3
0
def test_select_all_from_stakeholders_table(db):
    results = db.select_all_from_stakeholders_table()
    assert len(results) == 2
Example #4
0
def test_drop_stakeholders_table(db):
    with pytest.raises(sqlite3.OperationalError) as exception:
        db.drop_stakeholders_table()
        db.select_all_from_stakeholders_table()

    assert "no such table: stakeholders" == str(exception.value)
Example #5
0
def test_create_stakeholders_table(file):
    with stakeholders.db.Database(file=file) as db:
        db.create_stakeholders_table()
        results = db.select_all_from_stakeholders_table()

    assert len(results) == 0
Example #6
0
def test_create_stakeholders_table_error(file):
    with pytest.raises(sqlite3.OperationalError) as exception:
        with stakeholders.db.Database(file=file) as db:
            db.select_all_from_stakeholders_table()

    assert "no such table: stakeholders" == str(exception.value)
Example #7
0
def test_delete_from_stakeholders_table(db):
    db.delete_from_stakeholders_table(id="1")
    results = db.select_all_from_stakeholders_table()
    assert len(results) == 1