Пример #1
0
    def test_import_cases_no_filename(self):
        self.__basic_case_setup()
        self.post_with_status_check('api/cases/export', headers=self.headers)
        # essentially add two more cases, swap contents of case 1 and 2 in case_subscriptions
        delete_cases(['case1' 'case2'])

        response = self.get_with_status_check('api/cases/import',
                                              headers=self.headers)
        expected_subs = {
            'case1': {
                'uid2': ['e1'],
                'uid1': ['e1', 'e2', 'e3']
            },
            'case3': {
                'uid4': ['d'],
                'uid3': ['e', 'b', 'c']
            },
            'case2': {
                'uid1': ['e2', 'e3']
            },
            'case4': {
                'uid1': ['a', 'b']
            }
        }
        self.assertDictEqual(response, {'cases': expected_subs})
        self.assertDictEqual(case_subs.subscriptions, expected_subs)
        for case in ['case1', 'case2', 'case3', 'case4']:
            self.__assert_subscriptions_synced(case)
Пример #2
0
 def test_import_cases_with_filename(self):
     self.__basic_case_setup()
     filename = os.path.join(tests.config.test_data_path, 'case_other.json')
     data = {"filename": filename}
     self.post_with_status_check('api/cases/export',
                                 headers=self.headers,
                                 data=json.dumps(data),
                                 content_type='application/json')
     # essentially add two more cases, swap contents of case 1 and 2 in case_subscriptions
     delete_cases(['case1' 'case2'])
     response = self.get_with_status_check('api/cases/import',
                                           headers=self.headers,
                                           data=json.dumps(data),
                                           content_type='application/json')
     expected_subs = {
         'case1': {
             'uid2': ['e1'],
             'uid1': ['e1', 'e2', 'e3']
         },
         'case3': {
             'uid4': ['d'],
             'uid3': ['e', 'b', 'c']
         },
         'case2': {
             'uid1': ['e2', 'e3']
         },
         'case4': {
             'uid1': ['a', 'b']
         }
     }
     self.assertDictEqual(response, {'cases': expected_subs})
     self.assertDictEqual(case_subs.subscriptions, expected_subs)
     for case in ['case1', 'case2', 'case3', 'case4']:
         self.__assert_subscriptions_synced(case)
Пример #3
0
 def test_delete_cases_some_existing(self):
     subs.set_subscriptions(self.cases1)
     subs.add_cases(self.cases2)
     subs.delete_cases(['case2', 'case3'])
     expected_cases = {
         'case1': self.cases1['case1'],
         'case4': self.cases2['case4']
     }
     self.assertInMemoryCasesAreCorrect(expected_cases)
     self.assertDatabaseCasesAreCorrect(set(expected_cases.keys()))
Пример #4
0
 def __func():
     case_obj = CaseSubscription.query.filter_by(id=case_id).first()
     if case_obj:
         delete_cases([case_obj.name])
         db.session.delete(case_obj)
         db.session.commit()
         current_app.logger.debug('Case deleted {0}'.format(case_id))
         return {}, SUCCESS
     else:
         current_app.logger.error(
             'Cannot delete case {0}. Case does not exist.'.format(case_id))
         return {"error": "Case does not exist."}, OBJECT_DNE_ERROR
Пример #5
0
 def __func():
     case_obj = CaseSubscription.query.filter_by(id=case_id).first()
     if case_obj:
         delete_cases([case_obj.name])
         db.session.delete(case_obj)
         db.session.commit()
         current_app.logger.debug('Case deleted {0}'.format(case_id))
         return None, NO_CONTENT
     else:
         current_app.logger.error(
             'Cannot delete case {0}. Case does not exist.'.format(case_id))
         return Problem.from_crud_resource(
             OBJECT_DNE_ERROR, 'case', 'delete',
             'Case {} does not exist.'.format(case_id))
Пример #6
0
 def test_delete_cases_all_existing_cases_is_empty(self):
     subs.set_subscriptions(self.cases1)
     subs.delete_cases(['case1', 'case2'])
     self.assertInMemoryCasesAreCorrect({})
     self.assertDatabaseCasesAreCorrect(set())
Пример #7
0
 def test_delete_cases_no_existing_cases_is_empty(self):
     subs.delete_cases(['case1', 'case2'])
     self.assertInMemoryCasesAreCorrect({})
     self.assertDatabaseCasesAreCorrect(set())