Exemple #1
0
 def test_upload_product_picture_error(self):
     with patch("os.path.exists" ) as m_exist:
         with patch("builtins.open", mock_open()) as m_open:
             m_exist.return_value = True
             api_client = GrocyApiClient(CONST_BASE_URL, "demo_mode", port = CONST_PORT, verify_ssl = CONST_SSL)
             responses.add(responses.PUT, '{}:{}'.format(CONST_BASE_URL,CONST_PORT) + "/api/files/productpictures/MS5qcGc=", status=400)
             assert api_client.upload_product_picture(1,"/somepath/pic.jpg").status_code != 204
Exemple #2
0
 def get_details(self, api_client: GrocyApiClient):
     if self.recipe_id:
         recipe = api_client.get_recipe(self.recipe_id)
         if recipe:
             self._recipe = RecipeItem(recipe)
     if self.section_id:
         section = api_client.get_meal_plan_section(self.section_id)
         if section:
             self._section = MealPlanSection(section)
Exemple #3
0
 def test_upload_product_picture_invalid_missing_data(self):
     with patch("os.path.exists") as m_exist:
         m_exist.return_value = False
         api_client = GrocyApiClient("https://example.com", "api_key")
         responses.add(
             responses.PUT,
             "https://example.com:9192/api/files/productpictures/MS5qcGc=",
             status=204)
         assert api_client.upload_product_picture(
             1, "/somepath/pic.jpg") is None
Exemple #4
0
 def test_upload_product_picture_error(self):
     with patch("os.path.exists") as m_exist:
         with patch("builtins.open", mock_open()) as m_open:
             m_exist.return_value = True
             api_client = GrocyApiClient("https://example.com", "api_key")
             responses.add(
                 responses.PUT,
                 "https://example.com:9192/api/files/productpictures/MS5qcGc=",
                 status=400)
             assert api_client.upload_product_picture(
                 1, "/somepath/pic.jpg").status_code != 204
Exemple #5
0
 def get_details(self, api_client: GrocyApiClient):
     details = api_client.get_product(self.id)
     if details:
         self._name = details.product.name
         self._barcodes = [
             ProductBarcode(barcode) for barcode in details.barcodes
         ]
         self._product_group_id = details.product.product_group_id
         self._available_amount = details.stock_amount
Exemple #6
0
 def test_update_product_pic_error(self):
     api_client = GrocyApiClient(CONST_BASE_URL,
                                 "demo_mode",
                                 port=CONST_PORT,
                                 verify_ssl=CONST_SSL)
     responses.add(responses.PUT,
                   f"{self.base_url}/objects/products/1",
                   status=400)
     self.assertRaises(GrocyError, api_client.update_product_pic, 1)
Exemple #7
0
    def test_product_get_details_valid(self):
        stock = self.grocy.stock()

        product = stock[0]

        api_client = GrocyApiClient(CONST_BASE_URL, "demo_mode", port = CONST_PORT, verify_ssl = CONST_SSL)
        product.get_details(api_client)

        assert isinstance(product.name, str)
        assert isinstance(product.product_group_id, int)
Exemple #8
0
 def test_upload_product_picture_error(self):
     with patch("os.path.exists") as m_exist:
         with patch("builtins.open", mock_open()) as m_open:
             m_exist.return_value = True
             api_client = GrocyApiClient(CONST_BASE_URL,
                                         "demo_mode",
                                         port=CONST_PORT,
                                         verify_ssl=CONST_SSL)
             responses.add(
                 responses.PUT,
                 f"{self.base_url}/files/productpictures/MS5qcGc=",
                 status=400)
             self.assertRaises(HTTPError, api_client.upload_product_picture,
                               1, "/somepath/pic.jpg")
Exemple #9
0
    def test_product_get_details_invalid_no_data(self):
        current_stock_response = CurrentStockResponse({
            "product_id": 0,
            "amount": "0.33",
            "best_before_date": "2019-05-02"
        })
        product = Product(current_stock_response)

        api_client = GrocyApiClient(CONST_BASE_URL, "demo_mode", port = CONST_PORT, verify_ssl = CONST_SSL)

        responses.add(responses.GET, '{}:{}'.format(CONST_BASE_URL,CONST_PORT) + "/api/stock/products/0", status=200)

        product.get_details(api_client)

        assert product.name is None
Exemple #10
0
    def test_product_get_details_valid(self):
        stock = self.grocy.stock()

        product = stock[0]

        api_client = GrocyApiClient(
            CONST_BASE_URL, "demo_mode", port=CONST_PORT, verify_ssl=CONST_SSL
        )
        product.get_details(api_client)

        self.assertIsInstance(product.name, str)
        self.assertIsInstance(product.id, int)
        self.assertIsInstance(product.available_amount, float)
        self.assertIsInstance(product.best_before_date, datetime)
        if product.barcodes:
            self.assertIsInstance(product.barcodes, (list, str))
        self.assertIsInstance(product.product_group_id, int)
