Ejemplo n.º 1
0
    def test_str_value(self):
        # arrange
        option = Option(name="colour", option_type="str")

        # act
        option.value = "Black"

        #  assert
        self.assertEqual("Black", option.value)
        self.assertIsInstance(option.value, str)
Ejemplo n.º 2
0
    def test_numeric_value(self):
        # arrange
        option = Option(name="minPrice", option_type="float")

        # act
        option.value = 30000

        # assert
        self.assertEqual(30000, option.value)
        self.assertIsInstance(option.value, int)
Ejemplo n.º 3
0
    def test_get_index(self):
        # arrange
        expected_option = Option(name="range",
                                 feature_name="open",
                                 entity_id="gme",
                                 option_type="str",
                                 value_text="3m")
        MockContext.setup(Option, all=[expected_option])

        # act
        res = self.client.get(self.base_path)

        # assert
        self.assertEqual(res.status_code, 200)
        self.assertListEqual(res.json, [expected_option.__json__()])
Ejemplo n.º 4
0
def options_index(entity_identifier: str,
                  feature_name: str,
                  metadata_context: BaseContext = Provide[
                      ApplicationContainer.context_factory]):
    if request.method == constants.HTTP_GET:
        with metadata_context.get_session() as session:
            query = session.query(Option).filter(
                Option.entity_identifier == entity_identifier,
                Option.feature_name == feature_name)
            options = query.all()

        return jsonify([json(option) for option in options])

    request_option = request.get_json()

    option_value = (request_option['value_text'] if 'value_text'
                    in request_option else request_option['value'])
    with metadata_context.get_session() as session:
        new_option = Option(
            name=request_option['name'],
            entity_identifier=request_option['entity_identifier'],
            feature_name=request_option['feature_name'],
            option_type=request_option['option_type'],
            value_text=option_value,
            value_number=request_option['value_number'])
        session.add(new_option)

    return jsonify(json(new_option)), 201
Ejemplo n.º 5
0
    def test_json(self):
        # arrange
        expected_output = {
            "name": "colour",
            "entity_id": "F",
            "feature_name": "make",
            "option_type": "str",
            "value": "Black",
            "value_number": None
        }
        option = Option(entity_id="F",
                        feature_name="make",
                        name="colour",
                        option_type="str",
                        value_text="Black")

        # act
        json_option = option.__json__()

        # assert
        self.assertDictEqual(expected_output, json_option)
Ejemplo n.º 6
0
    def test_get_option(self):
        # arrange
        expected_option = Option(name="range",
                                 feature_name="open",
                                 entity_id="gme",
                                 option_type="str",
                                 value_text="3m")
        alternate_option = Option(name="range",
                                  feature_name="open",
                                  entity_id="gme",
                                  option_type="str",
                                  value_text="3m")
        MockContext.setup(Option,
                          all=[expected_option, alternate_option],
                          filter=None)

        # act
        res = self.client.get(self.base_path + expected_option.name)

        # assert
        self.assertEqual(len(res.json), 2)
        self.assertEqual(
            res.json,
            [expected_option.__json__(),
             alternate_option.__json__()])
Ejemplo n.º 7
0
def index(metadata_context: BaseContext = Provide[
    ApplicationContainer.context_factory]):
    if request.method == constants.HTTP_GET:
        with metadata_context.get_session() as session:
            options = session.query(Option).all()
            return jsonify([json(option) for option in options])

    with metadata_context.get_session() as session:
        request_option = request.get_json()
        new_option = Option(name=request_option['name'],
                            entity_id=request_option['entity_id'],
                            feature_name=request_option['feature_name'],
                            option_type=request_option['option_type'],
                            value_text=request_option['value_text'],
                            value_number=request_option['value_number'])
        session.add(new_option)

        return jsonify(json(new_option)), 201
Ejemplo n.º 8
0
    def test_bool_value(self):
        # arrange
        test_cases = {
            "true": True,
            "TRUE": True,
            "True": True,
            "False": False,
            "false": False,
            "StrValue": False
        }

        for value, expected in test_cases.items():
            with self.subTest(value=value, expected=expected):
                # arrange
                option = Option(name="is_enabled",
                                option_type="bool",
                                value_text=value)

                # act
                result = option.value

                #  assert
                self.assertEqual(expected, result)
                self.assertIsInstance(result, bool)