From 96ecf2f4771b21666768acfba02a3f410c88c525 Mon Sep 17 00:00:00 2001 From: serge Date: Wed, 14 Dec 2016 11:36:26 +0800 Subject: [PATCH] Improved test for statistics endpoint --- biosys/apps/main/tests/api/test_misc.py | 34 +++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/biosys/apps/main/tests/api/test_misc.py b/biosys/apps/main/tests/api/test_misc.py index c8645521..4bf38d73 100644 --- a/biosys/apps/main/tests/api/test_misc.py +++ b/biosys/apps/main/tests/api/test_misc.py @@ -1,9 +1,11 @@ +from django.contrib.auth import get_user_model +from django.shortcuts import reverse from django.test import TestCase from django_dynamic_fixture import G -from django.shortcuts import reverse from rest_framework import status from rest_framework.test import APIClient -from django.contrib.auth import get_user_model + +from main.models import Project class TestWhoAmI(TestCase): @@ -80,6 +82,34 @@ def test_get(self): resp.status_code, status.HTTP_200_OK ) + # expected response with no data + expected = { + 'projects': {'total': 0}, + 'datasets': { + 'total': 0, + 'generic': {'total': 0}, + 'observation': {'total': 0}, + 'speciesObservation': {'total': 0}, + }, + 'records': { + 'total': 0, + 'generic': {'total': 0}, + 'observation': {'total': 0}, + 'speciesObservation': {'total': 0}, + } + } + self.assertEquals(expected, resp.json()) + + # create one project + G(Project) + self.assertEquals(1, Project.objects.count()) + expected['projects']['total'] = 1 + resp = client.get(self.url) + self.assertEqual( + resp.status_code, + status.HTTP_200_OK + ) + self.assertEquals(expected, resp.json()) def test_not_allowed_methods(self): user = G(get_user_model())