Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse 'gcloud.logging._helpers' into '.entries'. #1878

Merged
merged 1 commit into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions gcloud/logging/_helpers.py

This file was deleted.

26 changes: 25 additions & 1 deletion gcloud/logging/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,35 @@
"""Log entries within the Google Cloud Logging API."""

import json
import re

from google.protobuf.json_format import Parse

from gcloud._helpers import _name_from_project_path
from gcloud._helpers import _rfc3339_nanos_to_datetime
from gcloud.logging._helpers import logger_name_from_path


_LOGGER_TEMPLATE = re.compile(r"""
projects/ # static prefix
(?P<project>[^/]+) # initial letter, wordchars + hyphen
/logs/ # static midfix
(?P<name>[^/]+) # initial letter, wordchars + allowed punc
""", re.VERBOSE)


def logger_name_from_path(path):
"""Validate a logger URI path and get the logger name.

:type path: str
:param path: URI path for a logger API request.

:rtype: str
:returns: Logger name parsed from ``path``.
:raises: :class:`ValueError` if the ``path`` is ill-formed or if
the project from the ``path`` does not agree with the
``project`` passed in.
"""
return _name_from_project_path(path, None, _LOGGER_TEMPLATE)


class _BaseEntry(object):
Expand Down
36 changes: 0 additions & 36 deletions gcloud/logging/test__helpers.py

This file was deleted.

21 changes: 21 additions & 0 deletions gcloud/logging/test_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@
import unittest2


class Test_logger_name_from_path(unittest2.TestCase):

def _callFUT(self, path):
from gcloud.logging.entries import logger_name_from_path
return logger_name_from_path(path)

def test_w_simple_name(self):
LOGGER_NAME = 'LOGGER_NAME'
PROJECT = 'my-project-1234'
PATH = 'projects/%s/logs/%s' % (PROJECT, LOGGER_NAME)
logger_name = self._callFUT(PATH)
self.assertEqual(logger_name, LOGGER_NAME)

def test_w_name_w_all_extras(self):
LOGGER_NAME = 'LOGGER_NAME-part.one~part.two%part-three'
PROJECT = 'my-project-1234'
PATH = 'projects/%s/logs/%s' % (PROJECT, LOGGER_NAME)
logger_name = self._callFUT(PATH)
self.assertEqual(logger_name, LOGGER_NAME)


class Test_BaseEntry(unittest2.TestCase):

PROJECT = 'PROJECT'
Expand Down