def test_map_request_data(client, jwt, app): """ Setup: Test: Validate: :param client: :param jwt: :param app: :return: """ nr_svc = NameRequestService() # Set data to the service input_data = {} nr_svc.request_data = input_data # Build the NR structure nr_model = build_nr(State.DRAFT) nr_model.save_to_db() # Apply the state change updated_nr_model = nr_svc.apply_state_change( nr_model, State.DRAFT, NameRequest.handle_name_request_update) # Test the result assert updated_nr_model is not None
def test_initial_to_reserved(client, jwt, app): """ Setup: - Initialize NameRequestService - Create a new Request model instance Test: - Call apply_state_change on the NameRequestService instance - Make sure to pass in the Request model instance to apply_state_change - Make sure to pass in the appropriate apply_state_change handler eg. handle_name_request_<create|update> to apply_state_change Validate: - That the state change is successful :param client: :param jwt: :param app: :return: """ nr_svc = NameRequestService() # Set data to the service input_data = {} nr_svc.request_data = input_data # Build the NR structure nr_model = build_nr(State.DRAFT) nr_model.save_to_db() # Apply the state change updated_nr_model = nr_svc.apply_state_change( nr_model, State.RESERVED, NameRequest.handle_name_request_update) # Test the result assert updated_nr_model is not None
def test_update_request_names(client, jwt, app): """ Setup: Test: Validate: :param client: :param jwt: :param app: :return: """ do_test_cleanup() # Initialize the service nr_svc = NameRequestService() """ Test updating three names """ # We will need a base NR nr = build_nr(State.DRAFT, {}, [test_names_no_id[0], test_names_no_id[1]]) # We can't save the NR without an NR Num nr.nrNum = 'NR L000001' # Save to DB so PK sequences are updated nr.save_to_db() db.session.flush() # NR added_names = list(map(lambda n: n.as_dict(), nr.names.all())) added_name_0 = pick_name_from_list(added_names, test_names_no_id[0].get('name')) added_name_1 = pick_name_from_list(added_names, test_names_no_id[1].get('name')) # Set data to the service, all we need to test is names so just provide what's necessary nr_svc.request_data = { 'names': [ # Same as test name 1 added_name_0, # Map this over added_name_1, # Map this over test_names_no_id[2] ] } # Build the names nr = nr_svc.map_request_names(nr) nr.save_to_db() nr = Request.find_by_nr(nr.nrNum) # Convert to dict nr = nr.json() assert nr is not None # Test the names assert_names_are_mapped_correctly(nr_svc.request_data.get('names'), nr.get('names')) # Clean up do_test_cleanup()
def test_map_request_data(client, jwt, app): """ Setup: Test: Validate: :param client: :param jwt: :param app: :return: """ nr_svc = NameRequestService() # Set data to the service input_data = {} nr_svc.request_data = input_data # Build the NR structure nr_model = build_nr(State.DRAFT) nr_model.save_to_db()