Esempio n. 1
0
    def test_post(self, mocker, can_update, can_access, is_source, is_up_on_proj, expected):
        class InventoryUpdate:
            id = 1

        class Project:
            name = 'project'

        InventorySource = namedtuple('InventorySource', ['source', 'update_on_project_update', 'pk', 'can_update',
                                                         'update', 'source_project'])

        class InventorySources(object):
            def all(self):
                return [InventorySource(pk=1, source=is_source, source_project=Project,
                                        update_on_project_update=is_up_on_proj,
                                        can_update=can_update, update=lambda:InventoryUpdate)]

            def exclude(self, **kwargs):
                return self.all()

        Inventory = namedtuple('Inventory', ['inventory_sources', 'kind'])
        obj = Inventory(inventory_sources=InventorySources(), kind='')

        mock_request = mocker.MagicMock()
        mock_request.user.can_access.return_value = can_access

        with mocker.patch.object(InventoryInventorySourcesUpdate, 'get_object', return_value=obj):
            with mocker.patch.object(InventoryInventorySourcesUpdate, 'get_serializer_context', return_value=None):
                with mocker.patch('awx.api.views.InventoryUpdateSerializer') as serializer_class:
                    serializer = serializer_class.return_value
                    serializer.to_representation.return_value = {}

                    view = InventoryInventorySourcesUpdate()
                    response = view.post(mock_request)
                    assert response.data == expected
Esempio n. 2
0
     InventoryRootGroupsList.as_view(),
     name='inventory_root_groups_list'),
 url(r'^(?P<pk>[0-9]+)/variable_data/$',
     InventoryVariableData.as_view(),
     name='inventory_variable_data'),
 url(r'^(?P<pk>[0-9]+)/script/$',
     InventoryScriptView.as_view(),
     name='inventory_script_view'),
 url(r'^(?P<pk>[0-9]+)/tree/$',
     InventoryTreeView.as_view(),
     name='inventory_tree_view'),
 url(r'^(?P<pk>[0-9]+)/inventory_sources/$',
     InventoryInventorySourcesList.as_view(),
     name='inventory_inventory_sources_list'),
 url(r'^(?P<pk>[0-9]+)/update_inventory_sources/$',
     InventoryInventorySourcesUpdate.as_view(),
     name='inventory_inventory_sources_update'),
 url(r'^(?P<pk>[0-9]+)/activity_stream/$',
     InventoryActivityStreamList.as_view(),
     name='inventory_activity_stream_list'),
 url(r'^(?P<pk>[0-9]+)/job_templates/$',
     InventoryJobTemplateList.as_view(),
     name='inventory_job_template_list'),
 url(r'^(?P<pk>[0-9]+)/ad_hoc_commands/$',
     InventoryAdHocCommandsList.as_view(),
     name='inventory_ad_hoc_commands_list'),
 url(r'^(?P<pk>[0-9]+)/access_list/$',
     InventoryAccessList.as_view(),
     name='inventory_access_list'),
 url(r'^(?P<pk>[0-9]+)/object_roles/$',
     InventoryObjectRolesList.as_view(),