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

added get_environments method to ServiceCatalog #1145

Merged
merged 2 commits into from Oct 10, 2014
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
7 changes: 7 additions & 0 deletions src/ralph/discovery/models_device.py
Expand Up @@ -311,6 +311,13 @@ class Meta:
def __unicode__(self):
return self.name

def get_environments(self):
env_ids_from_service = models_ci.CIRelation.objects.filter(
parent=self.id,
).values('child__id')
envs = DeviceEnvironment.objects.filter(id__in=env_ids_from_service)
return envs


class Device(
LastSeen,
Expand Down
15 changes: 15 additions & 0 deletions src/ralph/discovery/tests/test_models.py
Expand Up @@ -10,6 +10,11 @@
from django.test import TestCase
import mock

from ralph.cmdb.tests.utils import (
CIRelationFactory,
DeviceEnvironmentFactory,
ServiceCatalogFactory,
)
from ralph.discovery.models import DeviceType, Device, UptimeSupport
from ralph.discovery.models_history import HistoryChange

Expand Down Expand Up @@ -82,3 +87,13 @@ class Model(UptimeSupport):
self.assertEqual(m.uptime, None)
m.uptime = 132
self.assertEqual(m.uptime, datetime.timedelta(seconds=132))


class ServiceEnvironments(TestCase):

def test_getting_environments(self):
service = ServiceCatalogFactory()
env = DeviceEnvironmentFactory()
self.assertEqual(len(service.get_environments()), 0)
CIRelationFactory(parent=service, child=env)
self.assertEqual(len(service.get_environments()), 1)