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

Add system test for 'Client.list_metrics'. #1611

Merged
merged 1 commit into from
Mar 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions gcloud/logging/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ def from_api_repr(cls, resource, client):

:rtype: :class:`gcloud.logging.metric.Metric`
:returns: Metric parsed from ``resource``.
:raises: :class:`ValueError` if ``client`` is not ``None`` and the
project from the resource does not agree with the project
from the client.
"""
metric_name = _metric_name_from_path(resource['name'], client.project)
metric_name = resource['name']

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

filter_ = resource['filter']
description = resource.get('description', '')
return cls(metric_name, filter_, client=client,
Expand Down
7 changes: 2 additions & 5 deletions gcloud/logging/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,9 @@ def test_list_metrics_no_paging(self):

CLIENT_OBJ = self._makeOne(project=PROJECT, credentials=CREDS)

METRIC_PATH = 'projects/%s/metrics/%s' % (PROJECT, self.METRIC_NAME)

RETURNED = {
'metrics': [{
'name': METRIC_PATH,
'name': self.METRIC_NAME,
'filter': self.FILTER,
'description': self.DESCRIPTION,
}],
Expand Down Expand Up @@ -329,13 +327,12 @@ def test_list_metrics_with_paging(self):

CLIENT_OBJ = self._makeOne(project=PROJECT, credentials=CREDS)

METRIC_PATH = 'projects/%s/metrics/%s' % (PROJECT, self.METRIC_NAME)
TOKEN1 = 'TOKEN1'
TOKEN2 = 'TOKEN2'
SIZE = 1
RETURNED = {
'metrics': [{
'name': METRIC_PATH,
'name': self.METRIC_NAME,
'filter': self.FILTER,
'description': self.DESCRIPTION,
}],
Expand Down
14 changes: 2 additions & 12 deletions gcloud/logging/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_from_api_repr_minimal(self):
CLIENT = _Client(project=self.PROJECT)
FULL = 'projects/%s/metrics/%s' % (self.PROJECT, self.METRIC_NAME)
RESOURCE = {
'name': FULL,
'name': self.METRIC_NAME,
'filter': self.FILTER,
}
klass = self._getTargetClass()
Expand All @@ -109,7 +109,7 @@ def test_from_api_repr_w_description(self):
FULL = 'projects/%s/metrics/%s' % (self.PROJECT, self.METRIC_NAME)
DESCRIPTION = 'DESCRIPTION'
RESOURCE = {
'name': FULL,
'name': self.METRIC_NAME,
'filter': self.FILTER,
'description': DESCRIPTION,
}
Expand All @@ -122,16 +122,6 @@ def test_from_api_repr_w_description(self):
self.assertEqual(metric.project, self.PROJECT)
self.assertEqual(metric.full_name, FULL)

def test_from_api_repr_with_mismatched_project(self):
PROJECT1 = 'PROJECT1'
PROJECT2 = 'PROJECT2'
CLIENT = _Client(project=PROJECT1)
FULL = 'projects/%s/metrics/%s' % (PROJECT2, self.METRIC_NAME)
RESOURCE = {'name': FULL, 'filter': self.FILTER}
klass = self._getTargetClass()
self.assertRaises(ValueError, klass.from_api_repr,
RESOURCE, client=CLIENT)

def test_create_w_bound_client(self):
TARGET = 'projects/%s/metrics' % (self.PROJECT,)
RESOURCE = {
Expand Down
14 changes: 14 additions & 0 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,17 @@ def test_create_metric(self):
metric.create()
self.to_delete.append(metric)
self.assertTrue(metric.exists())

def test_list_metrics(self):
metric = Config.CLIENT.metric(
DEFAULT_METRIC_NAME, DEFAULT_FILTER, DEFAULT_DESCRIPTION)
self.assertFalse(metric.exists())
before_metrics, _ = Config.CLIENT.list_metrics()
before_names = set(metric.name for metric in before_metrics)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

metric.create()
self.to_delete.append(metric)
self.assertTrue(metric.exists())
after_metrics, _ = Config.CLIENT.list_metrics()
after_names = set(metric.name for metric in after_metrics)
self.assertEqual(after_names - before_names,
set([DEFAULT_METRIC_NAME]))