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)
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" })
def test_insert_into_associations_table(db): db.insert_into_associations_table(**{ "stakeholder_id": 1, "deliverable_id": 2 }) results = db.select_all_from_associations_table() assert len(results) == 3
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
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" })
def test_delete_from_associations_table(db): db.delete_from_associations_table(id="1") results = db.select_all_from_associations_table() assert len(results) == 1
def test_select_all_from_associations_table(db): results = db.select_all_from_associations_table() assert len(results) == 2
def test_drop_associations_table(db): with pytest.raises(sqlite3.OperationalError) as exception: db.drop_associations_table() db.select_all_from_associations_table() assert "no such table: associations" == str(exception.value)