Exemple #1
0
    def test_data_with_decimal_scores_flag_not_bool(self):
        data = getRightData()
        data['learning_unit_years'][0]['decimal_scores'] = "NOT BOOL"

        try:
            paper_sheet.validate_data_structure(data)
            self.fail("Decimal scores allowed must be a bool")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.TypeInvalid)
Exemple #2
0
    def test_data_with_wrong_link_to_regulation(self):
        data = getRightData()
        data['link_to_regulation'] = "testnotemail"

        try:
            paper_sheet.validate_data_structure(data)
            self.fail("The link to regulation must be a valid URL")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.UrlInvalid)
    def test_data_with_decimal_scores_flag_not_bool(self):
        data = getRightData()
        data['learning_unit_years'][0]['decimal_scores'] = "NOT BOOL"

        try :
            paper_sheet.validate_data_structure(data)
            self.fail("Decimal scores allowed must be a bool")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.TypeInvalid)
    def test_data_with_no_programs_key_in_learning_unit(self):
        data = getRightData()
        del data['learning_unit_years'][0]['programs']

        try :
            paper_sheet.validate_data_structure(data)
            self.fail("Programs key must exist in learning unit years")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.RequiredFieldInvalid)
    def test_data_with_bad_value_on_learning_unit_years(self):
        data = getRightData()
        data['learning_unit_years'] = "not list" #must be a list

        try :
            paper_sheet.validate_data_structure(data)
            self.fail("The learning unit years must be a list")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.SequenceTypeInvalid)
    def test_data_with_session_number_not_integer(self):
        data = getRightData()
        data['learning_unit_years'][0]['session_number']="NOT INT"

        try :
            paper_sheet.validate_data_structure(data)
            self.fail("Session number must be an integer")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.TypeInvalid)
    def test_data_with_no_learning_unit_years(self):
        data = getRightData()
        del data['learning_unit_years']

        try :
            paper_sheet.validate_data_structure(data)
            self.fail("The learning unit years is a mandatory field")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.RequiredFieldInvalid)
    def test_data_with_wrong_link_to_regulation(self):
        data = getRightData()
        data['link_to_regulation']="testnotemail"

        try :
            paper_sheet.validate_data_structure(data)
            self.fail("The link to regulation must be a valid URL")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.UrlInvalid)
Exemple #9
0
    def test_data_with_session_number_not_integer(self):
        data = getRightData()
        data['learning_unit_years'][0]['session_number'] = "NOT INT"

        try:
            paper_sheet.validate_data_structure(data)
            self.fail("Session number must be an integer")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.TypeInvalid)
    def test_data_with_bad_value_on_enrollement_key_in_learning_unit(self):
        data = getRightData()
        data['learning_unit_years'][0]['programs'][0]['enrollments'] = "bad value"

        try:
            paper_sheet.validate_data_structure(data)
            self.fail("Enrollement key must be a list in learning unit years - programs")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0], voluptuous_error.SequenceTypeInvalid)
Exemple #11
0
    def test_data_with_bad_value_on_learning_unit_years(self):
        data = getRightData()
        data['learning_unit_years'] = "not list"  #must be a list

        try:
            paper_sheet.validate_data_structure(data)
            self.fail("The learning unit years must be a list")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0],
                                  voluptuous_error.SequenceTypeInvalid)
Exemple #12
0
    def test_data_with_no_learning_unit_years(self):
        data = getRightData()
        del data['learning_unit_years']

        try:
            paper_sheet.validate_data_structure(data)
            self.fail("The learning unit years is a mandatory field")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0],
                                  voluptuous_error.RequiredFieldInvalid)
Exemple #13
0
    def test_data_with_no_programs_key_in_learning_unit(self):
        data = getRightData()
        del data['learning_unit_years'][0]['programs']

        try:
            paper_sheet.validate_data_structure(data)
            self.fail("Programs key must exist in learning unit years")
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0],
                                  voluptuous_error.RequiredFieldInvalid)
Exemple #14
0
    def test_data_with_bad_value_on_enrollement_key_in_learning_unit(self):
        data = getRightData()
        data['learning_unit_years'][0]['programs'][0][
            'enrollments'] = "bad value"

        try:
            paper_sheet.validate_data_structure(data)
            self.fail(
                "Enrollement key must be a list in learning unit years - programs"
            )
        except voluptuous_error.Invalid as e:
            self.assertIsInstance(e.errors[0],
                                  voluptuous_error.SequenceTypeInvalid)
Exemple #15
0
def print_scores(global_id):
    json_document = get_score_sheet(global_id)
    if json_document:
        document = json.loads(json_document)
        try:
            paper_sheet.validate_data_structure(document)
            return paper_sheet.build_pdf(document)
        except (KeyError, voluptuous_error.Invalid):
            trace = traceback.format_exc()
            logger.error(trace)
            logger.warning("A document could not be produced from the json document of the global id {0}".format(global_id))
    else:
        logger.warning("A json document for the global id {0} doesn't exist.".format(global_id))
    return None
Exemple #16
0
def check_db_scores(global_id):
    scores = assessments.models.score_encoding.find_by_global_id(global_id)
    if not scores or not scores.document:
        return False

    try:
        outdated_document = is_outdated(scores.document)
    except ValueError:
        return False

    if outdated_document:
        return False

    try:
        paper_sheet.validate_data_structure(json.loads(scores.document))
        return True
    except (KeyError, voluptuous_error.Invalid):
        trace = traceback.format_exc()
        logger.error(trace)
        logger.warning("A document could not be produced from the json document of the global id {0}".format(global_id))
        return False
Exemple #17
0
 def test_valid_data(self):
     data = getRightData()
     self.assertEqual(data, paper_sheet.validate_data_structure(data))
 def test_valid_data(self):
     data = getRightData()
     self.assertEqual(data, paper_sheet.validate_data_structure(data))
 def test_data_empty(self):
     with self.assertRaises(voluptuous_error.MultipleInvalid):
         paper_sheet.validate_data_structure({})
Exemple #20
0
 def test_data_empty(self):
     with self.assertRaises(voluptuous_error.MultipleInvalid):
         paper_sheet.validate_data_structure({})