def test_receiver_notify_not_found(self, mock_find): mock_find.side_effect = exc.ResourceNotFound(type='receiver', id='RR') req = orro.ReceiverNotifyRequest(identity='Bogus') ex = self.assertRaises(rpc.ExpectedException, self.eng.receiver_notify, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
def test_receiver_notify_permission_check_fail(self, mock_find): fake_obj = mock.Mock() fake_obj.id = 'FAKE_ID' fake_obj.user = '******' mock_find.return_value = fake_obj req = orro.ReceiverNotifyRequest(identity='FAKE_RECEIVER') ex = self.assertRaises(rpc.ExpectedException, self.eng.receiver_notify, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.Forbidden, ex.exc_info[0])
def test_receiver_notify_incorrect_type(self, mock_find): fake_obj = mock.Mock() fake_obj.id = 'FAKE_ID' fake_obj.user = self.ctx.user fake_obj.type = 'not_message' mock_find.return_value = fake_obj req = orro.ReceiverNotifyRequest(identity='FAKE_RECEIVER') ex = self.assertRaises(rpc.ExpectedException, self.eng.receiver_notify, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.BadRequest, ex.exc_info[0])
def test_receiver_notify(self, mock_find, mock_load): fake_obj = mock.Mock() fake_obj.id = 'FAKE_ID' fake_obj.type = 'message' fake_obj.user = self.ctx.user_id fake_receiver = mock.Mock() mock_find.return_value = fake_obj mock_load.return_value = fake_receiver req = orro.ReceiverNotifyRequest(identity='FAKE_RECEIVER') result = self.eng.receiver_notify(self.ctx, req.obj_to_primitive()) self.assertIsNone(result) mock_find.assert_called_once_with(self.ctx, 'FAKE_RECEIVER') mock_load.assert_called_once_with(self.ctx, receiver_obj=fake_obj, project_safe=True) fake_receiver.notify.assert_called_once_with(self.ctx)
def test_receiver_notify_request(self): params = {'identity': 'receiver-001'} sot = receivers.ReceiverNotifyRequest(**params) self.assertEqual('receiver-001', sot.identity)