Commit 5971ac6a by Clinton Blackburn

Reorganized Tests

test_views was too big.
parent ca57a8c4
......@@ -2,6 +2,7 @@
# NOTE: Full URLs are used throughout these tests to ensure that the API contract is fulfilled. The URLs should *not*
# change for versions greater than 1.0.0. Tests target a specific version of the API, additional tests should be added
# for subsequent versions if there are breaking changes introduced in those versions.
import StringIO
import csv
import datetime
......@@ -12,14 +13,11 @@ from django.conf import settings
from django_dynamic_fixture import G
import pytz
from opaque_keys.edx.keys import CourseKey
from analytics_data_api.constants.country import get_country
from analytics_data_api.constants.country import get_country
from analytics_data_api.v0 import models
from analytics_data_api.constants import country, enrollment_modes, genders
from analytics_data_api.v0.models import CourseActivityWeekly
from analytics_data_api.v0.serializers import ProblemResponseAnswerDistributionSerializer
from analytics_data_api.v0.serializers import GradeDistributionSerializer
from analytics_data_api.v0.serializers import SequentialOpenDistributionSerializer
from analytics_data_api.v0.tests.utils import flatten
from analyticsdataserver.tests import TestCaseWithAuthentication
......@@ -390,37 +388,6 @@ class CourseEnrollmentByGenderViewTests(CourseEnrollmentViewTestCaseMixin, Defau
self.assertViewReturnsExpectedData(expected)
# pylint: disable=no-member,no-value-for-parameter
class AnswerDistributionTests(TestCaseWithAuthentication):
path = '/answer_distribution/'
maxDiff = None
@classmethod
def setUpClass(cls):
cls.course_id = "org/num/run"
cls.module_id = "i4x://org/num/run/problem/RANDOMNUMBER"
cls.part_id1 = "i4x-org-num-run-problem-RANDOMNUMBER_2_1"
cls.ad1 = G(
models.ProblemResponseAnswerDistribution,
course_id=cls.course_id,
module_id=cls.module_id,
part_id=cls.part_id1
)
def test_get(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % (self.module_id, self.path))
self.assertEquals(response.status_code, 200)
expected_dict = ProblemResponseAnswerDistributionSerializer(self.ad1).data
actual_list = response.data
self.assertEquals(len(actual_list), 1)
self.assertDictEqual(actual_list[0], expected_dict)
def test_get_404(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % ("DOES-NOT-EXIST", self.path))
self.assertEquals(response.status_code, 404)
class CourseEnrollmentViewTests(CourseEnrollmentViewTestCaseMixin, TestCaseWithAuthentication):
model = models.CourseEnrollmentDaily
path = '/enrollment'
......@@ -626,61 +593,3 @@ class CourseActivityWeeklyViewTests(CourseViewTestCaseMixin, TestCaseWithAuthent
expected = self.format_as_response(*self.model.objects.all())
self.assertEqual(len(expected), 2)
self.assertIntervalFilteringWorks(expected, self.interval_start, interval_end + datetime.timedelta(days=1))
# pylint: disable=no-member,no-value-for-parameter
class GradeDistributionTests(TestCaseWithAuthentication):
path = '/grade_distribution/'
maxDiff = None
@classmethod
def setUpClass(cls):
cls.course_id = "org/class/test"
cls.module_id = "i4x://org/class/test/problem/RANDOM_NUMBER"
cls.ad1 = G(
models.GradeDistribution,
course_id=cls.course_id,
module_id=cls.module_id,
)
def test_get(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % (self.module_id, self.path))
self.assertEquals(response.status_code, 200)
expected_dict = GradeDistributionSerializer(self.ad1).data
actual_list = response.data
self.assertEquals(len(actual_list), 1)
self.assertDictEqual(actual_list[0], expected_dict)
def test_get_404(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % ("DOES-NOT-EXIST", self.path))
self.assertEquals(response.status_code, 404)
# pylint: disable=no-member,no-value-for-parameter
class SequentialOpenDistributionTests(TestCaseWithAuthentication):
path = '/sequential_open_distribution/'
maxDiff = None
@classmethod
def setUpClass(cls):
cls.course_id = "org/class/test"
cls.module_id = "i4x://org/class/test/problem/RANDOM_NUMBER"
cls.ad1 = G(
models.SequentialOpenDistribution,
course_id=cls.course_id,
module_id=cls.module_id,
)
def test_get(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % (self.module_id, self.path))
self.assertEquals(response.status_code, 200)
expected_dict = SequentialOpenDistributionSerializer(self.ad1).data
actual_list = response.data
self.assertEquals(len(actual_list), 1)
self.assertDictEqual(actual_list[0], expected_dict)
def test_get_404(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % ("DOES-NOT-EXIST", self.path))
self.assertEquals(response.status_code, 404)
# coding=utf-8
# NOTE: Full URLs are used throughout these tests to ensure that the API contract is fulfilled. The URLs should *not*
# change for versions greater than 1.0.0. Tests target a specific version of the API, additional tests should be added
# for subsequent versions if there are breaking changes introduced in those versions.
# pylint: disable=no-member,no-value-for-parameter
from django_dynamic_fixture import G
from analytics_data_api.v0 import models
from analytics_data_api.v0.serializers import ProblemResponseAnswerDistributionSerializer, \
GradeDistributionSerializer, SequentialOpenDistributionSerializer
from analyticsdataserver.tests import TestCaseWithAuthentication
class AnswerDistributionTests(TestCaseWithAuthentication):
path = '/answer_distribution/'
maxDiff = None
@classmethod
def setUpClass(cls):
cls.course_id = "org/num/run"
cls.module_id = "i4x://org/num/run/problem/RANDOMNUMBER"
cls.part_id1 = "i4x-org-num-run-problem-RANDOMNUMBER_2_1"
cls.ad1 = G(
models.ProblemResponseAnswerDistribution,
course_id=cls.course_id,
module_id=cls.module_id,
part_id=cls.part_id1
)
def test_get(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % (self.module_id, self.path))
self.assertEquals(response.status_code, 200)
expected_dict = ProblemResponseAnswerDistributionSerializer(self.ad1).data
actual_list = response.data
self.assertEquals(len(actual_list), 1)
self.assertDictEqual(actual_list[0], expected_dict)
def test_get_404(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % ("DOES-NOT-EXIST", self.path))
self.assertEquals(response.status_code, 404)
class GradeDistributionTests(TestCaseWithAuthentication):
path = '/grade_distribution/'
maxDiff = None
@classmethod
def setUpClass(cls):
cls.course_id = "org/class/test"
cls.module_id = "i4x://org/class/test/problem/RANDOM_NUMBER"
cls.ad1 = G(
models.GradeDistribution,
course_id=cls.course_id,
module_id=cls.module_id,
)
def test_get(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % (self.module_id, self.path))
self.assertEquals(response.status_code, 200)
expected_dict = GradeDistributionSerializer(self.ad1).data
actual_list = response.data
self.assertEquals(len(actual_list), 1)
self.assertDictEqual(actual_list[0], expected_dict)
def test_get_404(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % ("DOES-NOT-EXIST", self.path))
self.assertEquals(response.status_code, 404)
class SequentialOpenDistributionTests(TestCaseWithAuthentication):
path = '/sequential_open_distribution/'
maxDiff = None
@classmethod
def setUpClass(cls):
cls.course_id = "org/class/test"
cls.module_id = "i4x://org/class/test/problem/RANDOM_NUMBER"
cls.ad1 = G(
models.SequentialOpenDistribution,
course_id=cls.course_id,
module_id=cls.module_id,
)
def test_get(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % (self.module_id, self.path))
self.assertEquals(response.status_code, 200)
expected_dict = SequentialOpenDistributionSerializer(self.ad1).data
actual_list = response.data
self.assertEquals(len(actual_list), 1)
self.assertDictEqual(actual_list[0], expected_dict)
def test_get_404(self):
response = self.authenticated_get('/api/v0/problems/%s%s' % ("DOES-NOT-EXIST", self.path))
self.assertEquals(response.status_code, 404)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment