Skip to content

Commit

Permalink
Merge branch 'master' into debug_events
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech committed Jul 2, 2024
2 parents ba0740f + 22c14f9 commit 32cc9b0
Show file tree
Hide file tree
Showing 128 changed files with 5,686 additions and 6,196 deletions.
90 changes: 0 additions & 90 deletions ee/api/test/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,93 +837,3 @@ def mock_implementation(url: str, headers: Any = None, params: Any = None) -> Ma
self.organization.refresh_from_db()

assert self.organization.customer_trust_scores == {"recordings": 0, "events": 15, "rows_synced": 0}


class TestActivateBillingAPI(APILicensedTest):
def test_activate_success(self):
url = "/api/billing-v2/activate"
data = {"products": "product_1:plan_1,product_2:plan_2", "redirect_path": "custom/path"}

response = self.client.get(url, data=data)
self.assertEqual(response.status_code, status.HTTP_302_FOUND)

self.assertIn("/activate", response.url)
self.assertIn("products=product_1:plan_1,product_2:plan_2", response.url)
url_pattern = r"redirect_uri=http://[^/]+/custom/path"
self.assertRegex(response.url, url_pattern)

def test_deprecated_activation_success(self):
url = "/api/billing-v2/activate"
data = {"products": "product_1:plan_1,product_2:plan_2", "redirect_path": "custom/path"}

response = self.client.get(url, data=data)
self.assertEqual(response.status_code, status.HTTP_302_FOUND)

self.assertIn("/activate", response.url)
self.assertIn("products=product_1:plan_1,product_2:plan_2", response.url)
url_pattern = r"redirect_uri=http://[^/]+/custom/path"
self.assertRegex(response.url, url_pattern)

def test_activate_with_default_redirect_path(self):
url = "/api/billing-v2/activate"
data = {
"products": "product_1:plan_1,product_2:plan_2",
}

response = self.client.get(url, data)

self.assertEqual(response.status_code, status.HTTP_302_FOUND)
self.assertIn("products=product_1:plan_1,product_2:plan_2", response.url)
url_pattern = r"redirect_uri=http://[^/]+/organization/billing"
self.assertRegex(response.url, url_pattern)

def test_activate_failure(self):
url = "/api/billing-v2/activate"
data = {"none": "nothing"}

response = self.client.get(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_activate_with_plan_error(self):
url = "/api/billing-v2/activate"
data = {"plan": "plan"}

response = self.client.get(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.json(),
{
"attr": "plan",
"code": "invalid_input",
"detail": "The 'plan' parameter is no longer supported. Please use the 'products' parameter instead.",
"type": "validation_error",
},
)

@patch("ee.billing.billing_manager.BillingManager.deactivate_products")
@patch("ee.billing.billing_manager.BillingManager.get_billing")
def test_deactivate_success(self, mock_get_billing, mock_deactivate_products):
mock_deactivate_products.return_value = MagicMock()
mock_get_billing.return_value = {
"available_features": [],
"products": [],
}

url = "/api/billing-v2/deactivate"
data = {"products": "product_1"}

response = self.client.get(url, data)

self.assertEqual(response.status_code, status.HTTP_200_OK)
mock_deactivate_products.assert_called_once_with(self.organization, "product_1")
mock_get_billing.assert_called_once_with(self.organization, None)

def test_deactivate_failure(self):
url = "/api/billing-v2/deactivate"
data = {"none": "nothing"}

response = self.client.get(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Loading

0 comments on commit 32cc9b0

Please sign in to comment.