Beispiel #1
0
    def show_management_plan():
        # We open a connection to the database and create the
        # `stakeholders`, `deliverables`, and `associations` tables
        # if they do not already exist.

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

            # We request all records from the `associations` table.

            results = db.select_all_from_associations_table()

            # We map, reduce, and sort these records.

            mapped_reduced_sorted = stakeholders.utils.sort(
                stakeholders.utils.map_reduce(results))

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

            return (json.dumps(mapped_reduced_sorted), 200, {
                "Content-Type": "application/json"
            })
Beispiel #2
0
def test_create_associations_table(file):
    with stakeholders.db.Database(file=file) as db:
        db.create_stakeholders_table()
        db.create_deliverables_table()
        db.create_associations_table()
        results = db.select_all_from_associations_table()

    assert len(results) == 0
Beispiel #3
0
def test_create_associations_table_error(file):
    with pytest.raises(sqlite3.OperationalError) as exception:
        with stakeholders.db.Database(file=file) as db:
            db.create_stakeholders_table()
            db.create_deliverables_table()
            db.select_all_from_associations_table()

    assert "no such table: associations" == str(exception.value)
Beispiel #4
0
def db(file):
    with stakeholders.db.Database(file=file) as db:
        db.create_stakeholders_table()

        db.insert_into_stakeholders_table(**{
            "name": "stakeholder #1",
            "role": "project sponsor",
            "sentiment": "😀",
            "power": "high",
            "interest": "high",
            "approach": "monitor closely"
        })

        db.insert_into_stakeholders_table(**{
            "name": "stakeholder #2",
            "role": "customer",
            "sentiment": "😐",
            "power": "high",
            "interest": "low",
            "approach": "keep satisfied"
        })

        db.create_deliverables_table()

        db.insert_into_deliverables_table(**{
            "name": "deliverable #1",
            "kind": "interactive",
            "medium": "in-person meeting",
            "formality": "formal",
            "frequency": "daily"
        })

        db.insert_into_deliverables_table(**{
            "name": "deliverable #2",
            "kind": "push",
            "medium": "video/teleconference",
            "formality": "casual",
            "frequency": "weekly"
        })

        db.create_associations_table()

        db.insert_into_associations_table(**{
            "stakeholder_id": 1,
            "deliverable_id": 1
        })

        db.insert_into_associations_table(**{
            "stakeholder_id": 2,
            "deliverable_id": 2
        })
     
        yield db
Beispiel #5
0
    def delete_deliverable():
        """
        This is the endpoint for deleting a deliverable.

        It accepts a `POST` request.

        It returns a status code (`200`) and a message (`Success`).
        """

        # We open a connection to the database and create the
        # `deliverables` table if it does not already exist.
        #
        # We delete a record from the `deliverables` table.

        with stakeholders.db.Database(file=file) as db:
            db.create_deliverables_table()
            db.delete_from_deliverables_table(**flask.request.form.to_dict())

            # We return a `200` status code and a `Success` message.

            return ("Success", 200)
Beispiel #6
0
    def show_associations():
        """
        This is the endpoint for showing associations.

        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`, `deliverables`, and `associations` tables
        # if they do not already exist.

        with stakeholders.db.Database(file=file) as db:
            db.create_stakeholders_table()
            db.create_deliverables_table()
            db.create_associations_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 `associations` table.
            #
            # Otherwise, we select a single record
            # from the `associations` table.

            if id is None:
                results = db.select_all_from_associations_table()
            else:
                results = db.select_from_associations_table(id=id)

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

            return (json.dumps(results), 200, {
                "Content-Type": "application/json"
            })
Beispiel #7
0
    def update_association():
        """
        This is the endpoint for updating an association.

        It accepts a `POST` request.

        It returns a status code (`200`) and a message (`Success`).
        """

        # We open a connection to the database and create the
        # `stakeholders`, `deliverables`, and `associations` tables
        # if they do not already exist.
        #
        # We update a record in the `associations` table.

        with stakeholders.db.Database(file=file) as db:
            db.create_stakeholders_table()
            db.create_deliverables_table()
            db.create_associations_table()
            db.update_associations_table(**flask.request.form.to_dict())

            # We return a `200` status code and a `Success` message.

            return ("Success", 200)