def test_sync_webapi_metricprofiles(self, func): func.side_effect = mocked_web_api_request self.assertEqual(poem_models.MetricProfiles.objects.all().count(), 2) sync_webapi('metric_profiles', poem_models.MetricProfiles) self.assertEqual(poem_models.MetricProfiles.objects.all().count(), 2) self.assertEqual( poem_models.MetricProfiles.objects.get(name='TEST_PROFILE'), self.mp1) self.assertRaises(poem_models.MetricProfiles.DoesNotExist, poem_models.MetricProfiles.objects.get, name='ANOTHER-PROFILE') self.assertEqual( poem_models.TenantHistory.objects.filter( object_id=self.mp2.id).count(), 0) self.assertTrue( poem_models.MetricProfiles.objects.get(name='NEW_PROFILE')) history = poem_models.TenantHistory.objects.filter( object_repr='NEW_PROFILE') self.assertEqual(history.count(), 1) self.assertEqual(history[0].comment, 'Initial version.') serialized_data = json.loads(history[0].serialized_data)[0]['fields'] self.assertEqual(serialized_data['name'], 'NEW_PROFILE') self.assertEqual(serialized_data['apiid'], '11110000-aaaa-kkkk-aaaa-aaeekkccnnee') self.assertEqual(serialized_data['metricinstances'], [['dg.3GBridge', 'eu.egi.cloud.Swift-CRUD']])
def test_sync_webapi_thresholdsprofile(self, func): func.side_effect = mocked_web_api_request self.assertEqual(poem_models.ThresholdsProfiles.objects.all().count(), 2) sync_webapi('thresholds_profiles', poem_models.ThresholdsProfiles) self.assertEqual(poem_models.ThresholdsProfiles.objects.all().count(), 2) self.assertEqual( poem_models.ThresholdsProfiles.objects.get(name='TEST_PROFILE'), self.tp1) self.assertRaises(poem_models.ThresholdsProfiles.DoesNotExist, poem_models.ThresholdsProfiles.objects.get, name='ANOTHER-PROFILE')
def test_sync_webapi_aggregationprofiles(self, func): func.side_effect = mocked_web_api_request self.assertEqual(poem_models.Aggregation.objects.all().count(), 2) sync_webapi('aggregation_profiles', poem_models.Aggregation) self.assertEqual(poem_models.Aggregation.objects.all().count(), 2) self.assertEqual( poem_models.Aggregation.objects.get(name='TEST_PROFILE'), self.aggr1) self.assertRaises(poem_models.Aggregation.DoesNotExist, poem_models.Aggregation.objects.get, name='ANOTHER-PROFILE') self.assertTrue( poem_models.Aggregation.objects.get(name='NEW_PROFILE'))
def get(self, request, report_name=None): sync_webapi(settings.WEBAPI_REPORTS, poem_models.Reports) if report_name: try: report = poem_models.Reports.objects.get( name=report_name ) serializer = serializers.ReportsSerializer(report) return Response(serializer.data) except poem_models.Reports.DoesNotExist: raise NotFound(status=404, detail='Report not found') else: reports = poem_models.Reports.objects.all().order_by('name') serializer = serializers.ReportsSerializer(reports, many=True) return Response(serializer.data)
def get(self, request, profile_name=None): sync_webapi(settings.WEBAPI_METRIC, poem_models.MetricProfiles) if profile_name: try: profile = poem_models.MetricProfiles.objects.get( name=profile_name) serializer = serializers.MetricProfileSerializer(profile) return Response(serializer.data) except poem_models.MetricProfiles.DoesNotExist: raise NotFound(status=404, detail='Metric profile not found') else: profiles = poem_models.MetricProfiles.objects.all().order_by( 'name') serializer = serializers.MetricProfileSerializer(profiles, many=True) return Response(serializer.data)
def get(self, request, name=None): sync_webapi(settings.WEBAPI_THRESHOLDS, poem_models.ThresholdsProfiles) if name: try: profile = poem_models.ThresholdsProfiles.objects.get(name=name) serializer = serializers.ThresholdsProfileSerializer(profile) return Response(serializer.data) except poem_models.ThresholdsProfiles.DoesNotExist: raise NotFound(status=404, detail='Thresholds profile does not exist.') else: profiles = poem_models.ThresholdsProfiles.objects.all().order_by( 'name') serializer = serializers.ThresholdsProfileSerializer(profiles, many=True) return Response(serializer.data)
def get(self, request, aggregation_name=None): sync_webapi(settings.WEBAPI_AGGREGATION, poem_models.Aggregation) if aggregation_name: try: aggregation = poem_models.Aggregation.objects.get( name=aggregation_name) serializer = serializers.AggregationProfileSerializer( aggregation) return Response(serializer.data) except poem_models.Aggregation.DoesNotExist: raise NotFound(status=404, detail='Aggregation not found') else: aggregations = poem_models.Aggregation.objects.all().order_by( 'name') serializer = serializers.AggregationProfileSerializer(aggregations, many=True) return Response(serializer.data)