Example #1
0
    def test_update_order_status(self):

        rehome_status = OrderLock.COMPLETED
        plan_id = uuid.uuid4()
        plans = {plan_id: '{"status": "under-spin-up"}'}
        order_lock_inst = OrderLock(id='conflict_id')
        order_lock_inst.update = mock.MagicMock(return_value=None)
        actual_response = self.order_lock_svc._update_order_status(
            rehome_status=rehome_status,
            plans=plans,
            order_lock=order_lock_inst)

        self.assertEqual(actual_response, {plan_id: OrderLock.COMPLETED})
Example #2
0
class TestOrder_Lock(unittest.TestCase):
    def setUp(self):
        self.orderLock = OrderLock()

    def testOrderLock(self):
        self.assertEqual(True, self.orderLock.atomic())
        self.assertEqual("id", self.orderLock.pk_name())
        self.assertEqual(None, self.orderLock.pk_value())

        self.values = {
            'is_spinup_completed': False,
            'id': None,
            'spinup_completed_timestamp': None,
            'plans': None
        }
        self.assertEqual(self.values, self.orderLock.values())

        self.reprVal = '<OrderLock None>'
        self.assertEqual(self.reprVal, self.orderLock.__repr__())

        self.assertEqual(False,
                         self.orderLock.__json__().get('is_spinup_completed'))

        self.schema = {
            'PRIMARY KEY': '(id)',
            'is_spinup_completed': 'boolean',
            'id': 'text',
            'spinup_completed_timestamp': 'bigint',
            'plans': 'map<text, text>'
        }

        self.assertEqual(self.schema, self.orderLock.schema())
Example #3
0
    def test_get_plans_by_id(self):

        plan_id = uuid.uuid4()
        plans = {
            plan_id: '{'
                     '"status": "under-spin-up",'
                     '"service_resource_id": "resource-id"'
                     '}'
        }
        order_locks = [OrderLock(id='conflict_id', plans=plans)]
        self.order_lock_svc.OrderLock.query = mock.MagicMock(return_value=None)
        self.order_lock_svc.OrderLock.query.get_plan_by_col = mock.MagicMock(return_value=order_locks)
        actual_response = self.order_lock_svc._get_plans_by_id('order_id')

        self.assertEquals(actual_response, plans)
Example #4
0
    def test_rehomes_for_service_resource(self):

        plan_id = uuid.uuid4()
        plans = {
            plan_id: '{'
                         '"status": "rehome",'
                         '"service_resource_id": "resource-id"'
                     '}'
        }
        order_locks = [OrderLock(id='conflict_id', plans=plans)]

        rehome_status = OrderLock.COMPLETED
        self.order_lock_svc.update_order_status_and_get_effected_plans = mock.MagicMock(return_value=plans)
        self.order_lock_svc.OrderLock.query = mock.MagicMock(return_value=None)
        self.order_lock_svc.OrderLock.query.all = mock.MagicMock(return_value=order_locks)

        actual_response = self.order_lock_svc.rehomes_for_service_resource(rehome_status, 'resource-id', list())
        expect_response = [{'plan_id': plan_id, 'should_rehome': True}]

        self.assertEquals(actual_response, expect_response)
Example #5
0
    def test_update_order_status_and_get_effected_plans(self):

        plan_id = uuid.uuid4()
        plans = {
            plan_id: '{'
                         '"status": "under-spin-up",'
                         '"service_resource_id": "resource-id"'
                     '}'
        }
        order_locks = [OrderLock(id='conflict_id', plans=plans)]
        rehome_status = OrderLock.COMPLETED

        self.order_lock_svc.OrderLock.query = mock.MagicMock(return_value=None)
        self.order_lock_svc.OrderLock.query.all = mock.MagicMock(return_value=order_locks)
        self.order_lock_svc._update_order_status = mock.MagicMock(return_value=None)
        self.order_lock_svc._get_plans_by_id = mock.MagicMock(return_value=plans)

        actual_response = self.order_lock_svc.update_order_status_and_get_effected_plans(rehome_status=rehome_status,
                                                                                         service_resource_id='resource-id')
        self.assertEquals(actual_response, plans)
Example #6
0
 def setUp(self):
     self.orderLock = OrderLock()