def test_parameter_string_for_hardcoded_measurement_info_flow_info_json_values(
            self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Flow cytometer configuration')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph(
            '{"do_flow": {"value": "every-sampling","inputs": {"every-sampling": {"flow_params" : "yeast"}}}}'
        )
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(1, len(param_result))
        expected_output = {
            "do_flow": {
                "value": "every-sampling",
                "inputs": {
                    "every-sampling": {
                        "flow_params": "yeast"
                    }
                }
            }
        }

        self.assertEqual(expected_output,
                         param_result['measurement_info.flow_info'])
    def test_container_search_string_with_default_value(self):
        ip_table = test_utils.create_fake_parameter()
        container_search_string = IntentParserCell()
        container_search_string.add_paragraph('Container Search String')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('\n')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=container_search_string,
            parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        expected_experiment_result = {
            ip_constants.PARAMETER_BASE_DIR: None,
            ip_constants.PARAMETER_XPLAN_REACTOR: 'xplan',
            ip_constants.PARAMETER_PLATE_SIZE: None,
            ip_constants.PARAMETER_PROTOCOL_NAME: None,
            ip_constants.PARAMETER_PLATE_NUMBER: None,
            ip_constants.PARAMETER_CONTAINER_SEARCH_STRING:
            dc_constants.GENERATE,
            ip_constants.PARAMETER_STRAIN_PROPERTY: None,
            ip_constants.PARAMETER_XPLAN_PATH: None,
            ip_constants.PARAMETER_SUBMIT: True,
            ip_constants.PARAMETER_PROTOCOL_ID: None,
            ip_constants.PARAMETER_TEST_MODE: False,
            ip_constants.PARAMETER_EXPERIMENT_REFERENCE_URL_FOR_XPLAN: None,
            ip_constants.DEFAULT_PARAMETERS: {}
        }
        self.assertEqual(13, len(param_table.get_experiment()))
        self.assertDictEqual(expected_experiment_result,
                             param_table.get_experiment())
    def test_parameter_field_with_empty_value(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Inoculation volume')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(0, len(param_result))
    def test_parameter_with_non_boolean_value(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Sample has sbh_uri as an aliquot property')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('neither')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(0, len(param_result))
    def test_parameter_string_value_with_list_of_numbers(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Media well ids')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('94,95')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(1, len(param_result))
        self.assertEqual('94,95', param_result['exp_info.media_well_strings'])
    def test_parameter_string_value_with_colon_separator(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Inoculation volume')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('5 microliter')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(1, len(param_result))
        self.assertEqual('5:microliter', param_result['inoc_info.inoc_vol'])
    def test_parameter_with_one_float_value(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Plate reader gain')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('0.1')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(1, len(param_result))
        self.assertEqual(0.1, param_result['plate_reader_info.gain'])
    def test_parameter_string_for_hardcoded_kill_switch_json_values(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Kill switch')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph(
            '{"value": "false", "inputs": {"false": {}}}')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(1, len(param_result))
        expected_output = {"value": "false", "inputs": {"false": {}}}

        self.assertEqual(expected_output,
                         param_result['reagent_info.kill_switch'])
    def test_two_parameter_string_value_without_colon_separator(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Inoculation media')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('S750, Modified M9 Media')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        expected_result = {
            'inoc_info.inoculation_media.0': 'S750',
            'inoc_info.inoculation_media.1': 'Modified M9 Media'
        }
        self.assertEqual(2, len(param_result))
        self.assertDictEqual(expected_result, param_result)
    def test_parameter_with_three_float_values(self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Plate reader gain')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('0.1, 0.2, 0.3')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        expected_result = {
            'plate_reader_info.gain.0': 0.1,
            'plate_reader_info.gain.1': 0.2,
            'plate_reader_info.gain.2': 0.3
        }
        self.assertEqual(3, len(param_result))
        self.assertDictEqual(expected_result, param_result)
    def test_parameter_string_for_hardcoded_induction_info_induction_reagents_inducer_json_values(
            self):
        ip_table = test_utils.create_fake_parameter()
        parameter = IntentParserCell()
        parameter.add_paragraph('Induction inducer')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph(
            '{"containerId" : "ct1e262bek47rkx","wellIndex" : 0}')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=parameter, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        param_result = param_table.get_structured_request()
        self.assertEqual(1, len(param_result))
        expected_output = {"containerId": "ct1e262bek47rkx", "wellIndex": 0}
        self.assertEqual(
            expected_output,
            param_result['induction_info.induction_reagents.inducer'])
    def test_process_complete_experiment_data_from_parameter_table(self):
        ip_table = test_utils.create_fake_parameter()
        plate_size = IntentParserCell()
        plate_size.add_paragraph('Plate Size')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('96')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=plate_size, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        plate_number = IntentParserCell()
        plate_number.add_paragraph('Plate Number')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('2')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=plate_number, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        protocol_name = IntentParserCell()
        protocol_name.add_paragraph('protocol')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('ObstacleCourse')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=protocol_name, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        container_search_string = IntentParserCell()
        container_search_string.add_paragraph('Container Search String')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('Ct1e3qc85mqwbz8, ct1e3qc85jc4gj52')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=container_search_string,
            parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        strain_property = IntentParserCell()
        strain_property.add_paragraph('Strain Property')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('SD2_common_name')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=strain_property,
            parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        xplan_path = IntentParserCell()
        xplan_path.add_paragraph('XPlan Path')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('path/foo/xplan_path')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=xplan_path, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        experiment_reference_url = IntentParserCell()
        experiment_reference_url.add_paragraph(
            'Experiment Reference URL For XPlan')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('path/foo/experiment_reference')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=experiment_reference_url,
            parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        protocol_id = IntentParserCell()
        protocol_id.add_paragraph('Protocol ID')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('pr1e5gw8bdekdxv')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=protocol_id, parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        deafult_params = IntentParserCell()
        deafult_params.add_paragraph('Inoculation volume')
        parameter_value = IntentParserCell()
        parameter_value.add_paragraph('5 microliter')
        data_row = test_utils.create_parameter_table_row(
            parameter_cell=deafult_params,
            parameter_value_cell=parameter_value)
        ip_table.add_row(data_row)

        param_table = ParameterTable(ip_table,
                                     parameter_fields=self.parameter_fields)
        param_table.process_table()
        sr_result = param_table.get_structured_request()
        exp_result = param_table.get_experiment()
        expected_sr_result = {'inoc_info.inoc_vol': '5:microliter'}
        expected_experiment_result = {
            ip_constants.PARAMETER_BASE_DIR:
            None,
            ip_constants.PARAMETER_XPLAN_REACTOR:
            'xplan',
            ip_constants.PARAMETER_PLATE_SIZE:
            96,
            ip_constants.PARAMETER_PROTOCOL_NAME:
            'ObstacleCourse',
            ip_constants.PARAMETER_PLATE_NUMBER:
            2,
            ip_constants.PARAMETER_CONTAINER_SEARCH_STRING:
            ['Ct1e3qc85mqwbz8', 'ct1e3qc85jc4gj52'],
            ip_constants.PARAMETER_STRAIN_PROPERTY:
            'SD2_common_name',
            ip_constants.PARAMETER_XPLAN_PATH:
            'path/foo/xplan_path',
            ip_constants.PARAMETER_SUBMIT:
            True,
            ip_constants.PARAMETER_PROTOCOL_ID:
            'pr1e5gw8bdekdxv',
            ip_constants.PARAMETER_TEST_MODE:
            False,
            ip_constants.PARAMETER_EXPERIMENT_REFERENCE_URL_FOR_XPLAN:
            'path/foo/experiment_reference',
            ip_constants.DEFAULT_PARAMETERS: {
                'inoc_info.inoc_vol': '5:microliter'
            }
        }
        self.assertEqual(1, len(expected_sr_result))
        self.assertDictEqual(expected_sr_result, sr_result)

        self.assertEqual(13, len(expected_experiment_result))
        self.assertDictEqual(expected_experiment_result, exp_result)