Skip to content

Commit

Permalink
[COST-4993] gate ec2 endpoint with unleash (#5229)
Browse files Browse the repository at this point in the history
  • Loading branch information
maskarb authored Jul 22, 2024
1 parent 7aad9f8 commit 6ffdd28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions koku/api/report/aws/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
# SPDX-License-Identifier: Apache-2.0
#
"""AWS views."""
from rest_framework.exceptions import NotFound

from api.common.permissions.aws_access import AwsAccessPermission
from api.common.permissions.aws_access import AWSOUAccessPermission
from api.models import Provider
from api.report.aws.query_handler import AWSReportQueryHandler
from api.report.aws.serializers import AWSEC2ComputeQueryParamSerializer
from api.report.aws.serializers import AWSQueryParamSerializer
from api.report.view import ReportView
from masu.processor import is_feature_cost_4403_ec2_compute_cost_enabled


class AWSView(ReportView):
Expand Down Expand Up @@ -45,3 +48,8 @@ class AWSEC2ComputeView(AWSView):

report = "ec2_compute"
serializer = AWSEC2ComputeQueryParamSerializer

def get(self, request, **kwargs):
if not is_feature_cost_4403_ec2_compute_cost_enabled(request.user.customer.schema_name):
raise NotFound()
return super().get(request, **kwargs)
18 changes: 18 additions & 0 deletions koku/api/report/test/aws/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
"""Test the AWS Report views."""
import copy
from unittest.mock import patch

from django.urls import reverse
from rest_framework import status
Expand Down Expand Up @@ -601,6 +602,23 @@ def test_invalid_aws_category_key(self):
response = self.client.get(url, **self.headers)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_ec2_compute_view_unleashed(self):
"""Test EC2 compute view returns correct repsonses depending on unleash."""
url = reverse("reports-aws-ec2-compute")
with patch(
"api.report.aws.view.is_feature_cost_4403_ec2_compute_cost_enabled",
return_value=False,
):
response = self.client.get(url, **self.headers)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

with patch(
"api.report.aws.view.is_feature_cost_4403_ec2_compute_cost_enabled",
return_value=True,
):
response = self.client.get(url, **self.headers)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_ec2_compute_view_returns_default_time_period_params(self):
"""Test EC2 compute view returns HTTP 200 and valid default meta filter."""

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py39
envlist = py311
skipsdist = True

[flake8]
Expand Down

0 comments on commit 6ffdd28

Please sign in to comment.