def test_items(self):
        product_resource = ProductsResource(config=self.config)
        item_resource = product_resource.items('PRD-000')
        assert item_resource.resource == 'products/PRD-000/items'
        assert item_resource.model_class == Item

        item_resource = product_resource.items('PRD-001')
        assert item_resource.resource == 'products/PRD-001/items'
 def test_delete_parameter(self, delete_mock):
     delete_mock.return_value = Response(True, '[]', 204)
     request = ProductsResource(config=self.config)
     request.delete_parameter('PRD-075-401-854', 'PRM-075-401-854-0004')
     url = ('http://localhost:8080/public/v1'
            '/products/PRD-075-401-854/parameters/PRM-075-401-854-0004')
     delete_mock.assert_called_with(headers={
         'Content-Type': 'application/json',
         'Authorization': 'ApiKey XXXX:YYYYY'
     },
                                    timeout=300,
                                    url=url)
 def test_modify_parameter(self, put_mock):
     modify_parameter_response = create_parameter_response
     put_mock.return_value = Response(True, modify_parameter_response, 200)
     body = modify_parameter_response
     request = ProductsResource(config=self.config)
     request.update_parameter('PRD-075-401-854', 'PRM-075-401-854-0004',
                              body)
     url = ('http://localhost:8080/public/v1'
            '/products/PRD-075-401-854/parameters/PRM-075-401-854-0004')
     put_mock.assert_called_with(headers={
         'Content-Type': 'application/json',
         'Authorization': 'ApiKey XXXX:YYYYY'
     },
                                 json=body,
                                 timeout=300,
                                 url=url)
    def test_create_parameter(self, post_mock):
        # type: (Mock) -> None
        post_mock.return_value = Response(True, create_parameter_response, 200)
        body = create_parameter_body
        request = ProductsResource(config=self.config)
        request.create_parameter('PRD-075-401-854', body)

        post_mock.assert_called_with(
            headers={
                'Content-Type': 'application/json',
                'Authorization': 'ApiKey XXXX:YYYYY'
            },
            json=body,
            timeout=300,
            url=
            'http://localhost:8080/public/v1/products/PRD-075-401-854/parameters/'
        )
    def test_parameter_empty(self, get_mock):
        # type: (Mock) -> None
        get_mock.return_value = Response(True, '[]', 200)

        request = ProductsResource(config=self.config)
        result = request.list_parameters('PRD-000-000-000')
        assert get_mock.call_count == 1
        url = 'http://localhost:8080/public/v1/products/PRD-000-000-000/parameters/'
        get_mock.assert_has_calls([
            call(headers={
                'Content-Type': 'application/json',
                'Authorization': 'ApiKey XXXX:YYYYY'
            },
                 timeout=300,
                 url=url)
        ])
        self.assertEqual(result, [], msg=None)
    def test_parameters_request_ok(self, get_mock):
        # type: (Mock) -> None
        get_mock.side_effect = [
            Response(True, '[' + get_parameters_contents + ']', 200),
            Response(True, get_parameters_contents, 200)
        ]

        request = ProductsResource(config=self.config)
        result = request.list_parameters('PRD-075-401-854')
        assert get_mock.call_count == 1
        self.assertEqual(len(result), 1, msg=None)

        get_mock.assert_has_calls([
            call(headers={
                'Content-Type': 'application/json',
                'Authorization': 'ApiKey XXXX:YYYYY'
            },
                 timeout=300,
                 url=('http://localhost:8080/public/v1/'
                      'products/PRD-075-401-854/parameters/'))
        ])
Exemple #7
0
 def delete_parameter(self, product_id, param_id):
     product = ProductsResource(config=self.configuration)
     return product.delete_parameter(product_id, param_id)
Exemple #8
0
 def update_parameter(self, product_id, parameter_id, body):
     product = ProductsResource(config=self.configuration)
     return product.update_parameter(product_id, parameter_id, body)
Exemple #9
0
 def list_parameters(self, product_id):
     product = ProductsResource(config=self.configuration)
     return product.list_parameters(product_id)
 def test_create_parameter_bad(self):
     request = ProductsResource(config=self.config)
     with pytest.raises(ValueError) as e:
         request.create_parameter(None, None)
     assert str(e.value) == 'Invalid ID'