def test_applicant_contact_should_not_fail_when_user_email_not_found(self): # change user email to some new random value self.user.email = get_random_string( 7) + '@bug719.eresearchtest.monash.edu' self.user.save() for pc in self.test_data.get('project_contacts', []): contact = pc.get('contact', None) if contact: self.assertNotEqual(self.user.email, pc.get(contact.get('email', None)), 'Random email matches contact email') try: contactObj = Contact.objects.get(email=self.user.email) self.assertIsNone( contactObj, 'Random Contact should not exist for email id ' + self.user.email) except Contact.DoesNotExist: pass except Contact.MultipleContactExists: self.assertIsNotNone( None, 'Multiple contact exists with random email id ' + self.user.email) # Create should complete successfully self._create_project_common(self.test_data)
def setup_random_update(cls, project_data, update_fn): instances = 4 cores = 4 quota = 4000 project_data['notes'] = get_random_string( 8) + ' - ' + project_data.get('description', '') for request_data in project_data.get("requests", []): # update compute compute_requests = request_data.get('compute_requests', None) if compute_requests: count = 0 for c in compute_requests: count += 1 c["instances"] = instances * count c["cores"] = cores * count # update storage storage_requests = request_data.get('storage_requests', None) if storage_requests: count = 0 for s in storage_requests: count += 1 s["quota"] = quota * count return update_fn(request_data, instances, cores, quota)
def test_applicant_contact_should_not_fail_when_user_email_not_found( self): # change user email to some new random value self.user.email = get_random_string( 7) + '@bug719.eresearchtest.monash.edu' self.user.save() for pc in self.test_data.get('project_contacts', []): contact = pc.get('contact', None) if contact: self.assertNotEqual(self.user.email, pc.get(contact.get( 'email', None)), 'Random email matches contact email') try: contactObj = Contact.objects.get(email=self.user.email) self.assertIsNone( contactObj, 'Random Contact should not exist for email id ' + self.user.email) except Contact.DoesNotExist: pass except Contact.MultipleContactExists: self.assertIsNotNone( None, 'Multiple contact exists with random email id ' + self.user.email) # Create should complete successfully self._create_project_common(self.test_data)
def setup_new_user(self): username = api_utils.get_random_string(12) self.user = self.get_new_user(username, username + '@crams.tst') self.token, created = CramsToken.objects.get_or_create(user=self.user) self.user_contact, created = Contact.objects.get_or_create( title='Mr', given_name='Test', surname='MeRC', email=self.user.email, phone='99020780', organisation='Monash University')
def add_required_project_ids(self, project_json, required_sysid_list): project_ids = project_json.get('project_ids') system_list = set() for pid_json in project_ids: system_name = pid_json.get('system').get('system') system_list.add(system_name) for sys in required_sysid_list.difference(system_list): project_ids.append({ "identifier": api_utils.get_random_string(12), "system": self.system_id_map.get(sys), })
def test_fail_update_static_fields_after_approve(self): def _updateFailFn(response): self.assertEqual( response.status_code, status.HTTP_400_BAD_REQUEST, 'update after approve for description should fail : {}'.format( response.data)) testCount = self.PROVISION_PROJECT_RETURN_PROJECT response = self.flowUpTo(testCount) project = response.data project['description'] = 'New Description ' + get_random_string(64) self.update_response_data_random(project, _updateFailFn)
def setup_new_user(self): username = api_utils.get_random_string(12) self.user = self.get_new_user(username, username + '@crams.tst') self.token, created = CramsToken.objects.get_or_create(user=self.user)
def get_project_only_no_request_data(user_id, contact_obj): """ Project only data :param user_id: :param contact_obj: :return: """ return { "title": "Creating project testing1", "description": "Creating project testing1", "project_question_responses": [ { "question_response": "Tom, Jack", "question": { "key": "additionalresearchers" } }, { "question_response": "nectar supporting", "question": { "key": "nectarvls" } }, { "question_response": "ncris supporting", "question": { "key": "ncris" } } ], "institutions": [ { "institution": "Monash" } ], "publications": [ { "reference": "pub1" } ], "grants": [ { "grant_type": { "id": 1 }, "funding_body_and_scheme": "arc tests funding", "grant_id": "arc-001", "start_year": 2014, "duration": 304, "total_funding": 200 } ], "project_ids": [ { "identifier": 'nec_' + utils.get_random_string(11), "system": { "id": 1, "system": "NeCTAR" }, "type": "R" } ], "project_contacts": [ { "contact": { "id": contact_obj.id, "email": contact_obj.email }, "contact_role": { "id": 2 } } ], "domains": [ { "percentage": 100, "for_code": { "id": 1 } } ], "created_by": { "id": user_id }, "updated_by": { "id": user_id } }
def get_base_nectar_project_data(user_id, contact_obj, proj_ids=None): """ Nectar Project Data :param user_id: :param contact_obj: :return: """ system_map = dbUtils.get_system_name_map() ret_data = { "title": "Creating allocation request testing1", "description": "Creating allocation request testing1", "project_question_responses": [ {"question_response": "Tom, Jack", "question": { "key": "additionalresearchers" } }, { "question_response": "nectar supporting", "question": {"key": "nectarvls"} }, { "question_response": "ncris supporting", "question": {"key": "ncris"} } ], "institutions": [{"institution": "Monash"}], "publications": [{"reference": "pub1"}], "grants": [{"grant_type": {"id": 1}, "funding_body_and_scheme": "arc tests funding", "grant_id": "arc-001", "start_year": 2014, "duration": 57, "total_funding": 200}], "project_contacts": [{ "contact": { "id": contact_obj.id, "email": contact_obj.email }, "contact_role": {"id": 2}}], "domains": [{ "percentage": 100, "for_code": {"id": 1}}], "requests": [ { "compute_requests": [{ "instances": 21, "approved_instances": 12, "cores": 32, "approved_cores": 22, "core_hours": 744, "approved_core_hours": 744, "compute_product": {"id": 1}, "compute_question_responses": [] }], "storage_requests": [ {"quota": 22, "approved_quota": 12, "storage_product": {"id": 3, "name": "Nectar Volume (Monash)"}, "storage_question_responses": [] } ], "request_question_responses": [ {"question_response": "1", "question": {"key": "duration"}}, {"question_response": "False", "question": {"key": "ptconversion"}}, { "question_response": "Some Question Response", "question": {"key": "researchcase"}}, { "question_response": "Creating allocation request " "testing1 patterns", "question": {"key": "usagepattern"}}, {"question_response": "Monash", "question": {"key": "homenode"}}, {"question_response": "Monash Node", "question": {"key": "homerequirements"}}, {"question_response": 20000, "question": {"key": "estimatedusers"} }], "request_status": {"id": 1}, "funding_scheme": {"id": 1}, "start_date": "2015-11-25", "end_date": "2015-12-25", "created_by": {"id": user_id}, "updated_by": {"id": user_id}, "approval_notes": "" } ] } if not proj_ids: ret_data["project_ids"] = [{ "identifier": 'nec_' + utils.get_random_string(11), "system": system_map.get(DBConstants.SYSTEM_NECTAR), }] else: ret_data["project_ids"] = proj_ids return ret_data
def get_vicnode_test_data(user_id, contact_obj): """ Vicnode Test Data :param user_id: :param contact_obj: :return: """ return { "title": "Test Collection", "description": "Test Collection Description", "project_question_responses": [], "institutions": [], "publications": [], "grants": [], "project_ids": [{ "identifier": 'vic_' + utils.get_random_string(11), "system": { "id": 2 } }], "project_contacts": [{ "contact": { "id": contact_obj.id, "email": contact_obj.email }, "contact_role": { "id": 2 } }], "domains": [{ "percentage": 100, "for_code": { "id": 186 } }], "requests": [{ "compute_requests": [], "storage_requests": [{ "quota": 120, "approved_quota": 120, "storage_product": { "id": 15, "name": "VicNode Vault (Monash)" }, "storage_question_responses": [{ "question_response": 10, "question": { "key": "vn_current_size" } }] }], "request_question_responses": [{ "question_response": "Yes", "question": { "key": "vn_authorization" } }, { "question_response": "On a PC", "question": { "key": "vn_data_migration_src" } }, { "question_response": "Yes", "question": { "key": "vn_data_migration_assistance" } }, { "question_response": "via a PC", "question": { "key": "vn_current_access_method" } }, { "question_response": "Direct access via a PC", "question": { "key": "vn_preferred_access_method" } }, { "question_response": ".txt", "question": { "key": "vn_data_format" } }, { "question_response": "Yes", "question": { "key": "vn_only_copy" } }, { "question_response": "Irreplaceable", "question": { "key": "vn_can_be_regenerated" } }, { "question_response": "Lose job.", "question": { "key": "vn_loss_impact" } }], "request_status": { "id": 1 }, "funding_scheme": { "id": 2 }, "start_date": "2016-01-01", "end_date": "2017-01-01", "created_by": { "id": user_id }, "updated_by": { "id": user_id }, "approval_notes": "", "paent_request": None }] }
def get_project_only_no_request_data(user_id, contact_obj): """ Project only data :param user_id: :param contact_obj: :return: """ return { "title": "Creating project testing1", "description": "Creating project testing1", "project_question_responses": [{ "question_response": "Tom, Jack", "question": { "key": "additionalresearchers" } }, { "question_response": "nectar supporting", "question": { "key": "nectarvls" } }, { "question_response": "ncris supporting", "question": { "key": "ncris" } }], "institutions": [{ "institution": "Monash" }], "publications": [{ "reference": "pub1" }], "grants": [{ "grant_type": { "id": 1 }, "funding_body_and_scheme": "arc tests funding", "grant_id": "arc-001", "start_year": 2014, "total_funding": 200 }], "project_ids": [{ "identifier": 'nec_' + utils.get_random_string(11), "system": { "id": 1, "system": "NeCTAR" }, "type": "R" }], "project_contacts": [{ "contact": { "id": contact_obj.id, "email": contact_obj.email }, "contact_role": { "id": 2 } }], "domains": [{ "percentage": 100, "for_code": { "id": 1 } }], "created_by": { "id": user_id }, "updated_by": { "id": user_id } }
def get_base_nectar_project_data(user_id, contact_obj, proj_ids=None): """ Nectar Project Data :param user_id: :param contact_obj: :return: """ system_map = dbUtils.get_system_name_map() ret_data = { "title": "Creating allocation request testing1", "description": "Creating allocation request testing1", "project_question_responses": [{ "question_response": "Tom, Jack", "question": { "key": "additionalresearchers" } }, { "question_response": "nectar supporting", "question": { "key": "nectarvls" } }, { "question_response": "ncris supporting", "question": { "key": "ncris" } }], "institutions": [{ "institution": "Monash" }], "publications": [{ "reference": "pub1" }], "grants": [{ "grant_type": { "id": 1 }, "funding_body_and_scheme": "arc tests funding", "grant_id": "arc-001", "start_year": 2014, "total_funding": 200 }], "project_contacts": [{ "contact": { "id": contact_obj.id, "email": contact_obj.email }, "contact_role": { "id": 2 } }], "domains": [{ "percentage": 100, "for_code": { "id": 1 } }], "requests": [{ "compute_requests": [{ "instances": 21, "approved_instances": 12, "cores": 32, "approved_cores": 22, "core_hours": 744, "approved_core_hours": 744, "compute_product": { "id": 1 }, "compute_question_responses": [] }], "storage_requests": [{ "quota": 22, "approved_quota": 12, "storage_product": { "id": 3, "name": "Nectar Volume (Monash)" }, "storage_question_responses": [] }], "request_question_responses": [{ "question_response": "1", "question": { "key": "duration" } }, { "question_response": "False", "question": { "key": "ptconversion" } }, { "question_response": "Some Question Response", "question": { "key": "researchcase" } }, { "question_response": "Creating allocation request " "testing1 patterns", "question": { "key": "usagepattern" } }, { "question_response": "Monash", "question": { "key": "homenode" } }, { "question_response": "Monash Node", "question": { "key": "homerequirements" } }, { "question_response": 20000, "question": { "key": "estimatedusers" } }], "request_status": { "id": 1 }, "funding_scheme": { "id": 1 }, "start_date": "2015-11-25", "end_date": "2015-12-25", "created_by": { "id": user_id }, "updated_by": { "id": user_id }, "approval_notes": "" }] } if not proj_ids: ret_data["project_ids"] = [{ "identifier": 'nec_' + utils.get_random_string(11), "system": system_map.get(DBConstants.SYSTEM_NECTAR), }] else: ret_data["project_ids"] = proj_ids return ret_data