33# Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved.
44
55import os
6+ import pytest
67import unittest
78from mock import patch
89from connect .resources .asset_request import AssetRequestResource
910from connect .config import Config
10- from .common import Response , load_str
11+ from .common import load_str
1112
1213update_param_asset_request_response = load_str (
1314 os .path .join (os .path .dirname (__file__ ), 'data' , 'update_param_asset_request_response.json' ))
@@ -17,19 +18,33 @@ class TestAssetRequest(unittest.TestCase):
1718 def setUp (self ):
1819 self .config = Config (file = 'tests/config.json' )
1920
20- @patch ('requests.post' )
21- def update_param_asset_request (self , post_mock ):
22- post_mock .return_value = Response (True , update_param_asset_request_response , 200 )
21+ @patch ('requests.put' )
22+ def test_update_param_asset_request (self , put_mock ):
2323 request = AssetRequestResource (config = self .config )
2424 pr_id = 'PR-4405-9454-9305-001'
25- asset_request = request (pr_id )
26- assert post_mock .call_count == 1
27- post_mock .assert_called_with (
25+ test_data = {
26+ "params" : [{
27+ "id" : "PM-9861-7949-8492-0001" ,
28+ "value" : "32323323"
29+ }]
30+ }
31+ request .update_param_asset_request (pr_id , test_data , "i'm a note!" )
32+ assert put_mock .call_count == 1
33+ put_mock .assert_called_with (
2834 headers = {'Content-Type' : 'application/json' , 'Authorization' : 'ApiKey XXXX:YYYYY' },
2935 timeout = 300 ,
3036 url = ('http://localhost:8080/api/public/v1/'
31- 'tier/requests/PR-4405-9454-9305-001' ))
32- assert asset_request .id == 'PR-4405-9454-9305-001'
37+ 'requests/PR-4405-9454-9305-001/' ),
38+ json = {
39+ 'asset' : test_data ,
40+ 'note' : "i'm a note!" ,
41+ })
42+
43+ def test_invalid_request_id (self ):
44+ asset_request = AssetRequestResource (config = self .config )
45+ with pytest .raises (ValueError ) as e :
46+ asset_request .update_param_asset_request (None , None , None )
47+ assert str (e .value ) == 'Invalid ID'
3348
3449
3550if __name__ == "__main__" :
0 commit comments