コード例 #1
0
class TestQuantityUnitConversion(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = f"{QUANTITY_UNIT_CONVERTIONS_ENDPOINT }/1"

    def test_quantity_unit_conversion_data_diff_valid(self):
        quantity_unit_conversion = self.api.do_request("GET", self.endpoint)
        quantity_unit_conversion_keys = quantity_unit_conversion.keys()
        moked_quantity_unit_conversion_json = """{
            "id": "1",
            "from_qu_id": "3",
            "to_qu_id": "12",
            "factor": "10.0",
            "product_id": "10",
            "row_created_timestamp": "2020-03-05 00:50:10"
        }"""
        moked_keys = json.loads(moked_quantity_unit_conversion_json).keys()
        self.assertCountEqual(list(quantity_unit_conversion_keys),
                              list(moked_keys))

    def test_parse_json(self):
        quantity_unit_conversion = QuantityUnitConversion(
            self.api, QUANTITY_UNIT_CONVERTIONS_ENDPOINT,
            self.api.do_request("GET", self.endpoint))
        assert isinstance(quantity_unit_conversion.id, int)
        assert isinstance(quantity_unit_conversion.from_qu_id, int)
        assert isinstance(quantity_unit_conversion.to_qu_id, int)
        assert isinstance(quantity_unit_conversion.id, int)
        assert isinstance(quantity_unit_conversion.factor, float)
        assert isinstance(quantity_unit_conversion.product_id, int)
        assert isinstance(quantity_unit_conversion.row_created_timestamp,
                          datetime)
コード例 #2
0
class TestUserEntity(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = USEROBJECTS_ENDPOINT + '/1'

    def test_userobject_data_diff_valid(self):
        userobject = self.api.do_request("GET", self.endpoint)
        userobject_keys = userobject.keys()
        moked_userobject_json = """{
            "id": "1",
            "userentity_id": "1",
            "row_created_timestamp": "2020-03-06 00:50:10"
        }"""
        moked_keys = json.loads(moked_userobject_json).keys()
        self.assertCountEqual(list(userobject_keys), list(moked_keys))

    def test_parse_json(self):
        userobject = UserObject(self.api, USEROBJECTS_ENDPOINT,
                                self.api.do_request("GET", self.endpoint))
        assert isinstance(userobject.id, int)
        assert isinstance(userobject.userentity_id, int)
        assert isinstance(userobject.row_created_timestamp, datetime)
コード例 #3
0
class TestLocation(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = LOCATION_ENDPOINT + '/2'

    def test_location_data_diff_valid(self):
        location = self.api.do_request("GET", self.endpoint)
        location_keys = location.keys()
        moked_location_json = """{
            "id": "2",
            "name": "Fridge",
            "description": null,
            "row_created_timestamp": "2020-03-01 00:50:24",
            "is_freezer": "0"
        }"""
        moked_keys = json.loads(moked_location_json).keys()
        self.assertCountEqual(list(location_keys), list(moked_keys))

    def test_parse_json(self):
        location = Location(self.api, LOCATION_ENDPOINT,
                            self.api.do_request("GET", self.endpoint))
        assert isinstance(location.id, int)
        assert isinstance(location.description,
                          str) or location.description is None
        assert isinstance(location.name, str)
        assert isinstance(location.is_freezer, bool)
        assert isinstance(location.row_created_timestamp, datetime)
コード例 #4
0
class TestQuantityUnit(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = QUANTITY_UNITS_ENDPOINT + '/2'

    def test_quantity_unit_data_diff_valid(self):
        quantity_unit = self.api.do_request("GET", self.endpoint)
        quantity_unit_keys = quantity_unit.keys()
        moked_quantity_unit_json = """{
            "id": "2",
            "name": "Piece",
            "description": null,
            "row_created_timestamp": "2020-03-04 00:50:13",
            "name_plural": "Pieces",
            "plural_forms": null
        }"""
        moked_keys = json.loads(moked_quantity_unit_json).keys()
        self.assertCountEqual(list(quantity_unit_keys), list(moked_keys))

    def test_parse_json(self):
        quantity_unit = QuantityUnit(self.api, QUANTITY_UNITS_ENDPOINT,
                                     self.api.do_request("GET", self.endpoint))
        assert isinstance(quantity_unit.id, int)
        assert isinstance(quantity_unit.description,
                          str) or quantity_unit.description is None
        assert isinstance(quantity_unit.name, str)
        assert isinstance(quantity_unit.name_plural, str)
        assert isinstance(quantity_unit.plural_forms,
                          str) or quantity_unit.plural_forms is None
        assert isinstance(quantity_unit.row_created_timestamp, datetime)
コード例 #5
0
class TestTaskCategory(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = TASK_CATEGORIES_ENDPOINT + '/1'

    def test_task_category_data_diff_valid(self):
        task_category = self.api.do_request("GET", self.endpoint)
        task_category_keys = task_category.keys()
        moked_task_category_json = """{
            "id": "1",
            "name": "Home",
            "description": null,
            "row_created_timestamp": "2020-03-05 00:50:10"
        }"""
        moked_keys = json.loads(moked_task_category_json).keys()
        self.assertCountEqual(list(task_category_keys), list(moked_keys))

    def test_parse_json(self):
        task_category = TaskCategory(self.api, TASK_CATEGORIES_ENDPOINT,
                                     self.api.do_request("GET", self.endpoint))
        assert isinstance(task_category.id, int)
        assert isinstance(task_category.description,
                          str) or task_category.description is None
        assert isinstance(task_category.name, str)
        assert isinstance(task_category.row_created_timestamp, datetime)
コード例 #6
0
class TestProductGroup(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = PRODUCT_GROUPS_ENDPOINT + '/1'

    def test_product_group_data_diff_valid(self):
        product_group = self.api.do_request("GET", self.endpoint)
        product_group_keys = product_group.keys()
        moked_product_group_json = """{
            "id": "1",
            "name": "01 Sweets",
            "description": null,
            "row_created_timestamp": "2020-03-05 00:50:10"
        }"""
        moked_keys = json.loads(moked_product_group_json).keys()
        self.assertCountEqual(list(product_group_keys), list(moked_keys))

    def test_parse_json(self):
        product_group = ProductGroup(self.api, PRODUCT_GROUPS_ENDPOINT,
                                     self.api.do_request("GET", self.endpoint))
        assert isinstance(product_group.id, int)
        assert isinstance(product_group.description,
                          str) or product_group.description is None
        assert isinstance(product_group.name, str)
        assert isinstance(product_group.row_created_timestamp, datetime)
コード例 #7
0
ファイル: test_equipment.py プロジェクト: fossabot/pygrocydm
class TestEquipment(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = EQUIPMENT_ENDPOINT + '/1'

    def test_equipment_data_diff_valid(self):
        equipment = self.api.do_request("GET", self.endpoint)
        equipment_keys = equipment.keys()
        moked_equipment_json = """{
            "id": "1",
            "name": "Coffee machine",
            "description": null,
            "row_created_timestamp": "2020-03-05 00:50:10",
            "instruction_manual_file_name": "loremipsum.pdf"
        }"""
        moked_keys = json.loads(moked_equipment_json).keys()
        self.assertCountEqual(list(equipment_keys), list(moked_keys))

    def test_parse_json(self):
        equipment = Equipment(self.api, EQUIPMENT_ENDPOINT,
                              self.api.do_request("GET", self.endpoint))
        assert isinstance(equipment.id, int)
        assert isinstance(equipment.description,
                          str) or equipment.description is None
        assert isinstance(equipment.name, str)
        assert isinstance(equipment.instruction_manual_file_name,
                          str) or not equipment.instruction_manual_file_name
        assert isinstance(equipment.row_created_timestamp, datetime)
コード例 #8
0
class TestBattery(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = BATTERIES_ENDPOINT + '/1'

    def test_battery_data_diff_valid(self):
        battery = self.api.do_request("GET", self.endpoint)
        battery_keys = battery.keys()
        moked_battery_json = """{
            "id": "1",
            "name": "Battery1",
            "description": "Warranty ends 2023",
            "used_in": "TV remote control",
            "charge_interval_days": "0",
            "row_created_timestamp": "2020-03-01 00:50:25"
        }"""
        moked_keys = json.loads(moked_battery_json).keys()
        self.assertCountEqual(list(battery_keys), list(moked_keys))

    def test_parse_json(self):
        battery = Battery(self.api, BATTERIES_ENDPOINT,
                          self.api.do_request("GET", self.endpoint))
        assert isinstance(battery.id, int)
        assert isinstance(battery.description,
                          str) or battery.description is None
        assert isinstance(battery.name, str)
        assert isinstance(battery.used_in, (str, None))
        assert isinstance(battery.charge_interval_days, int)
        assert isinstance(battery.row_created_timestamp, datetime)
コード例 #9
0
class TestRecipeNesting(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = RECIPES_NESTINGS_ENDPOINT + '/1'

    def test_recipe_nesting_data_diff_valid(self):
        recipe_nesting = self.api.do_request("GET", self.endpoint)
        recipe_nesting_keys = recipe_nesting.keys()
        moked_recipe_nesting_json = """{
            "id": "1",
            "recipe_id": "6",
            "includes_recipe_id": "4",
            "row_created_timestamp": "2020-03-12 00:50:11",
            "servings": "1"
        }"""
        moked_keys = json.loads(moked_recipe_nesting_json).keys()
        self.assertCountEqual(list(recipe_nesting_keys), list(moked_keys))

    def test_parse_json(self):
        recipe_nesting = RecipeNesting(
            self.api, RECIPES_NESTINGS_ENDPOINT,
            self.api.do_request("GET", self.endpoint))
        assert isinstance(recipe_nesting.id, int)
        assert isinstance(recipe_nesting.recipe_id, int)
        assert isinstance(recipe_nesting.includes_recipe_id, int)
        assert isinstance(recipe_nesting.servings, int)
        assert isinstance(recipe_nesting.row_created_timestamp, datetime)
コード例 #10
0
class TestUserfield(TestCase):

    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL, "demo_mode",  verify_ssl=CONST_SSL, port=CONST_PORT)
        self.endpoint = USERFIELDS_ENDPOINT + '/1'

    def test_userfield_data_diff_valid(self):
        userfield = self.api.do_request("GET", self.endpoint)
        userfield_keys = userfield.keys()
        moked_userfield_json = """{
            "id": "1",
            "entity": "userentity-exampleuserentity",
            "name": "customfield1",
            "caption": "Custom field 1",
            "type": "text-single-line",
            "show_as_column_in_tables": "1",
            "row_created_timestamp": "2020-03-06 00:50:10",
            "config": null
        }"""
        moked_keys = json.loads(moked_userfield_json).keys()
        self.assertCountEqual(list(userfield_keys), list(moked_keys))

    def test_parse_json(self):
        uf_types = { item.value for item in UserfieldType }
        userfield = Userfield(self.api, USERFIELDS_ENDPOINT, self.api.do_request("GET", self.endpoint))
        assert isinstance(userfield.id, int)
        assert isinstance(userfield.entity, str)
        assert isinstance(userfield.name, str)
        assert isinstance(userfield.caption, str)
        assert isinstance(userfield.type, str) and userfield.type in uf_types
        assert isinstance(userfield.show_as_column_in_tables, bool)
        assert isinstance(userfield.config, str) or userfield.config is None
        assert isinstance(userfield.row_created_timestamp, datetime)
コード例 #11
0
class TestShoppingList(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = SHOPPING_LISTS_ENDPOINT + '/1'

    def test_shopping_list_data_diff_valid(self):
        shopping_list = self.api.do_request("GET", self.endpoint)
        shopping_list_keys = shopping_list.keys()
        moked_shopping_list_json = """{
            "id": "1",
            "name": "Shopping list",
            "description": null,
            "row_created_timestamp": "2020-03-02 00:50:09"
        }"""
        moked_keys = json.loads(moked_shopping_list_json).keys()
        self.assertCountEqual(list(shopping_list_keys), list(moked_keys))

    def test_parse_json(self):
        shopping_list = ShoppingList(self.api, SHOPPING_LIST_ENDPOINT,
                                     self.api.do_request("GET", self.endpoint))
        assert isinstance(shopping_list.id, int)
        assert isinstance(shopping_list.description,
                          str) or shopping_list.description is None
        assert isinstance(shopping_list.name, str)
        assert isinstance(shopping_list.row_created_timestamp, datetime)
コード例 #12
0
class TestShoppingListItem(TestCase):

    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL, "demo_mode",  verify_ssl=CONST_SSL, port=CONST_PORT)
        self.endpoint = SHOPPING_LIST_ENDPOINT + '/1'

    def test_shopping_list_item_data_diff_valid(self):
        shopping_list_item = self.api.do_request("GET", self.endpoint)
        shopping_list_item_keys = shopping_list_item.keys()
        moked_shopping_list_item_json = """{
            "id": "1",
            "product_id": null,
            "note": "Some good snacks",
            "amount": "1",
            "row_created_timestamp": "2020-03-02 00:50:10",
            "shopping_list_id": "1",
            "done": "0"
        }"""
        moked_keys = json.loads(moked_shopping_list_item_json).keys()
        self.assertCountEqual(list(shopping_list_item_keys), list(moked_keys))

    def test_parse_json(self):
        shopping_list_item = ShoppingListItem(self.api, SHOPPING_LISTS_ENDPOINT, self.api.do_request("GET", self.endpoint))
        assert isinstance(shopping_list_item.id, int)
        assert isinstance(shopping_list_item.product_id, int) or shopping_list_item.product_id is None
        assert isinstance(shopping_list_item.note, str) or shopping_list_item.note is None
        assert isinstance(shopping_list_item.amount, float)
        assert isinstance(shopping_list_item.shopping_list_id, int)
        assert isinstance(shopping_list_item.done, bool)
        assert isinstance(shopping_list_item.row_created_timestamp, datetime)
コード例 #13
0
class TestUserEntity(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = USERENTITIES_ENDPOINT + '/1'

    def test_userentity_data_diff_valid(self):
        userentity = self.api.do_request("GET", self.endpoint)
        userentity_keys = userentity.keys()
        moked_userentity_json = """{
            "id": "1",
            "name": "exampleuserentity",
            "caption": "Example userentity",
            "description": "This is an example user entity...",
            "show_in_sidebar_menu": "1",
            "icon_css_class": "fas fa-smile",
            "row_created_timestamp": "2020-03-06 00:50:10"
        }"""
        moked_keys = json.loads(moked_userentity_json).keys()
        self.assertCountEqual(list(userentity_keys), list(moked_keys))

    def test_parse_json(self):
        userentity = UserEntity(self.api, USERENTITIES_ENDPOINT,
                                self.api.do_request("GET", self.endpoint))
        assert isinstance(userentity.id, int)
        assert isinstance(userentity.name, str)
        assert isinstance(userentity.caption, str)
        assert isinstance(userentity.description,
                          str) or userentity.description is None
        assert isinstance(userentity.show_in_sidebar_menu, bool)
        assert isinstance(userentity.icon_css_class,
                          str) or userentity.icon_css_class is None
        assert isinstance(userentity.row_created_timestamp, datetime)
コード例 #14
0
class TestChore(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = CHORES_ENDPOINT + '/1'

    def test_chore_data_diff_valid(self):
        chore = self.api.do_request("GET", self.endpoint)
        chore_keys = chore.keys()
        moked_chore_json = """{
            "id": "1",
            "name": "Changed towels in the bathroom",
            "description": null,
            "period_type": "manually",
            "period_days": "5",
            "row_created_timestamp": "2020-02-26 00:50:11",
            "period_config": null,
            "track_date_only": "0",
            "rollover": "0",
            "assignment_type": null,
            "assignment_config": null,
            "next_execution_assigned_to_user_id": null,
            "consume_product_on_execution": "0",
            "product_id": null,
            "product_amount": null,
            "period_interval": "1"
        }"""
        moked_keys = json.loads(moked_chore_json).keys()
        self.assertCountEqual(list(chore_keys), list(moked_keys))

    def test_parse_json(self):
        assignment_types = {item.value for item in AssignmentType}
        period_types = {item.value for item in PeriodType}
        chore = Chore(self.api, CHORES_ENDPOINT,
                      self.api.do_request("GET", self.endpoint))
        assert isinstance(chore.id, int)
        assert isinstance(chore.description, str) or chore.description is None
        assert isinstance(chore.name, str)
        assert isinstance(chore.period_type,
                          str) and chore.period_type in period_types
        assert isinstance(chore.period_days, int) or chore.period_days is None
        assert isinstance(
            chore.next_execution_assigned_to_user_id,
            int) or chore.next_execution_assigned_to_user_id is None
        assert isinstance(chore.description, str) or chore.description is None
        assert isinstance(chore.period_config,
                          str) or chore.period_config is None
        assert isinstance(chore.track_date_only,
                          bool) or not chore.track_date_only
        assert isinstance(chore.rollover, bool) or not chore.rollover
        assert (isinstance(chore.assignment_type, str)
                and chore.assignment_type
                in assignment_types) or chore.assignment_type is None
        assert isinstance(chore.assignment_config,
                          str) or chore.assignment_config is None
        assert isinstance(chore.row_created_timestamp, datetime)
コード例 #15
0
ファイル: test_tasks.py プロジェクト: BlueBlueBlob/pygrocydm
class TestTask(TestCase):

    def setUp(self):
        self.grocy_api = GrocyAPI(CONST_BASE_URL, "demo_mode",  verify_ssl = CONST_SSL, port = CONST_PORT)
        self.api_client = GrocyApiClient(CONST_BASE_URL, "demo_mode",  verify_ssl=CONST_SSL, port=CONST_PORT)

    def test_task_data_diff_valid(self): 
        task = self.api_client.do_request("GET", TASKS_ENDPOINT).pop()
        task_keys = task.keys()
        moked_task_json = """{
            "id": "1",
            "name": "Repair the garage door",
            "description": null,
            "due_date": "2020-03-18",
            "done": "0",
            "done_timestamp": null,
            "category_id": "1",
            "assigned_to_user_id": "1",
            "row_created_timestamp": "2020-03-04 00:50:14"
        }"""
        moked_keys = json.loads(moked_task_json).keys()
        self.assertCountEqual(list(task_keys), list(moked_keys))

    def test_parse_json(self):
        tasks = self.grocy_api.tasks()
        assert isinstance(tasks, Tasks)
        assert len(tasks.tasks_list) > 0
        for task in tasks.tasks_list:
            assert isinstance(task, Task)
            assert isinstance(task.id, int)
            assert isinstance(task.description, str) or not task.description
            assert isinstance(task.name, str)
            assert isinstance(task.due_date, (datetime, None)) or not task.description
            assert isinstance(task.done, bool)
            assert isinstance(task.done_timestamp, datetime) or not task.description
            assert isinstance(task.category_id, int) or not task.description
            assert isinstance(task.assigned_to_user_id, int)
            assert isinstance(task.row_created_timestamp, datetime)

    def test_complete_now(self):
        tasks = self.grocy_api.tasks()
        test_task = tasks.tasks_list[0]
        test_id = test_task.id
        test_task.complete()
        tasks.refresh()
        self.assertFalse(any(task.id == test_id for task in tasks.tasks_list))

    def test_undo(self):
        tasks = self.grocy_api.tasks()
        test_task = tasks.tasks_list[0]
        test_id = test_task.id
        test_task.complete()
        test_task.undo()
        tasks.refresh()
        for task in tasks.tasks_list:
            if task.id == test_id:
                test_task = task
                break
        self.assertTrue(any(task.id == test_id for task in tasks.tasks_list))
コード例 #16
0
class TestMealPlan(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = MEAL_PLAN_ENDPOINT + '/1'

    def test_meal_plan_data_diff_valid(self):
        meal_plan = self.api.do_request("GET", self.endpoint)
        meal_plan_keys = meal_plan.keys()
        moked_meal_plan_json = """{
            "id": "1",
            "day": "2020-03-09",
            "type": "recipe",
            "recipe_id": "1",
            "recipe_servings": "1",
            "note": null,
            "product_id": null,
            "product_amount": "0.0",
            "product_qu_id": null,
            "row_created_timestamp": "2020-03-11 00:50:12"
          }"""
        moked_keys = json.loads(moked_meal_plan_json).keys()
        self.assertCountEqual(list(meal_plan_keys), list(moked_keys))

    def test_parse_json(self):
        meal_types = {item.value for item in MealPlanType}
        meal_plan = MealPlan(self.api, MEAL_PLAN_ENDPOINT,
                             self.api.do_request("GET", self.endpoint))
        assert isinstance(meal_plan.id, int)
        assert isinstance(meal_plan.day, datetime)
        assert (isinstance(meal_plan.type, str)
                and meal_plan.type in meal_types)
        assert isinstance(meal_plan.recipe_id,
                          int) or meal_plan.recipe_id is None
        assert isinstance(meal_plan.recipe_servings,
                          int) or meal_plan.recipe_servings is None
        assert isinstance(meal_plan.note, str) or meal_plan.note is None
        assert isinstance(meal_plan.product_id,
                          int) or meal_plan.product_id is None
        assert isinstance(meal_plan.product_amount, float)
        assert isinstance(meal_plan.product_qu_id,
                          int) or not meal_plan.product_qu_id
        assert isinstance(meal_plan.row_created_timestamp, datetime)
コード例 #17
0
ファイル: test_recipe.py プロジェクト: BlueBlueBlob/pygrocydm
class TestRecipe(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = RECIPES_ENDPOINT + '/1'

    def test_recipe_data_diff_valid(self):
        recipe = self.api.do_request("GET", self.endpoint)
        recipe_keys = recipe.keys()
        moked_recipe_json = """{
            "id": "-35",
            "name": "2020-11",
            "description": null,
            "row_created_timestamp": "2020-03-11 11:12:23",
            "picture_file_name": null,
            "base_servings": "1",
            "desired_servings": "1",
            "not_check_shoppinglist": "0",
            "type": "mealplan-week",
            "product_id": null
          }"""
        moked_keys = json.loads(moked_recipe_json).keys()
        self.assertCountEqual(list(recipe_keys), list(moked_keys))

    def test_parse_json(self):
        recipe_types = {item.value for item in RecipeType}
        recipe = Recipe(self.api, RECIPES_ENDPOINT,
                        self.api.do_request("GET", self.endpoint))
        assert isinstance(recipe.id, int)
        assert isinstance(recipe.name, str)
        assert (isinstance(recipe.type, str) and recipe.type in recipe_types)
        assert isinstance(recipe.description,
                          str) or recipe.description is None
        assert isinstance(recipe.base_servings, int)
        assert isinstance(recipe.desired_servings, int)
        assert isinstance(recipe.picture_file_name,
                          str) or recipe.picture_file_name is None
        assert isinstance(recipe.not_check_shoppinglist, bool)
        assert isinstance(recipe.product_id, int) or not recipe.product_id
        assert isinstance(recipe.row_created_timestamp, datetime)
コード例 #18
0
class TestRecipePos(TestCase):

    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL, "demo_mode",  verify_ssl=CONST_SSL, port=CONST_PORT)
        self.endpoint = RECIPES_POS_ENDPOINT + '/1'

    def test_recipe_pos_data_diff_valid(self):
        recipe_pos = self.api.do_request("GET", self.endpoint)
        recipe_pos_keys = recipe_pos.keys()
        moked_recipe_pos_json = """{
            "id": "1",
            "recipe_id": "1",
            "product_id": "16",
            "amount": "1.0",
            "note": null,
            "qu_id": "3",
            "only_check_single_unit_in_stock": "0",
            "ingredient_group": "Bottom",
            "not_check_stock_fulfillment": "0",
            "row_created_timestamp": "2020-03-12 00:50:11",
            "variable_amount": null,
            "price_factor": "1.0"
        }"""
        moked_keys = json.loads(moked_recipe_pos_json).keys()
        self.assertCountEqual(list(recipe_pos_keys), list(moked_keys))

    def test_parse_json(self):
        recipe_pos = RecipePos(self.api, RECIPES_POS_ENDPOINT, self.api.do_request("GET", self.endpoint))
        assert isinstance(recipe_pos.id, int)
        assert isinstance(recipe_pos.recipe_id, int)
        assert isinstance(recipe_pos.product_id, int)
        assert isinstance(recipe_pos.amount, float)
        assert isinstance(recipe_pos.note, str) or recipe_pos.note is None
        assert isinstance(recipe_pos.qu_id, int)
        assert isinstance(recipe_pos.only_check_single_unit_in_stock, bool)
        assert isinstance(recipe_pos.ingredient_group, str) or recipe_pos.ingredient_group is None
        assert isinstance(recipe_pos.not_check_stock_fulfillment, bool)
        assert isinstance(recipe_pos.variable_amount, str) or not recipe_pos.variable_amount
        assert isinstance(recipe_pos.price_factor, float)
        assert isinstance(recipe_pos.row_created_timestamp, datetime)
コード例 #19
0
ファイル: test_task.py プロジェクト: BlueBlueBlob/pygrocydm
class TestTask(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = TASKS_ENDPOINT + '/1'

    def test_task_data_diff_valid(self):
        task = self.api.do_request("GET", self.endpoint)
        task_keys = task.keys()
        moked_task_json = """{
            "id": "1",
            "name": "Repair the garage door",
            "description": null,
            "due_date": "2020-03-18",
            "done": "0",
            "done_timestamp": null,
            "category_id": "1",
            "assigned_to_user_id": "1",
            "row_created_timestamp": "2020-03-04 00:50:14"
        }"""
        moked_keys = json.loads(moked_task_json).keys()
        self.assertCountEqual(list(task_keys), list(moked_keys))

    def test_parse_json(self):
        task = Task(self.api, TASKS_ENDPOINT,
                    self.api.do_request("GET", self.endpoint))
        assert isinstance(task.id, int)
        assert isinstance(task.description, str) or not task.description
        assert isinstance(task.name, str)
        assert isinstance(task.due_date,
                          (datetime, None)) or not task.description
        assert isinstance(task.done, bool)
        assert isinstance(task.done_timestamp,
                          datetime) or not task.description
        assert isinstance(task.category_id, int) or not task.description
        assert isinstance(task.assigned_to_user_id, int)
        assert isinstance(task.row_created_timestamp, datetime)
コード例 #20
0
class TestProduct(TestCase):
    def setUp(self):
        self.api = GrocyApiClient(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.endpoint = 'objects/products/1'

    def test_product_data_diff_valid(self):
        product = self.api.do_request("GET", self.endpoint)
        product_keys = product.keys()
        moked_product_json = """{
            "id": "1",
            "name": "Cookies",
            "description": null,
            "location_id": "4",
            "qu_id_purchase": "3",
            "qu_id_stock": "3",
            "qu_factor_purchase_to_stock": "1.0",
            "barcode": null,
            "min_stock_amount": "8",
            "default_best_before_days": "0",
            "row_created_timestamp": "2020-02-25 00:50:13",
            "product_group_id": "1",
            "picture_file_name": "cookies.jpg",
            "default_best_before_days_after_open": "0",
            "allow_partial_units_in_stock": "0",
            "enable_tare_weight_handling": "0",
            "tare_weight": "0.0",
            "not_check_stock_fulfillment_for_recipes": "0",
            "parent_product_id": null,
            "calories": "123",
            "cumulate_min_stock_amount_of_sub_products": "0",
            "default_best_before_days_after_freezing": "0",
            "default_best_before_days_after_thawing": "0"
        }"""
        moked_keys = json.loads(moked_product_json).keys()
        self.assertCountEqual(list(product_keys), list(moked_keys))

    def test_parse_json(self):
        product = Product(self.api, PRODUCTS_ENDPOINT,
                          self.api.do_request("GET", self.endpoint))
        assert isinstance(product.id, int)
        assert isinstance(product.product_group_id, int)
        assert isinstance(product.name, str)
        assert isinstance(product.barcodes,
                          (str, list)) or product.barcodes is None
        assert isinstance(product.location_id,
                          int) or product.location_id is None
        assert isinstance(product.qu_id_purchase,
                          int) or product.qu_id_purchase is None
        assert isinstance(product.description,
                          str) or product.description is None
        assert isinstance(product.qu_id_stock,
                          int) or product.qu_id_stock is None
        assert isinstance(product.enable_tare_weight_handling,
                          int) or product.enable_tare_weight_handling is None
        assert isinstance(
            product.not_check_stock_fulfillment_for_recipes,
            int) or product.not_check_stock_fulfillment_for_recipes is None
        assert isinstance(product.qu_factor_purchase_to_stock,
                          float) or product.qu_factor_purchase_to_stock is None
        assert isinstance(product.tare_weight,
                          float) or product.tare_weight is None
        assert isinstance(product.min_stock_amount,
                          int) or product.min_stock_amount == 0
        assert isinstance(product.default_best_before_days,
                          int) or product.default_best_before_days is None
        assert isinstance(
            product.default_best_before_days_after_open,
            int) or product.default_best_before_days_after_open is None
        assert isinstance(product.picture_file_name,
                          str) or product.picture_file_name is None
        assert isinstance(product.allow_partial_units_in_stock, bool)
        assert isinstance(product.row_created_timestamp, datetime)
コード例 #21
0
class TestRecipe(TestCase):
    def setUp(self):
        self.grocy_api = GrocyAPI(CONST_BASE_URL,
                                  "demo_mode",
                                  verify_ssl=CONST_SSL,
                                  port=CONST_PORT)
        self.api_client = GrocyApiClient(CONST_BASE_URL,
                                         "demo_mode",
                                         verify_ssl=CONST_SSL,
                                         port=CONST_PORT)
        self.endpoint = f"{RECIPES_ENDPOINT}/1/fulfillment"

    def test_recipe_data_diff_valid(self):
        recipe = self.api_client.do_request("GET", self.endpoint)
        recipe_keys = recipe.keys()
        moked_recipe_json = """{
            "id": "1",
            "recipe_id": "1",
            "need_fulfilled": "0",
            "need_fulfilled_with_shopping_list": "0",
            "missing_products_count": "4",
            "costs": "24.25",
            "calories": "492.0"
            }"""
        moked_keys = json.loads(moked_recipe_json).keys()
        self.assertCountEqual(list(recipe_keys), list(moked_keys))

    def test_parse_json(self):
        recipe = Recipe(self.api_client,
                        self.api_client.do_request("GET", self.endpoint))
        assert isinstance(recipe.id, int)
        assert isinstance(recipe.recipe_id, int)
        assert isinstance(recipe.need_fulfilled, bool)
        assert isinstance(recipe.need_fulfilled_with_shopping_list, bool)
        assert isinstance(recipe.missing_products_count, int)
        assert isinstance(recipe.costs, float)
        assert isinstance(recipe.calories, float)

    def test_add_product(self):
        recipes = self.grocy_api.recipes().fullfilment_list
        for recipe in recipes:
            if recipe.recipe_id == 2:
                recipe.add_not_fulfilled_products_to_shoppinglist()
                break

    def test_add_product_exclude(self):
        recipes = self.grocy_api.recipes().fullfilment_list
        for recipe in recipes:
            if recipe.recipe_id == 2:
                recipe.add_not_fulfilled_products_to_shoppinglist([17])
                break

    def test_consume_valid(self):
        recipes = self.grocy_api.recipes().fullfilment_list
        for recipe in recipes:
            if recipe.recipe_id == 3:
                recipe.consume()
                break

    def test_consume_error(self):
        recipes = self.grocy_api.recipes().fullfilment_list
        for recipe in recipes:
            if recipe.recipe_id == 0:
                self.assertRaises(HTTPError, recipe.consume)