def get_repository_manager(): request = SimpleRequest(username='******') condition = PROXY_SESSION.get_proxy_condition() condition.set_http_request(request) proxy = PROXY_SESSION.get_proxy(condition) return RUNTIME.get_service_manager( 'REPOSITORY', implementation='TEST_SERVICE_FILESYSTEM', proxy=proxy)
def get_repository_manager(): condition = PROXY_SESSION.get_proxy_condition() dummy_request = SimpleRequest(username=web.ctx.env.get( 'HTTP_X_API_PROXY', '*****@*****.**'), authenticated=True) condition.set_http_request(dummy_request) if 'HTTP_X_API_LOCALE' in web.ctx.env: language_code = web.ctx.env['HTTP_X_API_LOCALE'].lower() if language_code in ['en', 'hi', 'te']: if language_code == 'en': language_code = 'ENG' script_code = 'LATN' elif language_code == 'hi': language_code = 'HIN' script_code = 'DEVA' else: language_code = 'TEL' script_code = 'TELU' else: language_code = DEFAULT_LANGUAGE_TYPE.identifier script_code = DEFAULT_SCRIPT_TYPE.identifier locale = InitializableLocale(language_type_identifier=language_code, script_type_identifier=script_code) condition.set_locale(locale) proxy = PROXY_SESSION.get_proxy(condition) return RUNTIME.get_service_manager('REPOSITORY', proxy=proxy)
def get_assessment_manager(): request = SimpleRequest(username='******') condition = PROXY_SESSION.get_proxy_condition() condition.set_http_request(request) proxy = PROXY_SESSION.get_proxy(condition) return RUNTIME.get_service_manager( 'ASSESSMENT', implementation='TEST_SERVICE_FILESYSTEM', proxy=proxy)
def get_logging_manager(): condition = PROXY_SESSION.get_proxy_condition() dummy_request = SimpleRequest(username=web.ctx.env.get( 'HTTP_X_API_PROXY', '*****@*****.**'), authenticated=True) condition.set_http_request(dummy_request) proxy = PROXY_SESSION.get_proxy(condition) return RUNTIME.get_service_manager('LOGGING', proxy=proxy)
def populate_grade_entries(self, gradebook, column): self._scores = [] for num in range(0, 100): username = '******'.format(num) request = SimpleRequest(username=username) gm = get_manager(request, 'grading') form = gradebook.get_grade_entry_form_for_create( column.ident, gm.effective_agent_id, []) form.set_score(float(num)) gradebook.create_grade_entry(form) self._scores.append(Decimal(num))
def upload_class(path, domain_repo, user): """use DysonX to parse and upload the class""" request = SimpleRequest(username=user.username) if not settings.TEST and settings.MEDIA_ROOT not in path: if '/' != path[0]: path = '/' + path path = ABS_PATH + path path = clean_up_path(path) dyson = DysonXUtil(request=request) return dyson.vacuum(path, domain_repo=domain_repo, user=user)
def get_agent_id(agent_id): """Not a great hack...depends too much on internal DLKit knowledge""" if '@mit.edu' not in agent_id: agent_id += '@mit.edu' test_request = SimpleRequest(agent_id) condition = PROXY_SESSION.get_proxy_condition() condition.set_http_request(test_request) proxy = PROXY_SESSION.get_proxy(condition) resm = RUNTIME.get_service_manager( 'RESOURCE', implementation='TEST_SERVICE_FUNCTIONAL', proxy=proxy) return resm.effective_agent_id
def create_test_request(test_user): # from django.http import HttpRequest # from django.conf import settings # from django.utils.importlib import import_module # #http://stackoverflow.com/questions/16865947/django-httprequest-object-has-no-attribute-session # test_request = HttpRequest() # engine = import_module(settings.SESSION_ENGINE) # session_key = None # test_request.user = test_user # test_request.session = engine.SessionStore(session_key) # return test_request return SimpleRequest(username=test_user.username)
def get_managers(username='******'): managers = [('am', 'ASSESSMENT'), ('authzm', 'AUTHORIZATION'), ('logm', 'LOGGING'), ('rm', 'REPOSITORY')] results = {} for manager in managers: nickname = manager[0] service_name = manager[1] condition = PROXY_SESSION.get_proxy_condition() dummy_request = SimpleRequest(username=username, authenticated=True) condition.set_http_request(dummy_request) proxy = PROXY_SESSION.get_proxy(condition) results[nickname] = RUNTIME.get_service_manager(service_name, proxy=proxy) return results
def setUp(self): for db in self.dbs_to_delete: self._delete_database(db) load_fixtures() self.url = '/api/v2/repository/' self.username = '******' self.instructor_req = SimpleRequest(self.username) self.student_name = '*****@*****.**' self.student_req = SimpleRequest(self.student_name) self.unauthenticated_req = SimpleRequest(self.username, authenticated=False) self.req = self.instructor_req self.test_file1 = open(ABS_PATH + '/files/test_file_1.txt', 'rb') self.test_file2 = open(ABS_PATH + '/files/test_file_2.txt', 'rb') if os.path.isdir(TEST_DATA_STORE_PATH): shutil.rmtree(TEST_DATA_STORE_PATH) if not os.path.isdir(TEST_DATA_STORE_PATH): os.makedirs(TEST_DATA_STORE_PATH)
def get_object_bank_from_request(request): """parse out the right params before passing to get_object_bank Do NOT use the convenience methods here with session, etc.""" valid_params = ['/assessment/items/'] path = request.path if any(p in path for p in valid_params): test_request = SimpleRequest(username=request.user.username) condition = PROXY_SESSION.get_proxy_condition() condition.set_http_request(test_request) proxy = PROXY_SESSION.get_proxy(condition) am = RUNTIME.get_service_manager('ASSESSMENT', proxy=proxy) try: if '/items/' in path: object_id = path.split('/items/')[-1] return get_object_bank(am, object_id, object_type='item') except NotFound: return None else: return None
def on_success(self, retval, task_id, targs, tkwargs): """ :param retval: :param task_id: :param targs: :param tkwargs: :return: """ if not settings.TEST and settings.ENABLE_NOTIFICATIONS: test_request = SimpleRequest(username=targs[2].username) rabbit = RabbitMQReceiver(request=test_request) rabbit._pub_wrapper( 'new', obj_type='repositories', id_list=["Upload successful. You may now view your course."], status='success') default_storage.delete(targs[0]) extracted_path = targs[0].replace('.zip', '').replace('.tar.gz', '') if os.path.isdir(extracted_path): shutil.rmtree(extracted_path)
def on_failure(self, exc, task_id, targs, tkwargs, einfo): """ :param exc: :param task_id: :param args: path, domain_repo, user (args to import_file) :param kwargs: :param einfo: Traceback (str(einfo)) :return: """ if not settings.TEST and settings.ENABLE_NOTIFICATIONS: test_request = SimpleRequest(username=targs[2].username) rabbit = RabbitMQReceiver(request=test_request) msg = 'Import of {0} raised exception: {1!r}'.format( targs[0].split('/')[-1], str(exc)) rabbit._pub_wrapper('new', obj_type='repositories', id_list=[msg], status='error') default_storage.delete(targs[0]) extracted_path = targs[0].replace('.zip', '').replace('.tar.gz', '') if os.path.isdir(extracted_path): shutil.rmtree(extracted_path)