Пример #1
0
    def test_from_release(self):
        release_input = {
            'id':
            hashutil.hash_to_bytes('aad23fa492a0c5fed0708a6703be875448c86884'),
            'target':
            hashutil.hash_to_bytes('5e46d564378afc44b31bb89f99d5675195fbdf67'),
            'target_type':
            'revision',
            'date': {
                'timestamp':
                datetime.datetime(2015,
                                  1,
                                  1,
                                  22,
                                  0,
                                  0,
                                  tzinfo=datetime.timezone.utc).timestamp(),
                'offset':
                0,
                'negative_utc':
                False,
            },
            'author': {
                'name': b'author name',
                'fullname': b'Author Name author@email',
                'email': b'author@email',
            },
            'name':
            b'v0.0.1',
            'message':
            b'some comment on release',
            'synthetic':
            True,
        }

        expected_release = {
            'id': 'aad23fa492a0c5fed0708a6703be875448c86884',
            'target': '5e46d564378afc44b31bb89f99d5675195fbdf67',
            'target_type': 'revision',
            'date': '2015-01-01T22:00:00+00:00',
            'author': {
                'name': 'author name',
                'fullname': 'Author Name author@email',
                'email': 'author@email',
            },
            'name': 'v0.0.1',
            'message': 'some comment on release',
            'target_type': 'revision',
            'synthetic': True,
        }

        # when
        actual_release = converters.from_release(release_input)

        # then
        self.assertEqual(actual_release, expected_release)
Пример #2
0
    def test_from_release_no_revision(self):
        release_input = {
            'id':
            hashutil.hash_to_bytes('b2171ee2bdf119cd99a7ec7eff32fa8013ef9a4e'),
            'target':
            None,
            'date': {
                'timestamp':
                datetime.datetime(2016,
                                  3,
                                  2,
                                  10,
                                  0,
                                  0,
                                  tzinfo=datetime.timezone.utc).timestamp(),
                'offset':
                0,
                'negative_utc':
                True,
            },
            'name':
            b'v0.1.1',
            'message':
            b'comment on release',
            'synthetic':
            False,
            'author': {
                'name': b'bob',
                'fullname': b'Bob [email protected]',
                'email': b'*****@*****.**',
            },
        }

        expected_release = {
            'id': 'b2171ee2bdf119cd99a7ec7eff32fa8013ef9a4e',
            'target': None,
            'date': '2016-03-02T10:00:00-00:00',
            'name': 'v0.1.1',
            'message': 'comment on release',
            'synthetic': False,
            'author': {
                'name': 'bob',
                'fullname': 'Bob [email protected]',
                'email': '*****@*****.**',
            },
        }

        # when
        actual_release = converters.from_release(release_input)

        # then
        self.assertEqual(actual_release, expected_release)
Пример #3
0
def lookup_release_multiple(sha1_git_list):
    """Return information about the revisions identified with
    their sha1_git identifiers.

    Args:
        sha1_git_list: A list of revision sha1_git identifiers

    Returns:
        Release information as dict.

    Raises:
        ValueError if the identifier provided is not of sha1 nature.

    """
    sha1_bin_list = (_to_sha1_bin(sha1_git) for sha1_git in sha1_git_list)
    releases = storage.release_get(sha1_bin_list) or []
    return (converters.from_release(r) for r in releases)
Пример #4
0
def test_from_release():
    """Convert release model object to a dict should be ok"""
    ts = int(
        datetime.datetime(2015, 1, 1, 22, 0, 0,
                          tzinfo=datetime.timezone.utc).timestamp())
    release_input = Release(
        id=hashutil.hash_to_bytes("aad23fa492a0c5fed0708a6703be875448c86884"),
        target=hashutil.hash_to_bytes(
            "5e46d564378afc44b31bb89f99d5675195fbdf67"),
        target_type=ObjectType.REVISION,
        date=TimestampWithTimezone(
            timestamp=Timestamp(seconds=ts, microseconds=0),
            offset=0,
            negative_utc=False,
        ),
        author=Person(
            name=b"author name",
            fullname=b"Author Name author@email",
            email=b"author@email",
        ),
        name=b"v0.0.1",
        message=b"some comment on release",
        synthetic=True,
    )

    expected_release = {
        "id": "aad23fa492a0c5fed0708a6703be875448c86884",
        "target": "5e46d564378afc44b31bb89f99d5675195fbdf67",
        "target_type": "revision",
        "date": "2015-01-01T22:00:00+00:00",
        "author": {
            "name": "author name",
            "fullname": "Author Name author@email",
            "email": "author@email",
        },
        "name": "v0.0.1",
        "message": "some comment on release",
        "target_type": "revision",
        "synthetic": True,
    }

    actual_release = converters.from_release(release_input)

    assert actual_release == expected_release
Пример #5
0
def lookup_release(release_sha1_git: str) -> Dict[str, Any]:
    """Return information about the release with sha1 release_sha1_git.

    Args:
        release_sha1_git: The release's sha1 as hexadecimal

    Returns:
        Release information as dict.

    Raises:
        ValueError if the identifier provided is not of sha1 nature.

    """
    sha1_git_bin = _to_sha1_bin(release_sha1_git)
    release = _first_element(storage.release_get([sha1_git_bin]))
    if not release:
        raise NotFoundExc(
            f"Release with sha1_git {release_sha1_git} not found.")
    return converters.from_release(release)
Пример #6
0
def lookup_release_multiple(
        sha1_git_list) -> Iterator[Optional[Dict[str, Any]]]:
    """Return information about the releases identified with
    their sha1_git identifiers.

    Args:
        sha1_git_list: A list of release sha1_git identifiers

    Returns:
        Iterator of Release metadata information as dict.

    Raises:
        ValueError if the identifier provided is not of sha1 nature.

    """
    sha1_bin_list = [_to_sha1_bin(sha1_git) for sha1_git in sha1_git_list]
    releases = storage.release_get(sha1_bin_list)
    for r in releases:
        if r is not None:
            yield converters.from_release(r)
        else:
            yield None
Пример #7
0
 def release_get(self, rel_id: str) -> Optional[Dict[str, Any]]:
     rel_id_bytes = hash_to_bytes(rel_id)
     rel_data = self.storage.release_get([rel_id_bytes])[0]
     return converters.from_release(rel_data) if rel_data else None
Пример #8
0
 def release_get(cls, rel_id):
     rel_id_bytes = hash_to_bytes(rel_id)
     rel_data = next(cls.storage.release_get([rel_id_bytes]))
     return converters.from_release(rel_data)