launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29129
[Merge] ~ilasc/launchpad:call-download-api-without-file-id into launchpad:master
Ioana Lasc has proposed merging ~ilasc/launchpad:call-download-api-without-file-id into launchpad:master.
Commit message:
Call new Loggerhead download API without file-id
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~ilasc/launchpad/+git/launchpad/+merge/429433
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:call-download-api-without-file-id into launchpad:master.
diff --git a/lib/lp/code/errors.py b/lib/lp/code/errors.py
index 2fa4a47..8e3efcd 100644
--- a/lib/lp/code/errors.py
+++ b/lib/lp/code/errors.py
@@ -365,15 +365,15 @@ class BranchHostingFault(Exception):
class BranchFileNotFound(BranchHostingFault):
"""Raised when a file does not exist in a branch."""
- def __init__(self, branch_id, filename=None, file_id=None, rev=None):
+ def __init__(self, branch_id, filename=None, path=None, rev=None):
super().__init__()
- if (filename is None) == (file_id is None):
+ if (filename is None) == (path is None):
raise AssertionError(
- "Exactly one of filename and file_id must be given."
+ "Exactly one of filename and path must be given."
)
self.branch_id = branch_id
self.filename = filename
- self.file_id = file_id
+ self.path = path
self.rev = rev
def __str__(self):
@@ -381,7 +381,7 @@ class BranchFileNotFound(BranchHostingFault):
if self.filename is not None:
message += self.filename
else:
- message += "with ID %s" % self.file_id
+ message += "with path %s" % self.path
if self.rev is not None:
message += " at revision %s" % self.rev
return message
diff --git a/lib/lp/code/interfaces/branchhosting.py b/lib/lp/code/interfaces/branchhosting.py
index e93096a..adb1d5c 100644
--- a/lib/lp/code/interfaces/branchhosting.py
+++ b/lib/lp/code/interfaces/branchhosting.py
@@ -28,27 +28,11 @@ class IBranchHostingClient(Interface):
:return: The diff between `old` and `new` as a byte string.
"""
- def getInventory(branch_id, dirname, rev=None, logger=None):
- """Get information on files in a directory.
-
- :param branch_id: The ID of the branch.
- :param dirname: The name of the directory, relative to the root of
- the branch.
- :param rev: An optional revno or revision ID. Defaults to 'head:'.
- :param logger: An optional logger.
- :raises ValueError: if `rev` is ill-formed.
- :raises BranchFileNotFound: if the directory does not exist.
- :raises BranchHostingFault: if the API returned some other error.
- :return: The directory inventory as a dict: see
- `loggerhead.controllers.inventory_ui` for details.
- """
-
- def getBlob(branch_id, file_id, rev=None, logger=None):
+ def getBlob(branch_id, path, rev=None, logger=None):
"""Get a blob by file name from a branch.
:param branch_id: The ID of the branch.
- :param file_id: The file ID of the file. (`getInventory` may be
- useful to retrieve this.)
+ :param path: The realtive path of the file.
:param rev: An optional revno or revision ID. Defaults to 'head:'.
:param logger: An optional logger.
:raises ValueError: if `rev` is ill-formed.
diff --git a/lib/lp/code/model/branch.py b/lib/lp/code/model/branch.py
index 43ed1b0..63d1b13 100644
--- a/lib/lp/code/model/branch.py
+++ b/lib/lp/code/model/branch.py
@@ -8,13 +8,10 @@ __all__ = [
]
import operator
-import os.path
from datetime import datetime
from functools import partial
-from urllib.parse import urlsplit
import pytz
-import six
from breezy import urlutils
from breezy.revision import NULL_REVISION
from breezy.url_policy_open import open_only_scheme
@@ -66,7 +63,6 @@ from lp.code.enums import (
)
from lp.code.errors import (
AlreadyLatestFormat,
- BranchFileNotFound,
BranchMergeProposalExists,
BranchTargetError,
BranchTypeError,
@@ -142,12 +138,10 @@ from lp.services.database.interfaces import IMasterStore, IStore
from lp.services.database.sqlbase import SQLBase, sqlvalues
from lp.services.database.sqlobject import ForeignKey, IntCol, StringCol
from lp.services.database.stormexpr import Array, ArrayAgg, ArrayIntersects
-from lp.services.features import getFeatureFlag
from lp.services.helpers import shortlist
from lp.services.job.interfaces.job import JobStatus
from lp.services.job.model.job import Job
from lp.services.mail.notificationrecipientset import NotificationRecipientSet
-from lp.services.memcache.interfaces import IMemcacheClient
from lp.services.propertycache import cachedproperty, get_property_cache
from lp.services.webapp import urlappend
from lp.services.webapp.authorization import check_permission
@@ -899,64 +893,9 @@ class Branch(SQLBase, WebhookTargetMixin, BzrIdentityMixin):
):
"""See `IBranch`."""
hosting_client = getUtility(IBranchHostingClient)
- if enable_memcache is None:
- enable_memcache = not getFeatureFlag(
- "code.bzr.blob.disable_memcache"
- )
if revision_id is None:
revision_id = self.last_scanned_id
- if revision_id is None:
- # revision_id may still be None if the branch scanner hasn't
- # scanned this branch yet. In this case, we won't be able to
- # guarantee that subsequent calls to this method within the same
- # transaction with revision_id=None will see the same revision,
- # and we won't be able to cache file lists. Neither is fatal,
- # and this should be relatively rare.
- enable_memcache = False
- dirname = os.path.dirname(filename)
- unset = object()
- file_list = unset
- if enable_memcache:
- memcache_client = getUtility(IMemcacheClient)
- instance_name = urlsplit(
- config.codehosting.internal_bzr_api_endpoint
- ).hostname
- memcache_key = six.ensure_binary(
- "%s:bzr-file-list:%s:%s:%s"
- % (instance_name, self.id, revision_id, dirname)
- )
- description = "file list for %s:%s:%s" % (
- self.unique_name,
- revision_id,
- dirname,
- )
- file_list = memcache_client.get_json(
- memcache_key, logger, description, default=unset
- )
-
- if file_list is unset:
- try:
- inventory = hosting_client.getInventory(
- self.id, dirname, rev=revision_id
- )
- file_list = {
- entry["filename"]: entry["file_id"]
- for entry in inventory["filelist"]
- }
- except BranchFileNotFound:
- file_list = None
- if enable_memcache:
- # Cache the file list in case there's a request for another
- # file in the same directory.
- memcache_client.set_json(
- memcache_key, file_list, logger=logger
- )
- file_id = (file_list or {}).get(os.path.basename(filename))
- if file_id is None:
- raise BranchFileNotFound(
- self.unique_name, filename=filename, rev=revision_id
- )
- return hosting_client.getBlob(self.id, file_id, rev=revision_id)
+ return hosting_client.getBlob(self.id, filename, rev=revision_id)
def getDiff(self, new, old=None):
"""See `IBranch`."""
diff --git a/lib/lp/code/model/branchhosting.py b/lib/lp/code/model/branchhosting.py
index 8b5abb4..1324d87 100644
--- a/lib/lp/code/model/branchhosting.py
+++ b/lib/lp/code/model/branchhosting.py
@@ -128,43 +128,18 @@ class BranchHostingClient:
"Failed to get diff from Bazaar branch: %s" % e
)
- def getInventory(self, branch_id, dirname, rev=None, logger=None):
+ def getBlob(self, branch_id, path, rev=None, logger=None):
"""See `IBranchHostingClient`."""
self._checkRevision(rev)
try:
if logger is not None:
logger.info(
- "Requesting inventory at %s from branch %s"
- % (dirname, branch_id)
- )
- quoted_tail = "files/%s/%s" % (
- quote(rev or "head:", safe=""),
- quote(dirname.lstrip("/")),
- )
- return self._get(branch_id, quoted_tail, as_json=True)
- except requests.RequestException as e:
- if (
- e.response is not None
- and e.response.status_code == requests.codes.NOT_FOUND
- ):
- raise BranchFileNotFound(branch_id, filename=dirname, rev=rev)
- else:
- raise BranchHostingFault(
- "Failed to get inventory from Bazaar branch: %s" % e
- )
-
- def getBlob(self, branch_id, file_id, rev=None, logger=None):
- """See `IBranchHostingClient`."""
- self._checkRevision(rev)
- try:
- if logger is not None:
- logger.info(
- "Fetching file ID %s from branch %s" % (file_id, branch_id)
+ "Fetching file ID %s from branch %s" % (path, branch_id)
)
return self._get(
branch_id,
"download/%s/%s"
- % (quote(rev or "head:", safe=""), quote(file_id, safe="")),
+ % (quote(rev or "head:", safe=""), quote(path, safe="")),
as_json=False,
)
except requests.RequestException as e:
@@ -172,7 +147,7 @@ class BranchHostingClient:
e.response is not None
and e.response.status_code == requests.codes.NOT_FOUND
):
- raise BranchFileNotFound(branch_id, file_id=file_id, rev=rev)
+ raise BranchFileNotFound(branch_id, path=path, rev=rev)
else:
raise BranchHostingFault(
"Failed to get file from Bazaar branch: %s" % e
diff --git a/lib/lp/code/model/tests/test_branch.py b/lib/lp/code/model/tests/test_branch.py
index 5f037c4..d78c340 100644
--- a/lib/lp/code/model/tests/test_branch.py
+++ b/lib/lp/code/model/tests/test_branch.py
@@ -3,7 +3,6 @@
"""Tests for Branches."""
-import json
from datetime import datetime, timedelta
import transaction
@@ -117,7 +116,6 @@ from lp.services.features.testing import FeatureFixture
from lp.services.job.interfaces.job import JobStatus
from lp.services.job.runner import JobRunner
from lp.services.job.tests import block_on_job, monitor_celery
-from lp.services.memcache.interfaces import IMemcacheClient
from lp.services.osutils import override_environ
from lp.services.propertycache import clear_property_cache
from lp.services.webapp.authorization import check_permission
@@ -3686,157 +3684,39 @@ class TestBranchGetBlob(TestCaseWithFactory):
def test_default_rev_unscanned(self):
branch = self.factory.makeBranch()
- hosting_fixture = self.useFixture(
- BranchHostingFixture(
- file_list={"README.txt": "some-file-id"}, blob=b"Some text"
- )
- )
+ self.useFixture(BranchHostingFixture(blob=b"Some text"))
blob = branch.getBlob("src/README.txt")
self.assertEqual(b"Some text", blob)
- self.assertEqual(
- [((branch.id, "src"), {"rev": None})],
- hosting_fixture.getInventory.calls,
- )
- self.assertEqual(
- [((branch.id, "some-file-id"), {"rev": None})],
- hosting_fixture.getBlob.calls,
- )
- self.assertEqual({}, getUtility(IMemcacheClient)._cache)
def test_default_rev_scanned(self):
branch = self.factory.makeBranch()
removeSecurityProxy(branch).last_scanned_id = "scanned-id"
- hosting_fixture = self.useFixture(
- BranchHostingFixture(
- file_list={"README.txt": "some-file-id"}, blob=b"Some text"
- )
- )
+ self.useFixture(BranchHostingFixture(blob=b"Some text"))
blob = branch.getBlob("src/README.txt")
self.assertEqual(b"Some text", blob)
- self.assertEqual(
- [((branch.id, "src"), {"rev": "scanned-id"})],
- hosting_fixture.getInventory.calls,
- )
- self.assertEqual(
- [((branch.id, "some-file-id"), {"rev": "scanned-id"})],
- hosting_fixture.getBlob.calls,
- )
- key = (
- "bazaar.launchpad.test:bzr-file-list:%s:scanned-id:src" % branch.id
- )
- self.assertEqual(
- json.dumps({"README.txt": "some-file-id"}),
- getUtility(IMemcacheClient).get(key.encode("UTF-8")),
- )
def test_with_rev(self):
branch = self.factory.makeBranch()
- hosting_fixture = self.useFixture(
- BranchHostingFixture(
- file_list={"README.txt": "some-file-id"}, blob=b"Some text"
- )
- )
- blob = branch.getBlob("src/README.txt", revision_id="some-rev")
- self.assertEqual(b"Some text", blob)
- self.assertEqual(
- [((branch.id, "src"), {"rev": "some-rev"})],
- hosting_fixture.getInventory.calls,
- )
- self.assertEqual(
- [((branch.id, "some-file-id"), {"rev": "some-rev"})],
- hosting_fixture.getBlob.calls,
- )
- key = "bazaar.launchpad.test:bzr-file-list:%s:some-rev:src" % branch.id
- self.assertEqual(
- json.dumps({"README.txt": "some-file-id"}),
- getUtility(IMemcacheClient).get(key.encode("UTF-8")),
- )
-
- def test_cached_inventory(self):
- branch = self.factory.makeBranch()
- hosting_fixture = self.useFixture(
- BranchHostingFixture(blob=b"Some text")
- )
- key = "bazaar.launchpad.test:bzr-file-list:%s:some-rev:src" % branch.id
- getUtility(IMemcacheClient).set(
- key.encode("UTF-8"), json.dumps({"README.txt": "some-file-id"})
- )
- blob = branch.getBlob("src/README.txt", revision_id="some-rev")
- self.assertEqual(b"Some text", blob)
- self.assertEqual([], hosting_fixture.getInventory.calls)
- self.assertEqual(
- [((branch.id, "some-file-id"), {"rev": "some-rev"})],
- hosting_fixture.getBlob.calls,
- )
-
- def test_disable_memcache(self):
- self.useFixture(
- FeatureFixture({"code.bzr.blob.disable_memcache": "on"})
- )
- branch = self.factory.makeBranch()
- hosting_fixture = self.useFixture(
- BranchHostingFixture(
- file_list={"README.txt": "some-file-id"}, blob=b"Some text"
- )
- )
- key = "bazaar.launchpad.test:bzr-file-list:%s:some-rev:src" % branch.id
- getUtility(IMemcacheClient).set(key.encode("UTF-8"), "{}")
+ self.useFixture(BranchHostingFixture(blob=b"Some text"))
blob = branch.getBlob("src/README.txt", revision_id="some-rev")
self.assertEqual(b"Some text", blob)
- self.assertEqual(
- [((branch.id, "src"), {"rev": "some-rev"})],
- hosting_fixture.getInventory.calls,
- )
- self.assertEqual(
- "{}", getUtility(IMemcacheClient).get(key.encode("UTF-8"))
- )
def test_file_at_root_of_branch(self):
branch = self.factory.makeBranch()
hosting_fixture = self.useFixture(
- BranchHostingFixture(
- file_list={"README.txt": "some-file-id"}, blob=b"Some text"
- )
+ BranchHostingFixture(blob=b"Some text")
)
blob = branch.getBlob("README.txt", revision_id="some-rev")
self.assertEqual(b"Some text", blob)
self.assertEqual(
- [((branch.id, ""), {"rev": "some-rev"})],
- hosting_fixture.getInventory.calls,
- )
- self.assertEqual(
- [((branch.id, "some-file-id"), {"rev": "some-rev"})],
+ [((branch.id, "README.txt"), {"rev": "some-rev"})],
hosting_fixture.getBlob.calls,
)
- key = "bazaar.launchpad.test:bzr-file-list:%s:some-rev:" % branch.id
- self.assertEqual(
- json.dumps({"README.txt": "some-file-id"}),
- getUtility(IMemcacheClient).get(key.encode("UTF-8")),
- )
-
- def test_file_not_in_directory(self):
- branch = self.factory.makeBranch()
- hosting_fixture = self.useFixture(BranchHostingFixture(file_list={}))
- self.assertRaises(
- BranchFileNotFound,
- branch.getBlob,
- "src/README.txt",
- revision_id="some-rev",
- )
- self.assertEqual(
- [((branch.id, "src"), {"rev": "some-rev"})],
- hosting_fixture.getInventory.calls,
- )
- self.assertEqual([], hosting_fixture.getBlob.calls)
- key = "bazaar.launchpad.test:bzr-file-list:%s:some-rev:src" % branch.id
- self.assertEqual(
- "{}", getUtility(IMemcacheClient).get(key.encode("UTF-8"))
- )
def test_missing_directory(self):
branch = self.factory.makeBranch()
hosting_fixture = self.useFixture(BranchHostingFixture())
- hosting_fixture.getInventory = FakeMethod(
+ hosting_fixture.getBlob = FakeMethod(
failure=BranchFileNotFound(
branch.unique_name, filename="src", rev="some-rev"
)
@@ -3847,29 +3727,6 @@ class TestBranchGetBlob(TestCaseWithFactory):
"src/README.txt",
revision_id="some-rev",
)
- self.assertEqual(
- [((branch.id, "src"), {"rev": "some-rev"})],
- hosting_fixture.getInventory.calls,
- )
- self.assertEqual([], hosting_fixture.getBlob.calls)
- key = "bazaar.launchpad.test:bzr-file-list:%s:some-rev:src" % branch.id
- self.assertEqual(
- "null", getUtility(IMemcacheClient).get(key.encode("UTF-8"))
- )
-
- def test_cached_missing_directory(self):
- branch = self.factory.makeBranch()
- hosting_fixture = self.useFixture(BranchHostingFixture())
- key = "bazaar.launchpad.test:bzr-file-list:%s:some-rev:src" % branch.id
- getUtility(IMemcacheClient).set(key.encode("UTF-8"), "null")
- self.assertRaises(
- BranchFileNotFound,
- branch.getBlob,
- "src/README.txt",
- revision_id="some-rev",
- )
- self.assertEqual([], hosting_fixture.getInventory.calls)
- self.assertEqual([], hosting_fixture.getBlob.calls)
class TestBranchUnscan(TestCaseWithFactory):
diff --git a/lib/lp/code/model/tests/test_branchhosting.py b/lib/lp/code/model/tests/test_branchhosting.py
index ccf6dc8..9e7e20d 100644
--- a/lib/lp/code/model/tests/test_branchhosting.py
+++ b/lib/lp/code/model/tests/test_branchhosting.py
@@ -108,108 +108,44 @@ class TestBranchHostingClient(TestCase):
"1",
)
- def test_getInventory(self):
- with self.mockRequests("GET", json={"filelist": []}):
- response = self.client.getInventory(123, "dir/path/file/name")
- self.assertEqual({"filelist": []}, response)
- self.assertRequest(
- "+branch-id/123/+json/files/head%3A/dir/path/file/name"
- )
-
- def test_getInventory_revision(self):
- with self.mockRequests("GET", json={"filelist": []}):
- response = self.client.getInventory(
- 123, "dir/path/file/name", rev="a"
- )
- self.assertEqual({"filelist": []}, response)
- self.assertRequest("+branch-id/123/+json/files/a/dir/path/file/name")
-
- def test_getInventory_not_found(self):
- with self.mockRequests("GET", status=404):
- self.assertRaisesWithContent(
- BranchFileNotFound,
- "Branch ID 123 has no file dir/path/file/name",
- self.client.getInventory,
- 123,
- "dir/path/file/name",
- )
-
- def test_getInventory_revision_not_found(self):
- with self.mockRequests("GET", status=404):
- self.assertRaisesWithContent(
- BranchFileNotFound,
- "Branch ID 123 has no file dir/path/file/name at revision a",
- self.client.getInventory,
- 123,
- "dir/path/file/name",
- rev="a",
- )
-
- def test_getInventory_bad_revision(self):
- self.assertRaises(
- ValueError,
- self.client.getInventory,
- 123,
- "dir/path/file/name",
- rev="x/y",
- )
-
- def test_getInventory_failure(self):
- with self.mockRequests("GET", status=400):
- self.assertRaisesWithContent(
- BranchHostingFault,
- "Failed to get inventory from Bazaar branch: "
- "400 Client Error: Bad Request",
- self.client.getInventory,
- 123,
- "dir/path/file/name",
- )
-
- def test_getInventory_url_quoting(self):
- with self.mockRequests("GET", json={"filelist": []}):
- self.client.getInventory(123, "+file/ name?", rev="+rev id?")
- self.assertRequest(
- "+branch-id/123/+json/files/%2Brev%20id%3F/%2Bfile/%20name%3F"
- )
-
def test_getBlob(self):
blob = b"".join(bytes((i,)) for i in range(256))
with self.mockRequests("GET", body=blob):
- response = self.client.getBlob(123, "file-id")
+ response = self.client.getBlob(123, "file-name")
self.assertEqual(blob, response)
- self.assertRequest("+branch-id/123/download/head%3A/file-id")
+ self.assertRequest("+branch-id/123/download/head%3A/file-name")
def test_getBlob_revision(self):
blob = b"".join(bytes((i,)) for i in range(256))
with self.mockRequests("GET", body=blob):
- response = self.client.getBlob(123, "file-id", rev="a")
+ response = self.client.getBlob(123, "file-name", rev="a")
self.assertEqual(blob, response)
- self.assertRequest("+branch-id/123/download/a/file-id")
+ self.assertRequest("+branch-id/123/download/a/file-name")
def test_getBlob_not_found(self):
with self.mockRequests("GET", status=404):
self.assertRaisesWithContent(
BranchFileNotFound,
- "Branch ID 123 has no file with ID file-id",
+ "Branch ID 123 has no file with path src/file",
self.client.getBlob,
123,
- "file-id",
+ "src/file",
)
def test_getBlob_revision_not_found(self):
with self.mockRequests("GET", status=404):
self.assertRaisesWithContent(
BranchFileNotFound,
- "Branch ID 123 has no file with ID file-id at revision a",
+ "Branch ID 123 has no file with path src/file at revision a",
self.client.getBlob,
123,
- "file-id",
+ "src/file",
rev="a",
)
def test_getBlob_bad_revision(self):
self.assertRaises(
- ValueError, self.client.getBlob, 123, "file-id", rev="x/y"
+ ValueError, self.client.getBlob, 123, "file-name", rev="x/y"
)
def test_getBlob_failure(self):
@@ -220,7 +156,7 @@ class TestBranchHostingClient(TestCase):
"400 Client Error: Bad Request",
self.client.getBlob,
123,
- "file-id",
+ "file-name",
)
def test_getBlob_url_quoting(self):
@@ -246,11 +182,11 @@ class TestBranchHostingClient(TestCase):
with self.testcase.mockRequests(
"GET", body=blob, set_default_timeout=False
):
- self.blob = self.testcase.client.getBlob(123, "file-id")
+ self.blob = self.testcase.client.getBlob(123, "file-name")
# We must make this assertion inside the job, since the job
# runner creates a separate timeline.
self.testcase.assertRequest(
- "+branch-id/123/download/head%3A/file-id"
+ "+branch-id/123/download/head%3A/file-name"
)
job = GetBlobJob(self)
diff --git a/lib/lp/code/tests/helpers.py b/lib/lp/code/tests/helpers.py
index 7f36b61..ff8165b 100644
--- a/lib/lp/code/tests/helpers.py
+++ b/lib/lp/code/tests/helpers.py
@@ -311,25 +311,11 @@ class BranchHostingFixture(fixtures.Fixture):
def __init__(
self,
diff=None,
- inventory=None,
- file_list=None,
blob=None,
disable_memcache=True,
):
self.create = FakeMethod()
self.getDiff = FakeMethod(result=diff or {})
- if inventory is None:
- if file_list is not None:
- # Simple common case.
- inventory = {
- "filelist": [
- {"filename": filename, "file_id": file_id}
- for filename, file_id in file_list.items()
- ],
- }
- else:
- inventory = {"filelist": []}
- self.getInventory = FakeMethod(result=inventory)
self.getBlob = FakeMethod(result=blob)
self.disable_memcache = disable_memcache
diff --git a/lib/lp/services/webapp/publisher.py b/lib/lp/services/webapp/publisher.py
index c44c87b..88e3d76 100644
--- a/lib/lp/services/webapp/publisher.py
+++ b/lib/lp/services/webapp/publisher.py
@@ -29,12 +29,7 @@ import http.client
import json
import re
from cgi import FieldStorage
-from typing import (
- Any,
- Dict,
- Optional,
- Type,
-)
+from typing import Any, Dict, Optional, Type
from urllib.parse import urlparse
from wsgiref.headers import Headers
diff --git a/lib/lp/snappy/browser/tests/test_snap.py b/lib/lp/snappy/browser/tests/test_snap.py
index 74b502c..10af3a1 100644
--- a/lib/lp/snappy/browser/tests/test_snap.py
+++ b/lib/lp/snappy/browser/tests/test_snap.py
@@ -771,7 +771,6 @@ class TestSnapAddView(BaseTestSnapView):
def test_initial_name_extraction_bzr_success(self):
self.useFixture(
BranchHostingFixture(
- file_list={"snapcraft.yaml": "file-id"},
blob=b"name: test-snap",
)
)
@@ -782,7 +781,7 @@ class TestSnapAddView(BaseTestSnapView):
self.assertEqual("test-snap", initial_values["store_name"])
def test_initial_name_extraction_bzr_error(self):
- self.useFixture(BranchHostingFixture()).getInventory = FakeMethod(
+ self.useFixture(BranchHostingFixture()).getBlob = FakeMethod(
failure=BranchHostingFault
)
branch = self.factory.makeBranch()
@@ -792,11 +791,7 @@ class TestSnapAddView(BaseTestSnapView):
self.assertIsNone(initial_values["store_name"])
def test_initial_name_extraction_bzr_no_name(self):
- self.useFixture(
- BranchHostingFixture(
- file_list={"snapcraft.yaml": "file-id"}, blob=b"some: nonsense"
- )
- )
+ self.useFixture(BranchHostingFixture(blob=b"some: nonsense"))
branch = self.factory.makeBranch()
view = create_initialized_view(branch, "+new-snap")
initial_values = view.initial_values
diff --git a/lib/lp/snappy/tests/test_snap.py b/lib/lp/snappy/tests/test_snap.py
index 5329c46..86a20e1 100644
--- a/lib/lp/snappy/tests/test_snap.py
+++ b/lib/lp/snappy/tests/test_snap.py
@@ -2754,22 +2754,15 @@ class TestSnapSet(TestCaseWithFactory):
)
def test_getSnapcraftYaml_bzr_snap_snapcraft_yaml(self):
- def getInventory(unique_name, dirname, *args, **kwargs):
- if dirname == "snap":
- return {
- "filelist": [
- {
- "filename": "snapcraft.yaml",
- "file_id": "some-file-id",
- }
- ]
- }
+ def getBlob(path, filename, *args, **kwargs):
+ if filename == "snapcraft.yaml":
+ return b"name: test-snap"
else:
- raise BranchFileNotFound("dummy", dirname)
+ raise BranchFileNotFound("dummy", filename)
self.useFixture(
BranchHostingFixture(blob=b"name: test-snap")
- ).getInventory = getInventory
+ ).getBlob = getBlob
branch = self.factory.makeBranch()
self.assertEqual(
{"name": "test-snap"},
@@ -2777,22 +2770,15 @@ class TestSnapSet(TestCaseWithFactory):
)
def test_getSnapcraftYaml_bzr_build_aux_snap_snapcraft_yaml(self):
- def getInventory(unique_name, dirname, *args, **kwargs):
- if dirname == "build-aux/snap":
- return {
- "filelist": [
- {
- "filename": "snapcraft.yaml",
- "file_id": "some-file-id",
- }
- ]
- }
+ def getBlob(path, filename, *args, **kwargs):
+ if filename == "build-aux/snap/snapcraft.yaml":
+ return b"name: test-snap"
else:
- raise BranchFileNotFound("dummy", dirname)
+ raise BranchFileNotFound("dummy", filename)
self.useFixture(
BranchHostingFixture(blob=b"name: test-snap")
- ).getInventory = getInventory
+ ).getBlob = getBlob
branch = self.factory.makeBranch()
self.assertEqual(
{"name": "test-snap"},
@@ -2800,22 +2786,15 @@ class TestSnapSet(TestCaseWithFactory):
)
def test_getSnapcraftYaml_bzr_plain_snapcraft_yaml(self):
- def getInventory(unique_name, dirname, *args, **kwargs):
- if dirname == "":
- return {
- "filelist": [
- {
- "filename": "snapcraft.yaml",
- "file_id": "some-file-id",
- }
- ]
- }
+ def getBlob(path, filename, *args, **kwargs):
+ if filename == "snapcraft.yaml":
+ return b"name: test-snap"
else:
- raise BranchFileNotFound("dummy", dirname)
+ raise BranchFileNotFound("dummy", filename)
self.useFixture(
BranchHostingFixture(blob=b"name: test-snap")
- ).getInventory = getInventory
+ ).getBlob = getBlob
branch = self.factory.makeBranch()
self.assertEqual(
{"name": "test-snap"},
@@ -2823,22 +2802,15 @@ class TestSnapSet(TestCaseWithFactory):
)
def test_getSnapcraftYaml_bzr_dot_snapcraft_yaml(self):
- def getInventory(unique_name, dirname, *args, **kwargs):
- if dirname == "":
- return {
- "filelist": [
- {
- "filename": ".snapcraft.yaml",
- "file_id": "some-file-id",
- }
- ]
- }
+ def getBlob(path, filename, *args, **kwargs):
+ if filename == ".snapcraft.yaml":
+ return b"name: test-snap"
else:
- raise BranchFileNotFound("dummy", dirname)
+ raise BranchFileNotFound("dummy", filename)
self.useFixture(
BranchHostingFixture(blob=b"name: test-snap")
- ).getInventory = getInventory
+ ).getBlob = getBlob
branch = self.factory.makeBranch()
self.assertEqual(
{"name": "test-snap"},
@@ -2846,7 +2818,7 @@ class TestSnapSet(TestCaseWithFactory):
)
def test_getSnapcraftYaml_bzr_error(self):
- self.useFixture(BranchHostingFixture()).getInventory = FakeMethod(
+ self.useFixture(BranchHostingFixture()).getBlob = FakeMethod(
failure=BranchHostingFault
)
branch = self.factory.makeBranch()
@@ -2926,7 +2898,6 @@ class TestSnapSet(TestCaseWithFactory):
def test_getSnapcraftYaml_snap_bzr(self):
self.useFixture(
BranchHostingFixture(
- file_list={"snapcraft.yaml": "some-file-id"},
blob=b"name: test-snap",
)
)