Skip to content

Commit

Permalink
Merge 10608ba into 6377367
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurek committed Oct 10, 2014
2 parents 6377367 + 10608ba commit 4682060
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ralph/util/api_scrooge.py
Expand Up @@ -199,7 +199,7 @@ def get_owners():
}


def get_services():
def get_services(only_calculated_in_scrooge=False):
"""
Returns Services (CIs with type Service) with additional information like
owners, business line etc.
Expand All @@ -210,6 +210,15 @@ def get_services():
for service in CI.objects.filter(
type=service_type
).select_related('relations'):
try:
calculate_in_scrooge = service.ciattributevalue_set.get(
attribute_id=7
).value
except CIAttributeValue.DoesNotExist:
calculate_in_scrooge = False
if only_calculated_in_scrooge and not calculate_in_scrooge:
continue

profit_center = service.child.filter(
parent__type=profit_center_type
).values_list('parent__id', flat=True)
Expand Down
21 changes: 21 additions & 0 deletions src/ralph/util/tests/tests.py
Expand Up @@ -267,6 +267,27 @@ def test_get_services_without_profit_center(self):
}
self.assertEquals(result, [service_dict])

def test_get_services_calc_in_scrooge(self):
service = utils.ServiceFactory()
utils.ServiceFactory() # service not calculated in scrooge
calc_in_scrooge_attr = models_ci.CIAttribute.objects.get(pk=7)
service.ciattributevalue_set.create(
attribute=calc_in_scrooge_attr,
value=True
)
result = [a for a in api_scrooge.get_services(True)]
service_dict = {
'name': service.name,
'ci_id': service.id,
'ci_uid': service.uid,
'symbol': None,
'profit_center': None,
'technical_owners': [],
'business_owners': [],
'environments': [],
}
self.assertEquals(result, [service_dict])


class UncompressBase64DataTest(TestCase):

Expand Down

0 comments on commit 4682060

Please sign in to comment.