Skip to content

Commit

Permalink
test: add test for view including total certs
Browse files Browse the repository at this point in the history
  • Loading branch information
johanseto committed Sep 12, 2023
1 parent 7eb1c93 commit 732df1d
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion eox_nelp/stats/tests/api/v1/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,49 @@ def test_total_components(self, mock_metrics):
self.assertEqual(expected_components, response.data["components"])
mock_metrics.get_courses_metrics.assert_called_once_with("testserver")

@override_settings(
MIDDLEWARE=["eox_tenant.middleware.CurrentSiteMiddleware"],
)
@patch("eox_nelp.stats.api.v1.views.metrics")
def test_total_certificates(self, mock_metrics):
"""
Test that the view will calculate the total of certificates based on the metrics values
Expected behavior:
- Status code 200.
- Components total values are the expected.
- get_courses_metrics is called once.
"""
total_courses = 4
fake_metric = {
"certificates": {
"verified": {"downloadable": 0, "not_passing": 0},
"honor": {"downloadable": 0, "not_passing": 0},
"audit": {"downloadable": 0, "not_passing": 0},
"professional": {"downloadable": 0, "not_passing": 0},
"no-id-professional": {"downloadable": 5, "not_passing": 4},
"masters": {"downloadable": 0, "not_passing": 0},
"executive-education": {"downloadable": 0, "not_passing": 0},
"paid-executive-education": {"downloadable": 0, "not_passing": 0},
"paid-bootcamp": {"downloadable": 0, "not_passing": 0},
"total": 9,
}
}
mock_metrics.get_learners_metric.return_value = 5
mock_metrics.get_instructors_metric.return_value = 4875
mock_metrics.get_courses_metrics.return_value = {
"total_courses": total_courses,
"metrics": [fake_metric for c in range(total_courses)],
}
expected_certificates = fake_metric["certificates"]["total"] * total_courses
url_endpoint = reverse("stats-api:v1:general-stats")

response = self.client.get(url_endpoint)

self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(expected_certificates, response.data["certificates"])
mock_metrics.get_courses_metrics.assert_called_once_with("testserver")

@override_settings(MIDDLEWARE=["eox_tenant.middleware.CurrentSiteMiddleware"])
@data("post", "put", "patch", "delete")
def test_invalid_method(self, method):
Expand Down Expand Up @@ -176,7 +219,8 @@ def test_get_detail(self, mock_metrics):
"openassessment": 0,
"problem": 49,
"video": 0
}
},
"certificates": 12
}
url_endpoint = reverse("stats-api:v1:course-stats", args=[course_id])

Expand Down

0 comments on commit 732df1d

Please sign in to comment.