def test_add_class_with_recordings(self):
        """ Add a class to a dataset and also add some recordings to it """

        dsid = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        test_data = {
            "name": "Class #3",
            "description": "This is description of class 3",
            "recordings": ["1c085555-3805-428a-982f-e14e0a2b18e6"]
        }
        dataset.add_class(dsid, test_data)
        updateddataset = dataset.get(dsid)

        # Check that both the class details and recordings are in the retrieved dataset
        expected = copy.deepcopy(test_data)
        expected["id"] = mock.ANY
        self.assertDictEqual(expected, updateddataset["classes"][2])
    def test_add_class_with_recordings(self):
        """ Add a class to a dataset and also add some recordings to it """

        dsid = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        test_data = {
            "name": "Class #3",
            "description": "This is description of class 3",
            "recordings": ["1c085555-3805-428a-982f-e14e0a2b18e6"]
        }
        dataset.add_class(dsid, test_data)
        updateddataset = dataset.get(dsid)

        # Check that both the class details and recordings are in the retrieved dataset
        expected = copy.deepcopy(test_data)
        expected["id"] = mock.ANY
        self.assertDictEqual(expected, updateddataset["classes"][2])
    def test_add_class_twice(self):
        """ A class name which already exists is skipped. """
        dsid = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        test_data = {
            "name": "Class #1",
            "description": "This is description of class 1",
            "recordings": ["1c085555-3805-428a-982f-e14e0a2b18e6"]
        }
        dataset.add_class(dsid, test_data)
        updateddataset = dataset.get(dsid)

        # Class #1 is not added again, but the recording is added to it
        self.assertEqual(2, len(updateddataset["classes"]))
        expected_recordings = ["0dad432b-16cc-4bf0-8961-fd31d124b01b",
                               "19e698e7-71df-48a9-930e-d4b1a2026c82",
                               "1c085555-3805-428a-982f-e14e0a2b18e6"]
        self.assertEqual(set(expected_recordings), set(updateddataset["classes"][0]["recordings"]))
    def test_add_class_twice(self):
        """ A class name which already exists is skipped. """
        dsid = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        test_data = {
            "name": "Class #1",
            "description": "This is description of class 1",
            "recordings": ["1c085555-3805-428a-982f-e14e0a2b18e6"]
        }
        dataset.add_class(dsid, test_data)
        updateddataset = dataset.get(dsid)

        # Class #1 is not added again, but the recording is added to it
        self.assertEqual(2, len(updateddataset["classes"]))
        expected_recordings = ["0dad432b-16cc-4bf0-8961-fd31d124b01b",
                               "19e698e7-71df-48a9-930e-d4b1a2026c82",
                               "1c085555-3805-428a-982f-e14e0a2b18e6"]
        self.assertEqual(set(expected_recordings), set(updateddataset["classes"][0]["recordings"]))
    def test_add_class(self):
        """ Add a class to a dataset """

        dsid = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        test_data = {
            "name": "Class #3",
            "description": "This is the description of class 3"
        }

        originaldataset = dataset.get(dsid)
        dataset.add_class(dsid, test_data)
        updateddataset = dataset.get(dsid)

        self.assertEqual(2, len(originaldataset["classes"]))
        self.assertEqual(3, len(updateddataset["classes"]))
        expected = copy.deepcopy(test_data)
        expected["recordings"] = []
        expected["id"] = mock.ANY
        self.assertDictEqual(expected, updateddataset["classes"][2])
    def test_add_class(self):
        """ Add a class to a dataset """

        dsid = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        test_data = {
            "name": "Class #3",
            "description": "This is the description of class 3"
        }

        originaldataset = dataset.get(dsid)
        dataset.add_class(dsid, test_data)
        updateddataset = dataset.get(dsid)

        self.assertEqual(2, len(originaldataset["classes"]))
        self.assertEqual(3, len(updateddataset["classes"]))
        expected = copy.deepcopy(test_data)
        expected["recordings"] = []
        expected["id"] = mock.ANY
        self.assertDictEqual(expected, updateddataset["classes"][2])