Esempio n. 1
0
    def project(self):
        """Return the Project instance."""
        if self.renku_metadata_path.exists() and self._project is None:
            self._project = Project.from_yaml(self.renku_metadata_path,
                                              client=self)

        return self._project
Esempio n. 2
0
def test_project_creator_deserialization(client, project):
    """Check that the correct creator is returned on deserialization."""
    from renku.core.models.provenance.agents import Person

    # modify the project metadata to change the creator
    project = client.project
    project.creator = Person(email='*****@*****.**', name='Johnny Doe')
    project.to_yaml()
    client.repo.git.commit('-a', '--amend', '-C', 'HEAD', '--author',
                           'Johnny Doe <*****@*****.**>', '--no-verify')

    # the project creator should always be the one in the metadata
    assert '*****@*****.**' == client.project.creator.email
    assert 'Johnny Doe' == client.project.creator.name
    assert client.project.creator.label == client.project.creator.name

    # Remove the creator from metadata
    project = client.project
    project.creator = None
    project.to_yaml()
    client.repo.git.commit('-a', '--amend', '-C', 'HEAD', '--author',
                           'Jane Doe <*****@*****.**>', '--no-verify')

    # now the creator should be the one from the commit
    project = Project.from_yaml(client.renku_metadata_path, client=client)
    assert '*****@*****.**' == project.creator.email
    assert 'Jane Doe' == project.creator.name
    assert project.creator.label == project.creator.name
Esempio n. 3
0
def test_project_serialization(client):
    """Test project serialization with JSON-LD context."""
    from renku.core.management.migrate import SUPPORTED_PROJECT_VERSION

    with freeze_time("2017-03-01T08:00:00.000000+00:00") as frozen_time:
        project_time = frozen_time().replace(tzinfo=timezone.utc)
        project = Project(name="demo", client=client)
        assert project.name == "demo"
        assert project.created == project_time

    data = project.as_jsonld()
    assert "http://schema.org/Project" in data["@type"]
    assert "http://www.w3.org/ns/prov#Location" in data["@type"]

    assert "demo" == data["http://schema.org/name"]
    assert project_time.isoformat("T") == data["http://schema.org/dateCreated"]
    assert str(
        SUPPORTED_PROJECT_VERSION) == data["http://schema.org/schemaVersion"]
Esempio n. 4
0
def test_project_datetime_loading(project_meta):
    """Check that datetime is correctly loaded."""
    project = Project.from_jsonld(
        yaml.load(project_meta, Loader=NoDatesSafeLoader))

    assert isinstance(project.updated, datetime)
    assert isinstance(project.created, datetime)

    assert project.updated.tzinfo is not None
    assert project.created.tzinfo is not None
Esempio n. 5
0
def test_project_metadata_compatibility(project_meta, version, is_broken):
    """Test loading of the initial version."""
    project = Project.from_jsonld(
        yaml.load(project_meta, Loader=NoDatesSafeLoader))

    assert str(version) == project.version

    if not is_broken:
        assert 'demo' == project.name

    assert 'schema:name' == project._jsonld_context['name']
    main_context_creator = project._jsonld_context['creator']
    assert Person._jsonld_context == main_context_creator['@context']
    assert 'schema:dateUpdated' == project._jsonld_context['updated']
    assert 'schema:dateCreated' == project._jsonld_context['created']
    assert 'schema:schemaVersion' == project._jsonld_context['version']
Esempio n. 6
0
def test_project_serialization():
    """Test project serialization with JSON-LD context."""
    with freeze_time('2017-03-01T08:00:00.000000+00:00') as frozen_time:
        project = Project(name='demo')
        assert project.name == 'demo'
        assert project.created == frozen_time().replace(tzinfo=timezone.utc)
        assert project.updated == frozen_time().replace(tzinfo=timezone.utc)

    data = asjsonld(project)
    assert 'schema:Project' in data['@type']
    assert 'prov:Location' in data['@type']

    context = data['@context']
    assert 'schema:name' == context['name']
    assert Person._jsonld_context == context['creator']['@context']
    assert 'schema:dateUpdated' == context['updated']
    assert 'schema:dateCreated' == context['created']
    assert 'schema:schemaVersion' == context['version']
Esempio n. 7
0
    def with_metadata(self, read_only=False, name=None):
        """Yield an editable metadata object."""
        metadata_path = self.renku_metadata_path

        if metadata_path.exists():
            metadata = Project.from_yaml(metadata_path, client=self)
        else:
            metadata = Project(name=name, client=self)
            metadata.__reference__ = metadata_path

        yield metadata

        if not read_only:
            metadata.to_yaml()
Esempio n. 8
0
 def project(self):
     """Return the Project instance."""
     if self.renku_metadata_path.exists():
         return Project.from_yaml(self.renku_metadata_path, client=self)