Skip to content

Commit

Permalink
Merge pull request #1878 from tseaver/logging-collapse__helpers
Browse files Browse the repository at this point in the history
Collapse 'gcloud.logging._helpers' into '.entries'.
  • Loading branch information
tseaver authored Jun 21, 2016
2 parents 22bf022 + 54eabe4 commit 7407556
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 79 deletions.
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

0 comments on commit 7407556

Please sign in to comment.