def test_base_update_available(self, fixture_working_dir_env_repo_scoped,
                                   snapshot):
        """Test checking if the base is able to be updated"""
        im = InventoryManager(fixture_working_dir_env_repo_scoped[0])
        lb = im.create_labbook('default', 'default',
                               'labbook-base-test-update')

        cm = ComponentManager(lb)

        # Add an old base.
        cm.add_base(gtmcore.fixtures.ENV_UNIT_TEST_REPO,
                    'quickstart-jupyterlab', 1)

        query = """
                {
                  labbook(owner: "default", name: "labbook-base-test-update") {
                    name
                    description
                    environment {
                      base{                        
                        id
                        revision
                      }
                      baseLatestRevision
                    }
                  }
                }
        """
        r = fixture_working_dir_env_repo_scoped[2].execute(query)
        assert 'errors' not in r
        assert r['data']['labbook']['environment']['base']['revision'] == 1
        assert r['data']['labbook']['environment']['baseLatestRevision'] == 2

        # We upgrade our base to the latest
        cm.change_base(gtmcore.fixtures.ENV_UNIT_TEST_REPO,
                       'quickstart-jupyterlab', 2)
        r = fixture_working_dir_env_repo_scoped[2].execute(query)
        assert 'errors' not in r
        assert r['data']['labbook']['environment']['base']['revision'] == 2
        assert r['data']['labbook']['environment']['baseLatestRevision'] == 2

        query = """
                {
                  labbook(owner: "default", name: "labbook-base-test-update") {
                    name                    
                    environment {
                      baseLatestRevision
                    }
                  }
                }
        """
        r = fixture_working_dir_env_repo_scoped[2].execute(query)
        assert 'errors' not in r
        assert r['data']['labbook']['environment']['baseLatestRevision'] == 2
Ejemplo n.º 2
0
    def mutate_and_get_payload(cls,
                               root,
                               info,
                               owner,
                               labbook_name,
                               repository,
                               base_id,
                               revision,
                               client_mutation_id=None):
        username = get_logged_in_username()

        lb = InventoryManager().load_labbook(username,
                                             owner,
                                             labbook_name,
                                             author=get_logged_in_author())

        cm = ComponentManager(lb)
        cm.change_base(repository, base_id, revision)

        return ChangeLabbookBase(labbook=Labbook(owner=owner, name=lb.name))
Ejemplo n.º 3
0
    def test_change_base(self, mock_labbook):
        """change_base is used both for updating versions and truly changing the base"""
        conf_file, root_dir, lb = mock_labbook

        # Initial configuration for the labbook - base config taken from `test_add_base` and package config from
        # `test_add_package` - so we don't test assertions (again) on this part
        cm = ComponentManager(lb)

        # We "misconfigure" a package that is not part of the base as if it was from a base
        # This shouldn't happen, but we address it just in case
        pkgs = [
            {
                "manager": "pip3",
                "package": "gigantum",
                "version": "0.5"
            },
            # pandas *is* part of the quickstart-juypter base, but we specify a different version here
            {
                "package": "pandas",
                "version": "0.21"
            }
        ]
        cm.add_packages('pip3', pkgs, force=True, from_base=True)
        packages = [p for p in cm.get_component_list('package_manager')]
        assert (len(packages) == 2)
        assert (all(p['from_base'] for p in packages))

        cm.add_base(gtmcore.fixtures.ENV_UNIT_TEST_REPO,
                    'quickstart-jupyterlab', 1)

        # After installing the base, we should have one version of matplotlib installed
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] == 'matplotlib'
        ]
        assert (len(packages) == 1)
        assert (packages[0]['version'] == '2.1.1')

        # add_base() should have converted these to user-installed
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] in ['gigantum', 'pandas']
        ]
        # If we had redundancy from fake base-installed pandas plus real base-installed pandas, this would be 3
        assert (len(packages) == 2)
        for p in packages:
            # Fake base-installed is converted to user ("not from_base") installed
            assert (not p['from_base'])
            if p['package'] == 'pandas':
                # we should still have the fake base-installed version
                assert (p['version'] == '0.21')

        pkgs = [
            {
                "manager": "pip3",
                "package": "requests",
                "version": "2.18.2"
            },
            # This will override an already installed package
            {
                "manager": "pip3",
                "package": "matplotlib",
                "version": "2.2"
            }
        ]
        cm.add_packages('pip3', pkgs, force=True)

        pkgs = [{
            "manager": "apt",
            "package": "ack",
            "version": "1.0"
        }, {
            "manager": "apt",
            "package": "docker",
            "version": "3.5"
        }]
        cm.add_packages('apt', pkgs)

        # Installing a customized version of matplotlib is a new package compared to other tests,
        # and is a critical piece of testing cm.change_base
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] == 'matplotlib'
        ]
        assert (len(packages) == 1)
        assert (packages[0]['version'] == '2.2')

        # We upgrade our base
        cm.change_base(gtmcore.fixtures.ENV_UNIT_TEST_REPO,
                       'quickstart-jupyterlab', 2)

        # matplotlib still set up per "user" update?
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] == 'matplotlib'
        ]
        assert (len(packages) == 1)
        assert (packages[0]['version'] == '2.2')

        # Base revision now 2?
        assert (cm.base_fields['revision'] == 2)