def test_validate_application(self): global_id = self.tutor.person.global_id application_to_create = _get_application_example( self.lbir1250_2017, '30', '20') application_to_create[ 'pending'] = tutor_application_epc.UPDATE_OPERATION tutor_application.create_or_update_application(global_id, application_to_create) # Check pending state application_searched_not_validated = tutor_application.get_application( global_id, self.lbir1250_2017) self.assertEqual(application_searched_not_validated['pending'], tutor_application_epc.UPDATE_OPERATION) self.assertTrue(application_searched_not_validated['updated_at']) sleep(1) # Wait 1 sec for testing updated_at field # Validate tutor_application.validate_application( global_id, self.lbir1250_2017.acronym, self.lbir1250_2017.academic_year.year) application_searched_validated = tutor_application.get_application( global_id, self.lbir1250_2017) self.assertRaises(KeyError, lambda: application_searched_validated['pending']) self.assertTrue(application_searched_validated['updated_at']) self.assertTrue(application_searched_validated['updated_at'] > application_searched_not_validated['updated_at'])
def test_pending_flag(self): global_id = self.tutor.person.global_id application_searched = tutor_application.get_application(global_id, self.lbir1200_2017) self.assertTrue(application_searched) tutor_application.set_pending_flag(global_id, application_searched, tutor_application_epc.UPDATE_OPERATION) # Research in order to verify that have pending state application_searched = tutor_application.get_application(global_id, self.lbir1200_2017) self.assertEqual(application_searched['pending'], tutor_application_epc.UPDATE_OPERATION) self.assertTrue(application_searched['updated_at'])
def test_delete_application(self): global_id = self.tutor.person.global_id # Before delete application_searched = tutor_application.get_application(global_id, self.lbir1200_2017) self.assertTrue(application_searched) # Delete process acronym_to_delete = self.lbir1200_2017.acronym year_to_delete = self.lbir1200_2017.academic_year.year tutor_application.delete_application(global_id, acronym_to_delete, year_to_delete) # After delete application_searched = tutor_application.get_application(global_id, self.lbir1200_2017) self.assertFalse(application_searched)
def test_get_application(self): global_id = self.tutor.person.global_id application_searched = tutor_application.get_application( global_id, self.lbir1200_2017) self.assertTrue(application_searched) self.assertIsInstance(application_searched, dict) self.assertEqual(application_searched['acronym'], self.lbir1200_2017.acronym)
def create_or_update_application(request, learning_container_year_id): tutor = mdl_base.tutor.find_by_user(request.user) global_id = tutor.person.global_id learning_unit_year = mdl_base.learning_unit_year.get_full_by_learning_container_year_id( learning_container_year_id) learning_container_year = learning_unit_year.learning_container_year can_be_saved = True if request.method == 'POST': form = ApplicationForm(learning_container_year=learning_container_year, data=request.POST) if form.is_valid(): application = form.cleaned_data try: tutor_application.create_or_update_application( global_id, application) tutor_application.set_pending_flag( global_id, application, tutor_application_epc.UPDATE_OPERATION) # Send message to EPC tutor_application_epc.send_message( tutor_application_epc.UPDATE_OPERATION, global_id, application) except Exception as e: error_msg = e.args[0] messages.add_message(request, messages.ERROR, error_msg) return redirect('applications_overview') else: inital_data = tutor_application.get_application( global_id, learning_container_year) can_be_saved = tutor_application.can_be_updated( inital_data) if inital_data else True form = ApplicationForm( initial=inital_data, learning_container_year=learning_container_year, ) return layout.render( request, "application_form.html", { 'a_tutor': tutor, 'form': form, 'learning_container_year': learning_container_year, 'learning_unit_year': learning_unit_year, 'can_be_saved': can_be_saved })
def delete_application(request, learning_container_year_id): tutor = mdl_base.tutor.find_by_user(request.user) global_id = tutor.person.global_id learning_container_year = mdl_base.learning_container_year.find_by_id(learning_container_year_id) application_to_delete = tutor_application.get_application(global_id, learning_container_year) if application_to_delete: try: # Delete with FLAG Pending tutor_application.set_pending_flag(global_id, application_to_delete, tutor_application_epc.DELETE_OPERATION) # Send signal to EPC tutor_application_epc.send_message(tutor_application_epc.DELETE_OPERATION, global_id, application_to_delete) except Exception as e: error_msg = e.args[0] messages.add_message(request, messages.ERROR, error_msg) return redirect('applications_overview') raise Http404
def test_get_application_not_found(self): global_id = self.tutor.person.global_id application_searched = tutor_application.get_application(global_id, self.lagro1200_2017) self.assertFalse(application_searched)