<commit_before>from __future__ import absolute_import, division, print_function, unicode_literals
import unittest

import requests_mock

from canvasapi import Canvas
from canvasapi.grading_period import GradingPeriod
from tests.util import register_uris
from tests import settings


@requests_mock.Mocker()
class TestGradingPeriod(unittest.TestCase):

    def setUp(self):
        self.canvas = Canvas(settings.BASE_URL, settings.API_KEY)

        self.grading_period = GradingPeriod(
            self.canvas._Canvas__requester,
            {"title": "grading period 1", "id": 1}
        )

    def test_str(self, m):

        test_str = str(self.grading_period)
        self.assertIsInstance(test_str, str)

    # update()
    def test_update(self, m):
        register_uris({'grading_period': ['update']}, m)

        edited_grading_period = self.grading_period.update(1, grading_period=[
            {'start_date': '2019-06-10T06:00:00Z', 'end_date': '2019-06-15T06:00:00Z'}])

        self.assertIsInstance(edited_grading_period, GradingPeriod)
        self.assertTrue(hasattr(edited_grading_period, 'title'))
        self.assertEqual(edited_grading_period.title, 'Grading period 1')
        self.assertTrue(hasattr(edited_grading_period, 'start_date'))
        self.assertTrue(hasattr(edited_grading_period, 'end_date'))
        self.assertEqual(edited_grading_period.start_date, '2019-05-23T06:00:00Z')
        self.assertEqual(edited_grading_period.end_date, '2019-08-23T06:00:00Z')

    # delete()
    def test_delete(self, m):
        register_uris({'grading_period': ['delete']}, m)
        self.assertTrue(self.grading_period.delete(1))

    def test_update_with_no_list(self, m):
        register_uris({'grading_period': ['update']}, m)

        with self.assertRaises(ValueError):
            self.grading_period.update(1, grading_period={
                'start_date': '2019-06-10T06:00:00Z', 'end_date': '2019-06-15T06:00:00Z'})
<commit_msg>Added test case to gradingPeriod.Update to check for a bad parameter without a list.<commit_after>from __future__ import absolute_import, division, print_function, unicode_literals
import unittest

import requests_mock

from canvasapi import Canvas
from canvasapi.exceptions import RequiredFieldMissing
from canvasapi.grading_period import GradingPeriod
from tests.util import register_uris
from tests import settings


@requests_mock.Mocker()
class TestGradingPeriod(unittest.TestCase):

    def setUp(self):
        self.canvas = Canvas(settings.BASE_URL, settings.API_KEY)

        self.grading_period = GradingPeriod(
            self.canvas._Canvas__requester,
            {"title": "grading period 1", "id": 1}
        )

    def test_str(self, m):

        test_str = str(self.grading_period)
        self.assertIsInstance(test_str, str)

    # update()
    def test_update(self, m):
        register_uris({'grading_period': ['update']}, m)

        edited_grading_period = self.grading_period.update(1, grading_period=[
            {'start_date': '2019-06-10T06:00:00Z', 'end_date': '2019-06-15T06:00:00Z'}])

        self.assertIsInstance(edited_grading_period, GradingPeriod)
        self.assertTrue(hasattr(edited_grading_period, 'title'))
        self.assertEqual(edited_grading_period.title, 'Grading period 1')
        self.assertTrue(hasattr(edited_grading_period, 'start_date'))
        self.assertTrue(hasattr(edited_grading_period, 'end_date'))
        self.assertEqual(edited_grading_period.start_date, '2019-05-23T06:00:00Z')
        self.assertEqual(edited_grading_period.end_date, '2019-08-23T06:00:00Z')

    # delete()
    def test_delete(self, m):
        register_uris({'grading_period': ['delete']}, m)
        self.assertTrue(self.grading_period.delete(1))

    #Check that the appropriate exception is raised when no list is given.
    def test_update_with_no_list(self, m):
        register_uris({'grading_period': ['update']}, m)

        with self.assertRaises(RequiredFieldMissing):
            self.grading_period.update(1, grading_period={
                'start_date': '2019-06-10T06:00:00Z', 'end_date': '2019-06-15T06:00:00Z'})

{'fraction_non_alphanumeric': 0.11523532265890345, 'fraction_numerical': 0.043668122270742356, 'mean_word_length': 3.8966745843230406, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6484847', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1312, 'n_words': 235}