コード例 #1
0
 def test_no_locking_profiles_raises_exception(self):
     no_profiles = [[row[0]] for row in self.locking_profiles]
     xls = self._construct_xls_for_import(KOBO_LOCK_SHEET, no_profiles)
     try:
         get_kobo_locking_profiles(xls)
     except FormPackLibraryLockingError as e:
         assert str(e) == 'At least one locking profile must be defined.'
コード例 #2
0
 def test_restriction_column_missing_raises_exception(self):
     locking_profiles = self.locking_profiles
     locking_profiles[0][0] = 'something_other_than_restriction'
     xls = self._construct_xls_for_import(KOBO_LOCK_SHEET, locking_profiles)
     try:
         get_kobo_locking_profiles(xls)
     except FormPackLibraryLockingError as e:
         assert str(e) == 'The column name `restriction` must be present.'
コード例 #3
0
 def test_locking_profile_name_is_locked_raises_exception(self):
     locking_profiles = self.locking_profiles
     locking_profiles[0][1] = 'locked'
     xls = self._construct_xls_for_import(KOBO_LOCK_SHEET, locking_profiles)
     try:
         get_kobo_locking_profiles(xls)
     except FormPackLibraryLockingError as e:
         assert str(e) == 'Locking profile name of "locked" cannot be used.'
コード例 #4
0
 def test_invalid_restriction_raises_exception(self):
     locking_profiles = self.locking_profiles
     locking_profiles.append(
         ['invalid_restriction', 'locked', 'locked', 'locked'])
     xls = self._construct_xls_for_import(KOBO_LOCK_SHEET, locking_profiles)
     try:
         get_kobo_locking_profiles(xls)
     except FormPackLibraryLockingError as e:
         assert str(e) == 'invalid_restriction is not a valid restriction.'
コード例 #5
0
    def test_get_kobo_locking_profiles(self):
        expected_locking_profiles = [
            {
                'name':
                'core',
                'restrictions': [
                    'choice_add',
                    'choice_order_edit',
                    'question_delete',
                    'question_label_edit',
                    'question_settings_edit',
                    'question_skip_logic_edit',
                    'question_validation_edit',
                    'group_delete',
                    'group_question_add',
                    'group_question_delete',
                    'group_question_order_edit',
                    'group_settings_edit',
                    'group_skip_logic_edit',
                    'group_split',
                    'form_replace',
                    'group_add',
                    'question_add',
                    'question_order_edit',
                    'language_edit',
                    'form_appearance',
                ],
            },
            {
                'name':
                'delete',
                'restrictions': [
                    'choice_delete',
                    'question_delete',
                    'group_delete',
                    'group_question_delete',
                ],
            },
            {
                'name':
                'flex',
                'restrictions': [
                    'choice_add',
                    'question_delete',
                    'question_label_edit',
                    'question_settings_edit',
                    'question_skip_logic_edit',
                    'question_validation_edit',
                    'group_question_add',
                    'group_question_delete',
                    'group_question_order_edit',
                    'group_settings_edit',
                    'group_skip_logic_edit',
                    'group_split',
                ],
            },
        ]

        xls = self._construct_xls_for_import(KOBO_LOCK_SHEET,
                                             self.locking_profiles)
        actual_locking_profiles = get_kobo_locking_profiles(xls)
        for profiles in expected_locking_profiles:
            name = profiles['name']
            expected_restrictions = profiles['restrictions']
            actual_restrictions = [
                val['restrictions'] for val in actual_locking_profiles
                if val['name'] == name
            ][0]
            assert expected_restrictions == actual_restrictions
コード例 #6
0
    def test_revert_kobo_lock_structure(self):
        expected_reverted_locking_profiles = [
            {
                'restriction': 'choice_add',
                'core': 'locked',
                'flex': 'locked'
            },
            {
                'restriction': 'choice_delete',
                'delete': 'locked'
            },
            {
                'restriction': 'choice_label_edit'
            },
            {
                'restriction': 'choice_value_edit'
            },
            {
                'restriction': 'choice_order_edit',
                'core': 'locked'
            },
            {
                'restriction': 'question_delete',
                'core': 'locked',
                'flex': 'locked',
                'delete': 'locked',
            },
            {
                'restriction': 'question_label_edit',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'question_settings_edit',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'question_skip_logic_edit',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'question_validation_edit',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'group_delete',
                'core': 'locked',
                'delete': 'locked',
            },
            {
                'restriction': 'group_split',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'group_label_edit'
            },
            {
                'restriction': 'group_question_add',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'group_question_delete',
                'core': 'locked',
                'flex': 'locked',
                'delete': 'locked',
            },
            {
                'restriction': 'group_question_order_edit',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'group_settings_edit',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'group_skip_logic_edit',
                'core': 'locked',
                'flex': 'locked',
            },
            {
                'restriction': 'form_replace',
                'core': 'locked'
            },
            {
                'restriction': 'group_add',
                'core': 'locked'
            },
            {
                'restriction': 'question_add',
                'core': 'locked'
            },
            {
                'restriction': 'question_order_edit',
                'core': 'locked'
            },
            {
                'restriction': 'language_edit',
                'core': 'locked'
            },
            {
                'restriction': 'form_appearance',
                'core': 'locked'
            },
            {
                'restriction': 'form_meta_edit'
            },
        ]
        xls = self._construct_xls_for_import(KOBO_LOCK_SHEET,
                                             self.locking_profiles)
        actual_reverted_locks = {
            KOBO_LOCK_SHEET: get_kobo_locking_profiles(xls)
        }
        revert_kobo_lock_structure(actual_reverted_locks)

        def _get_sorted_restrictions(restrictions):
            return sorted(restrictions, key=lambda k: k['restriction'])

        actual = _get_sorted_restrictions(
            actual_reverted_locks[KOBO_LOCK_SHEET])
        expected = _get_sorted_restrictions(expected_reverted_locking_profiles)
        assert len(actual) == len(expected)
        assert actual == expected
コード例 #7
0
def _append_kobo_locking_profiles(base64_encoded_upload: BytesIO,
                                  survey_dict: dict) -> None:
    decoded_bytes = base64.b64decode(base64_encoded_upload)
    kobo_locks = get_kobo_locking_profiles(BytesIO(decoded_bytes))
    if kobo_locks:
        survey_dict[KOBO_LOCK_SHEET] = kobo_locks