def test_update_malformed(self):
        id = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        bad_dataset = copy.deepcopy(self.test_data)

        bad_dataset["classes"][0]["name"] = None
        with self.assertRaises(dataset_validator.ValidationException):
            dataset.update(dataset_id=id, dictionary=bad_dataset, author_id=self.test_user_id)

        bad_dataset["classes"][0]["name"] = ""
        with self.assertRaises(dataset_validator.ValidationException):
            dataset.update(dataset_id=id, dictionary=bad_dataset, author_id=self.test_user_id)
 def test_last_edited(self):
     id = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
     ds = dataset.get(id)
     self.assertEqual(ds['created'], ds['last_edited'])
     with db.engine.begin() as connection:
         connection.execute("""UPDATE dataset SET last_edited = now() - interval %s where id = %s""",
                 ('1 hour', id))
     ds = dataset.get(id)
     self.assertTrue(ds['created'] > ds['last_edited'])
     dataset.update(id, self.test_data, author_id=self.test_user_id)
     ds_updated = dataset.get(id)
     self.assertTrue(ds_updated['last_edited'] > ds['last_edited'])
    def test_update(self):
        id = dataset.create_from_dict(self.test_data, author_id=self.test_user_id)
        updated_dict = copy.deepcopy(self.test_data)
        updated_dict["classes"][0]["recordings"] = []  # Removing recordings from first class
        dataset.update(
            dataset_id=id,
            dictionary=updated_dict,
            author_id=self.test_user_id,
        )

        ds = dataset.get(id)
        # First class shouldn't have any recordings
        self.assertEqual(len(ds["classes"][0]["recordings"]), 0)
        self.assertEqual(len(ds["classes"][1]["recordings"]), 3)