Skip to content

Commit

Permalink
Merge pull request #62 from eduNEXT/and/change_stats_default
Browse files Browse the repository at this point in the history
feat: change default stats view in order to show all available compon…
  • Loading branch information
andrey-canon authored Jul 7, 2023
2 parents ae8ccad + 340157f commit 034ba4f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
Empty file.
18 changes: 12 additions & 6 deletions eox_nelp/stats/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from django.urls import reverse
from rest_framework import status

from eox_nelp.stats.views import STATS_QUERY_PARAMS


@ddt
class GetTenantStatsTestCase(TestCase):
Expand Down Expand Up @@ -37,26 +39,30 @@ def test_get_default_stats(self):
self.assertEqual(self.template_name, response.templates[0].name)
self.assertContains(response, '<div id="tenant-stats"></div')

@data("show_videos", "show_course", "show_problems", "show_instructors", "show_learners")
def test_get_specific_stat(self, query_param):
for query_param in STATS_QUERY_PARAMS:
self.assertEqual("true", response.context[query_param])

@data(*STATS_QUERY_PARAMS)
def test_filter_stat_out(self, query_param):
"""
Test that the view render successfully when a query param is included
Since the default behavior shows all the components this tests that specific component
is filtered out when the query param is false.
Expected behavior:
- Status code 200.
- template name is as expected.
- tenant-stats div exist
- the query param is 'true'
- the query param is 'false'
- CSS was included
- JS was included
"""
url_endpoint = f"{reverse('stats:tenant')}?{query_param}=true"
url_endpoint = f"{reverse('stats:tenant')}?{query_param}=false"

response = self.client.get(url_endpoint)

self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(self.template_name, response.templates[0].name)
self.assertContains(response, '<div id="tenant-stats"></div')
self.assertEqual("true", response.context[query_param])
self.assertEqual("false", response.context[query_param])
self.assertContains(response, "tenant_stats/css/tenant_stats.css")
self.assertContains(response, "tenant_stats/js/tenant_stats.js")
43 changes: 25 additions & 18 deletions eox_nelp/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,43 @@
classes:
get_tenant_stats: function based view.
"""

from eox_nelp.templates_config import render_to_response

STATS_QUERY_PARAMS = [
"show_courses",
"show_videos",
"show_problems",
"show_learners",
"show_instructors",
]


def get_tenant_stats(request):
"""
Simple function based view that renders the StatsContainer essential component.
By default this show nothing since this requires the specific query para to show the content.
By default this will show all the available stats.
Examples:
renders just video card /eox-nelp/stats/tenant/?show_videos=true
renders all available stats /eox-nelp/stats/tenant/
render multiple components
/eox-nelp/stats/tenant/?show_videos=true&show_courses=true&show_instructors=true
filters out videos, courses and instructors
/eox-nelp/stats/tenant/?show_videos=false&show_courses=false&show_instructors=false
The available options are:
show_videos
show_courses
show_learners
show_instructors
show_problems
"""
context = {
"show_courses": "false",
"show_videos": "false",
"show_problems": "false",
"show_learners": "false",
"show_instructors": "false",
}
| name | default | Description |
| show_videos | true | Show the videos stats |
| show_courses | true | Show the courses stats |
| show_learners | true | Show the learner stats |
| show_instructors | true | Show the instructors stats |
| show_problems | true | Show the problems stats |
"""
context = {query_param: "true" for query_param in STATS_QUERY_PARAMS}
context.update(request.GET.dict())

return render_to_response("tenant_stats.html", context)

0 comments on commit 034ba4f

Please sign in to comment.