Exemple #11
0
    def test_product_get_details_invalid_no_data(self):
        current_stock_response = CurrentStockResponse({
            "product_id":
            0,
            "amount":
            "0.33",
            "best_before_date":
            "2019-05-02"
        })
        product = Product(current_stock_response)

        api_client = GrocyApiClient("https://example.com/api/", "api_key")

        responses.add(responses.GET,
                      "https://example.com/api/stock/products/0",
                      status=200)

        product.get_details(api_client)

        assert product.name is None
Exemple #12
0
 def get_details(self, api_client: GrocyApiClient):
     details = api_client.get_chore(self.id)
     self._init_from_ChoreDetailsResponse(details)
Exemple #13
0
    def test_product_get_details_valid(self):
        current_stock_response = CurrentStockResponse({
            "product_id":
            0,
            "amount":
            "0.33",
            "best_before_date":
            "2019-05-02"
        })
        product = Product(current_stock_response)

        api_client = GrocyApiClient("https://example.com/api/", "api_key")

        resp = {
            "product": {
                "id": 0,
                "name": "string",
                "description": "string",
                "location_id": 0,
                "qu_id_purchase": 0,
                "qu_id_stock": 0,
                "qu_factor_purchase_to_stock": 0,
                "barcode": "string",
                "min_stock_amount": 0,
                "default_best_before_days": 0,
                "picture_file_name": "string",
                "allow_partial_units_in_stock": True,
                "row_created_timestamp": "2019-05-02T18:30:48.041Z"
            },
            "quantity_unit_purchase": {
                "id": 0,
                "name": "string",
                "name_plural": "string",
                "description": "string",
                "row_created_timestamp": "2019-05-02T18:30:48.041Z"
            },
            "quantity_unit_stock": {
                "id": 0,
                "name": "string",
                "name_plural": "string",
                "description": "string",
                "row_created_timestamp": "2019-05-02T18:30:48.041Z"
            },
            "last_purchased": "2019-05-02",
            "last_used": "2019-05-02T18:30:48.041Z",
            "stock_amount": 0,
            "stock_amount_opened": 0,
            "next_best_before_date": "2019-05-02T18:30:48.041Z",
            "last_price": 0,
            "location": {
                "id": 0,
                "name": "string",
                "description": "string",
                "row_created_timestamp": "2019-05-02T18:30:48.041Z"
            }
        }
        responses.add(responses.GET,
                      "https://example.com/api/stock/products/0",
                      json=resp,
                      status=200)

        product.get_details(api_client)

        assert product.name == "string"
 def test_url_and_port(self):
     client = GrocyApiClient(api_key="",
                             base_url="http://grocy.de",
                             port=1234)
     assert client._base_url == "http://grocy.de:1234/api/"
 def test_url_only(self):
     client = GrocyApiClient(api_key="", base_url="http://grocy.de")
     assert client._base_url == "http://grocy.de:9192/api/"
Exemple #16
0
 def get_details(self, api_client: GrocyApiClient):
     details = api_client.get_product(self.id)
     if details:
         self._name = details.product.name
         self._barcodes = details.product.barcodes
         self._product_group_id = details.product.product_group_id
Exemple #17
0
 def test_update_product_pic_error(self):
     api_client = GrocyApiClient(CONST_BASE_URL, "demo_mode", port = CONST_PORT, verify_ssl = CONST_SSL)
     responses.add(responses.PUT, '{}:{}'.format(CONST_BASE_URL,CONST_PORT) + "/api/objects/products/1", status=400)
     assert api_client.update_product_pic(1).status_code != 204
Exemple #18
0
 def test_upload_product_picture_invalid_missing_data(self):
     with patch("os.path.exists" ) as m_exist:
         m_exist.return_value = False
         api_client = GrocyApiClient(CONST_BASE_URL, "demo_mode", port = CONST_PORT, verify_ssl = CONST_SSL)
         responses.add(responses.PUT, '{}:{}'.format(CONST_BASE_URL,CONST_PORT) + "/api/files/productpictures/MS5qcGc=", status=204)
         assert api_client.upload_product_picture(1,"/somepath/pic.jpg") is None
 def test_url_and_path(self):
     client = GrocyApiClient(api_key="",
                             base_url="http://grocy.de",
                             path="my/custom/path")
     assert client._base_url == "http://grocy.de:9192/my/custom/path/api/"
Exemple #20
0
 def test_update_product_pic_error(self):
     api_client = GrocyApiClient("https://example.com", "api_key")
     responses.add(responses.PUT,
                   "https://example.com:9192/api/objects/products/1",
                   status=400)
     assert api_client.update_product_pic(1).status_code != 204
Exemple #21
0
 def get_details(self, api_client: GrocyApiClient):
     if self._product_id:
         self._product = Product(api_client.get_product(self._product_id))
Exemple #22
0
 def get_details(self, api_client: GrocyApiClient):
     recipe = api_client.get_recipe(self.recipe_id)
     if recipe:
         self._recipe = RecipeItem(recipe)