~milner/landscape-client/enable-preseed

« back to all changes in this revision

Viewing changes to landscape/package/tests/helpers.py

Merged apt-load-system-packages [r=ack,free.ekanayaka] [f=856244].

Add AptFacade and have its get_packages() report all the system packages
(the ones in /var/lib/dpkg/status).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import smart
5
5
 
6
6
from landscape.lib.fs import create_file
 
7
from landscape.package.facade import AptFacade
 
8
 
 
9
 
 
10
class AptFacadeHelper(object):
 
11
    """Helper that sets up an AptFacade with a tempdir as its root."""
 
12
 
 
13
    def set_up(self, test_case):
 
14
        test_case.apt_root = test_case.makeDir()
 
15
        # Create all the required directories, so that apt doesn't
 
16
        # auto-create them, which causing the paths to be printed to stdout.
 
17
        test_case.dpkg_dir = self._create_sub_dir(test_case, "var/lib/dpkg")
 
18
        self._create_sub_dir(test_case, "etc/apt")
 
19
        self._create_sub_dir(test_case, "var/cache/apt/archives/partial")
 
20
        self._create_sub_dir(test_case, "var/lib/apt/lists/partial")
 
21
        test_case.dpkg_status = os.path.join(test_case.dpkg_dir, "status")
 
22
        with open(test_case.dpkg_status, "w") as status_file:
 
23
            status_file.write("")
 
24
        test_case.facade = AptFacade(root=test_case.apt_root)
 
25
 
 
26
    def _create_sub_dir(self, test_case, sub_dir):
 
27
        """Create a dir instead the Apt root dir."""
 
28
        full_path = os.path.join(test_case.apt_root, sub_dir)
 
29
        os.makedirs(full_path)
 
30
        return full_path
7
31
 
8
32
 
9
33
class SmartHelper(object):