def test_get_assets(self, return_value, side_effect=None, code=200, error_msg=None, pagination=None, user=None): # Mock get asset_manager method resource_collection = views.AssetCollection( permitted_methods=('GET', )) self.am_instance.get_provider_assets_info.return_value = return_value path = '/api/offering/resources' if pagination is not None: path += '?offset=' + pagination['offset'] + '&size=' + pagination[ 'size'] if user is not None: path += "{}user={}".format("&" if "?" in path else "?", user) request = self.factory.get(path, HTTP_ACCEPT='application/json') request.user = self.user # Create the side effect if needed if side_effect: side_effect(self) views.User.reset_mock() views.UserProfile.reset_mock() # Call the view response = resource_collection.read(request) self.assertEquals(response.status_code, code) self.assertEqual(response.get('Content-type'), 'application/json; charset=utf-8') body_response = json.loads(response.content) if not error_msg: views.AssetManager.assert_called_once_with() if user is not None: views.User.objects.get.assert_called_with(username=user) views.UserProfile.objects.get.assert_called_with( user=views.User.objects.get()) user_called = self.user.userprofile if user is None else views.UserProfile.objects.get( ) self.am_instance.get_provider_assets_info.assert_called_once_with( user_called, pagination=pagination) self.assertEquals(type(body_response), list) self.assertEquals(body_response, return_value) else: self.assertEqual(type(body_response), dict) self.assertEqual(body_response['error'], error_msg) self.assertEqual(body_response['result'], 'error')
# along with this program. If not, see <http://www.gnu.org/licenses/>. from django.conf.urls import url from wstore.admin import views as admin_views from wstore.asset_manager import views as offering_views from wstore.asset_manager.resource_plugins import views as plugins_views from wstore.ordering import views as ordering_views from wstore.charging_engine import views as charging_views from wstore.charging_engine.accounting import views as accounting_views from wstore.reports import views as reports_views urlpatterns = [ # API url(r'^charging/api/assetManagement/assets/?$', offering_views.AssetCollection(permitted_methods=('GET', ))), url(r'^charging/api/assetManagement/assets/uploadJob/?$', offering_views.UploadCollection(permitted_methods=('POST', ))), url(r'^charging/api/assetManagement/assets/validateJob/?$', offering_views.ValidateCollection(permitted_methods=('POST', ))), url( r'^charging/api/assetManagement/assets/offeringJob/?$', offering_views.ValidateOfferingCollection( permitted_methods=('POST', ))), url(r'^charging/api/assetManagement/assets/(?P<asset_id>\w+)/?$', offering_views.AssetEntry(permitted_methods=('GET', ))), url( r'^charging/api/assetManagement/assets/(?P<asset_id>\w+)/upgradeJob/?$', offering_views.UpgradeCollection(permitted_methods=('POST', ))), url(r'^charging/api/assetManagement/assets/product/(?P<product_id>\w+)/?$', offering_views.AssetEntryFromProduct(permitted_methods=('GET', ))),
from wstore.asset_manager import views as offering_views from wstore.token import views as token_views from wstore.asset_manager.resource_plugins import views as plugins_views from wstore.ordering import views as ordering_views from wstore.charging_engine import views as charging_views from wstore.charging_engine.accounting import views as accounting_views from wstore.reports import views as reports_views from wstore.product import views as product_views urlpatterns = patterns('', # API url(r'^charging/api/token/?$', token_views.TokenCollection(permitted_methods=('POST',))), url(r'^charging/api/token/refresh?$', token_views.TokenRefresh(permitted_methods=('POST',))), url(r'^charging/api/token/read?$', token_views.TokenRead(permitted_methods=('POST',))), url(r'^charging/api/assetManagement/assets/createProduct?$', product_views.ProductSpecification(permitted_methods=('POST',))), url(r'^charging/api/assetManagement/assets/?$', offering_views.AssetCollection(permitted_methods=('GET',))), url(r'^charging/api/assetManagement/assets/uploadJob/?$', offering_views.UploadCollection(permitted_methods=('POST',))), url(r'^charging/api/assetManagement/assets/validateJob/?$', offering_views.ValidateCollection(permitted_methods=('POST',))), url(r'^charging/api/assetManagement/assets/offeringJob/?$', offering_views.ValidateOfferingCollection(permitted_methods=('POST',))), url(r'^charging/api/assetManagement/assets/(?P<asset_id>\w+)/?$', offering_views.AssetEntry(permitted_methods=('GET',))), url(r'^charging/api/assetManagement/assets/(?P<asset_id>\w+)/upgradeJob/?$', offering_views.UpgradeCollection(permitted_methods=('POST',))), url(r'^charging/api/assetManagement/assets/product/(?P<product_id>\w+)/?$', offering_views.AssetEntryFromProduct(permitted_methods=('GET',))), url(r'^charging/api/assetManagement/assetTypes/?$', plugins_views.PluginCollection(permitted_methods=('GET', ))), url(r'^charging/api/assetManagement/assetTypes/(?P<plugin_id>[\w -]+)/?$', plugins_views.PluginEntry(permitted_methods=('GET',))), url(r'^charging/api/orderManagement/orders/?$', ordering_views.OrderingCollection(permitted_methods=('POST',))), url(r'^charging/api/orderManagement/orders/accept/?$', charging_views.PayPalConfirmation(permitted_methods=('POST',))), url(r'^charging/api/orderManagement/orders/cancel/?$', charging_views.PayPalCancellation(permitted_methods=('POST',))), url(r'^charging/api/orderManagement/orders/refund/?$', charging_views.PayPalRefund(permitted_methods=('POST',))), url(r'^charging/api/orderManagement/products/?$', ordering_views.InventoryCollection(permitted_methods=('POST',))), url(r'^charging/api/orderManagement/products/renewJob/?$', ordering_views.RenovationCollection(permitted_methods=('POST',))),