def test_parse_given_valid_args(self, args, expected):
        parser = FoodParser(Food)
        parser.parse(args)

        assert compare_nested_exprs(parser.where_clause,
                                    expected["where_clause"])
        assert parser.sort_clause == expected["sort_clause"]
        assert parser.limit_clause == expected["limit_clause"]
        assert parser.returning_clause == expected["returning_clause"]
Beispiel #2
0
 def parse_args(args):
     parser = FoodParser(Food)
     parser.parse(args)
     query = (Food.select(*parser.returning_clause).where(
         parser.where_clause).order_by(
             *(parser.sort_clause or (Food.date.asc(),
                                      Food.time.asc()))).limit(
                                          parser.limit_clause).dicts())
     return query, parser.columns or ["id", "name", "time", "date"]
 def test_parse_given_reset_false(self, arg_list, expected_attrs):
     assert len(arg_list) == len(expected_attrs)
     parser = FoodParser(Food)
     for args, expected in zip(arg_list, expected_attrs):
         parser.parse(args, reset=False)
         assert compare_nested_exprs(parser.where_clause,
                                     expected["where_clause"])
         assert parser.sort_clause == expected["sort_clause"]
         assert parser.limit_clause == expected["limit_clause"]
         assert parser.returning_clause == expected["returning_clause"]
         assert parser.id == expected["id"]
         assert parser.name == expected["name"]
         assert parser.date == expected["date"]
         assert parser.time == expected["time"]
         assert parser.columns == expected["columns"]
Beispiel #4
0
    def parse_args(args):
        parser = FoodParser(Food)
        parser.parse(args)
        params = {}

        if not parser.id:
            raise IdFieldNotFound
        params["id"] = parser.id
        if not parser.name:
            raise NameFieldNotFound
        params["name"] = parser.name
        if parser.date:
            params["date"] = parser.date
        if parser.time:
            params["time"] = parser.time

        return Food.replace(**params)
 def test_parse_given_invalid_args(self, args, error, invalid_value):
     parser = FoodParser(Food)
     with pytest.raises(error, match=rf".+?'{invalid_value}'.+"):
         parser.parse(args)
Beispiel #6
0
 def parse_args(args):
     parser = FoodParser(Food)
     parser.parse(args)
     return Food.delete().where(parser.where_clause)