Skip to content

Commit

Permalink
Merge ef65fae into a9cd923
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Apr 26, 2021
2 parents a9cd923 + ef65fae commit 57cd174
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 227 deletions.
13 changes: 11 additions & 2 deletions conbench/api/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def get(self):
name: sha
schema:
type: string
- in: query
name: context_id
schema:
type: string
- in: query
name: machine_id
schema:
Expand All @@ -60,10 +64,15 @@ def get(self):
- Runs
"""
sha = f.request.args.get("sha")
context_id = f.request.args.get("context_id")
machine_id = f.request.args.get("machine_id")
if sha and machine_id:
if sha and context_id and machine_id:
runs = Run.search(
filters=[Run.machine_id == machine_id, Commit.sha == sha],
filters=[
Run.context_id == context_id,
Run.machine_id == machine_id,
Commit.sha == sha,
],
joins=[Commit],
)
else:
Expand Down
4 changes: 2 additions & 2 deletions conbench/entities/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Run(Base, EntityMixin):
timestamp = NotNull(s.DateTime(timezone=False), server_default=s.sql.func.now())
commit_id = NotNull(s.String(50), s.ForeignKey("commit.id"))
commit = relationship("Commit", lazy="joined")
context_id = Nullable(s.String(50), s.ForeignKey("context.id"))
context_id = NotNull(s.String(50), s.ForeignKey("context.id"))
context = relationship("Context", lazy="joined")
machine_id = NotNull(s.String(50), s.ForeignKey("machine.id"))
machine = relationship("Machine", lazy="joined")
Expand All @@ -24,7 +24,7 @@ class Run(Base, EntityMixin):
class _Serializer(EntitySerializer):
def _dump(self, run):
commit = CommitSerializer().one.dump(run.commit)
context = ContextSerializer().one.dump(run.context) if run.context else {}
context = ContextSerializer().one.dump(run.context)
machine = MachineSerializer().one.dump(run.machine)
commit.pop("links", None)
context.pop("links", None)
Expand Down
1 change: 1 addition & 0 deletions conbench/tests/api/_expected_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@
"description": "Get a list of runs.",
"parameters": [
{"in": "query", "name": "sha", "schema": {"type": "string"}},
{"in": "query", "name": "context_id", "schema": {"type": "string"}},
{"in": "query", "name": "machine_id", "schema": {"type": "string"}},
],
"responses": {
Expand Down
18 changes: 13 additions & 5 deletions conbench/tests/api/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ def test_run_list(self, client):
response = client.get("/api/runs/")
self.assert_200_ok(response, contains=_expected_entity(run))

def test_run_list_filter_by_sha_and_machine(self, client):
def test_run_list_filter_by_run_keys(self, client):
sha = "02addad336ba19a654f9c857ede546331be7b631"
self.authenticate(client)
run = self._create()
args = {"sha": sha, "machine_id": run.machine_id}
args = {
"sha": sha,
"machine_id": run.machine_id,
"context_id": run.context_id,
}
args = urllib.parse.urlencode(args)
response = client.get(f"/api/runs/?{args}")
self.assert_200_ok(response, contains=_expected_entity(run))

def test_run_list_filter_by_sha_and_machine_no_match(self, client):
def test_run_list_filter_by_run_keys_no_match(self, client):
sha = "02addad336ba19a654f9c857ede546331be7b631"
self.authenticate(client)
self._create()
args = {"sha": sha, "machine_id": "some other machine id"}
run = self._create()
args = {
"sha": sha,
"machine_id": "some other machine id",
"context_id": run.context_id,
}
args = urllib.parse.urlencode(args)
response = client.get(f"/api/runs/?{args}")
self.assert_200_ok(response, [])
206 changes: 0 additions & 206 deletions conbench/tests/migrations/test_de31ab708b6c_backfill_context.py

This file was deleted.

28 changes: 28 additions & 0 deletions migrations/versions/4e5ee23705ca_context_id_not_null.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""context id not null
Revision ID: 4e5ee23705ca
Revises: de31ab708b6c
Create Date: 2021-04-26 14:23:28.001461
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "4e5ee23705ca"
down_revision = "de31ab708b6c"
branch_labels = None
depends_on = None


def upgrade():
op.alter_column(
"run", "context_id", existing_type=sa.VARCHAR(length=50), nullable=False
)


def downgrade():
op.alter_column(
"run", "context_id", existing_type=sa.VARCHAR(length=50), nullable=True
)
4 changes: 0 additions & 4 deletions migrations/versions/52b6915e289a_run_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("run", sa.Column("context_id", sa.String(length=50), nullable=True))
op.create_foreign_key(None, "run", "context", ["context_id"], ["id"])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "run", type_="foreignkey")
op.drop_column("run", "context_id")
# ### end Alembic commands ###
4 changes: 0 additions & 4 deletions migrations/versions/782f4533db71_add_parent_drop_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("commit", sa.Column("parent", sa.String(length=50), nullable=True))
op.drop_column("commit", "url")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"commit",
sa.Column("url", sa.VARCHAR(length=250), autoincrement=False, nullable=False),
)
op.drop_column("commit", "parent")
# ### end Alembic commands ###
4 changes: 0 additions & 4 deletions migrations/versions/991493b6406a_initial_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"case",
sa.Column("id", sa.String(length=50), nullable=False),
Expand Down Expand Up @@ -175,11 +174,9 @@ def upgrade():
sa.PrimaryKeyConstraint("id"),
)
op.create_index("time_summary_id_index", "time", ["summary_id"], unique=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("time_summary_id_index", table_name="time")
op.drop_table("time")
op.drop_index("data_summary_id_index", table_name="data")
Expand All @@ -198,4 +195,3 @@ def downgrade():
op.drop_table("commit")
op.drop_index("case_index", table_name="case")
op.drop_table("case")
# ### end Alembic commands ###

0 comments on commit 57cd174

Please sign in to comment.