diff --git a/test/test_api_usage.py b/test/test_api_usage.py
index 791c2139f..071630bd9 100644
--- a/test/test_api_usage.py
+++ b/test/test_api_usage.py
@@ -1375,7 +1375,8 @@ class TestRepositoryBuildResource(ApiTestCase):
     self.assertEquals(uuid, json['builds'][0]['id'])
 
     # Set queue item to be picked up.
-    qi = database.QueueItem.get(id=1)
+    build_ref = database.RepositoryBuild.get(uuid=uuid)
+    qi = database.QueueItem.get(id=build_ref.queue_id)
     qi.available = False
     qi.save()