示例#1
0
    def testCreateSubscription(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.CreateSubscription.return_value = show_pb2.ShowCreateSubscriptionResponse(
            subscription=subscription_pb2.Subscription(
                name=TEST_SUBSCRIPTION_NAME,
                size=TEST_SUBSCRIPTION_SIZE,
                burst=TEST_SUBSCRIPTION_BURST))
        getStubMock.return_value = stubMock

        show = opencue.wrappers.show.Show(show_pb2.Show(name=TEST_SHOW_NAME))
        allocation = opencue.wrappers.allocation.Allocation(
            facility_pb2.Allocation(id=TEST_ALLOCATION_ID))
        subscription = show.createSubscription(allocation,
                                               TEST_SUBSCRIPTION_SIZE,
                                               TEST_SUBSCRIPTION_BURST)

        stubMock.CreateSubscription.assert_called_with(
            show_pb2.ShowCreateSubscriptionRequest(
                show=show.data,
                allocation_id=TEST_ALLOCATION_ID,
                size=TEST_SUBSCRIPTION_SIZE,
                burst=TEST_SUBSCRIPTION_BURST),
            timeout=mock.ANY)
        self.assertEqual(subscription.size(), TEST_SUBSCRIPTION_SIZE)
        self.assertEqual(subscription.burst(), TEST_SUBSCRIPTION_BURST)
示例#2
0
    def testSetDefaultAlloc(self, getStubMock):
        alloc = facility_pb2.Allocation(name=TEST_ALLOC_NAME)
        stubMock = mock.Mock()
        stubMock.SetDefault.return_value = facility_pb2.AllocSetDefaultResponse()
        getStubMock.return_value = stubMock

        opencue.api.setDefaultAllocation(alloc)

        stubMock.SetDefault.assert_called_with(
            facility_pb2.AllocSetDefaultRequest(allocation=alloc), timeout=mock.ANY)
示例#3
0
    def testDeleteAlloc(self, getStubMock):
        allocToDelete = facility_pb2.Allocation(name=TEST_ALLOC_NAME)
        stubMock = mock.Mock()
        stubMock.Delete.return_value = facility_pb2.AllocDeleteResponse()
        getStubMock.return_value = stubMock

        opencue.api.deleteAllocation(allocToDelete)

        stubMock.Delete.assert_called_with(
            facility_pb2.AllocDeleteRequest(allocation=allocToDelete), timeout=mock.ANY)
示例#4
0
    def testAllocSetTag(self, getStubMock):
        alloc = facility_pb2.Allocation(name=TEST_ALLOC_NAME)
        newTag = 'arbitrary-tag'
        stubMock = mock.Mock()
        stubMock.SetTag.return_value = facility_pb2.AllocSetTagResponse()
        getStubMock.return_value = stubMock

        opencue.api.allocSetTag(alloc, newTag)

        stubMock.SetTag.assert_called_with(
            facility_pb2.AllocSetTagRequest(allocation=alloc, tag=newTag), timeout=mock.ANY)
示例#5
0
    def testAllocSetName(self, getStubMock):
        alloc = facility_pb2.Allocation(name=TEST_ALLOC_NAME)
        newName = 'arbitrary-name'
        stubMock = mock.Mock()
        stubMock.SetName.return_value = facility_pb2.AllocSetNameResponse()
        getStubMock.return_value = stubMock

        opencue.api.allocSetName(alloc, newName)

        stubMock.SetName.assert_called_with(
            facility_pb2.AllocSetNameRequest(allocation=alloc, name=newName), timeout=mock.ANY)
示例#6
0
    def testFindAlloc(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.Find.return_value = facility_pb2.AllocFindResponse(
            allocation=facility_pb2.Allocation(name=TEST_ALLOC_NAME))
        getStubMock.return_value = stubMock

        alloc = opencue.api.findAllocation(TEST_ALLOC_NAME)

        stubMock.Find.assert_called_with(
            facility_pb2.AllocFindRequest(name=TEST_ALLOC_NAME), timeout=mock.ANY)
        self.assertEqual(TEST_ALLOC_NAME, alloc.name())
示例#7
0
    def testGetAllocs(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.GetAll.return_value = facility_pb2.AllocGetAllResponse(
            allocations=facility_pb2.AllocationSeq(allocations=[facility_pb2.Allocation(name=TEST_ALLOC_NAME)]))
        getStubMock.return_value = stubMock

        allocs = opencue.api.getAllocations()

        stubMock.GetAll.assert_called_with(
            facility_pb2.AllocGetAllRequest(), timeout=mock.ANY)
        self.assertEqual([TEST_ALLOC_NAME], [alloc.name() for alloc in allocs])
示例#8
0
    def testDelete(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.Delete.return_value = facility_pb2.AllocDeleteResponse()
        getStubMock.return_value = stubMock

        alloc = opencue.wrappers.allocation.Allocation(
            facility_pb2.Allocation(name=TEST_ALLOC_NAME))
        alloc.delete()

        stubMock.Delete.assert_called_with(
            facility_pb2.AllocDeleteRequest(allocation=alloc.data), timeout=mock.ANY)
示例#9
0
    def setTag(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.SetTag.return_value = facility_pb2.AllocSetTagResponse()
        getStubMock.return_value = stubMock

        alloc = opencue.wrappers.allocation.Allocation(facility_pb2.Allocation())
        alloc.setTag(TEST_ALLOC_TAG)

        stubMock.SetTag.assert_called_with(
            facility_pb2.AllocSetTagRequest(allocation=alloc.data, tag=TEST_ALLOC_TAG),
            timeout=mock.ANY)
示例#10
0
    def testAllocSetBillable(self, getStubMock):
        alloc = facility_pb2.Allocation(name=TEST_ALLOC_NAME)
        isBillable = True
        stubMock = mock.Mock()
        stubMock.SetBillable.return_value = facility_pb2.AllocSetBillableResponse()
        getStubMock.return_value = stubMock

        opencue.api.allocSetBillable(alloc, isBillable)

        stubMock.SetBillable.assert_called_with(
            facility_pb2.AllocSetBillableRequest(allocation=alloc, value=isBillable),
            timeout=mock.ANY)
示例#11
0
    def testGetDefaultAlloc(self, getStubMock):
        arbitraryId = '00000000-0000-0000-0000-012345678980'
        stubMock = mock.Mock()
        stubMock.GetDefault.return_value = facility_pb2.AllocGetDefaultResponse(
            allocation=facility_pb2.Allocation(id=arbitraryId))
        getStubMock.return_value = stubMock

        alloc = opencue.api.getDefaultAllocation()

        stubMock.GetDefault.assert_called_with(
            facility_pb2.AllocGetDefaultRequest(), timeout=mock.ANY)
        self.assertEqual(arbitraryId, alloc.id())
示例#12
0
    def testCreateAlloc(self, getStubMock):
        facility = facility_pb2.Facility(name=TEST_FACILITY_NAME)
        stubMock = mock.Mock()
        stubMock.Create.return_value = facility_pb2.AllocCreateResponse(
            allocation=facility_pb2.Allocation(name=TEST_ALLOC_NAME))
        getStubMock.return_value = stubMock

        alloc = opencue.api.createAllocation(TEST_ALLOC_NAME, TEST_TAG, facility)

        stubMock.Create.assert_called_with(
            facility_pb2.AllocCreateRequest(name=TEST_ALLOC_NAME, tag=TEST_TAG, facility=facility),
            timeout=mock.ANY)
        self.assertEqual(TEST_ALLOC_NAME, alloc.name())
示例#13
0
 def testReparentHostIds(self, getStubMock):
     stubMock = mock.Mock()
     stubMock.ReparentHosts.return_value = facility_pb2.AllocReparentHostsResponse()
     getStubMock.return_value = stubMock
 
     alloc = opencue.wrappers.allocation.Allocation(
         facility_pb2.Allocation(name=TEST_ALLOC_NAME))
     hostIds = [TEST_HOST_ID]
     alloc.reparentHostIds(hostIds)
     hosts = [host_pb2.Host(id=TEST_HOST_ID)]
 
     stubMock.ReparentHosts.assert_called_with(
         facility_pb2.AllocReparentHostsRequest(
             allocation=alloc.data, hosts=host_pb2.HostSeq(hosts=hosts)), timeout=mock.ANY)
示例#14
0
    def testSetAllocation(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.SetAllocation.return_value = host_pb2.HostSetAllocationResponse()
        getStubMock.return_value = stubMock

        allocId = 'aaa-aaaa-aaa'
        alloc = opencue.wrappers.allocation.Allocation(facility_pb2.Allocation(id=allocId))
        host = opencue.wrappers.host.Host(
            host_pb2.Host(name=TEST_HOST_NAME))
        host.setAllocation(alloc)

        stubMock.SetAllocation.assert_called_with(
            host_pb2.HostSetAllocationRequest(host=host.data, allocation_id=alloc.id()),
            timeout=mock.ANY)
示例#15
0
    def testGetHosts(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.GetHosts.return_value = facility_pb2.AllocGetHostsResponse(
            hosts=host_pb2.HostSeq(hosts=[host_pb2.Host(name=TEST_HOST_NAME)]))
        getStubMock.return_value = stubMock

        alloc = opencue.wrappers.allocation.Allocation(
            facility_pb2.Allocation(name=TEST_ALLOC_NAME))
        hosts = alloc.getHosts()

        stubMock.GetHosts.assert_called_with(
            facility_pb2.AllocGetHostsRequest(allocation=alloc.data),
            timeout=mock.ANY)
        self.assertEqual(len(hosts), 1)
        self.assertEqual(hosts[0].name(), TEST_HOST_NAME)
示例#16
0
    def testGetSubscriptions(self, getStubMock):
        stubMock = mock.Mock()
        stubMock.GetSubscriptions.return_value = facility_pb2.AllocGetSubscriptionsResponse(
            subscriptions=subscription_pb2.SubscriptionSeq(
                subscriptions=[subscription_pb2.Subscription(name=TEST_SUBSCRIPTION_NAME)]))
        getStubMock.return_value = stubMock

        alloc = opencue.wrappers.allocation.Allocation(
            facility_pb2.Allocation(name=TEST_ALLOC_NAME))
        subscriptions = alloc.getSubscriptions()

        stubMock.GetSubscriptions.assert_called_with(
            facility_pb2.AllocGetSubscriptionsRequest(allocation=alloc.data), timeout=mock.ANY)
        self.assertEqual(len(subscriptions), 1)
        self.assertEqual(subscriptions[0].name(), TEST_SUBSCRIPTION_NAME)