from twisted.internet.defer import inlineCallbacks

from vumi.application.tests.utils import ApplicationTestCase
from vumi.demos.static_reply import StaticReplyApplication


class TestStaticReplyApplication(ApplicationTestCase):
    application_class = StaticReplyApplication

    @inlineCallbacks
    def test_receive_message(self):
        yield self.get_application(config={
            'reply_text': 'Your message is important to us.',
        })
        yield self.dispatch(self.mkmsg_in())
        [reply] = yield self.get_dispatched_messages()
        self.assertEqual('Your message is important to us.', reply['content'])
        self.assertEqual(u'close', reply['session_event'])

    @inlineCallbacks
    def test_receive_message_no_reply(self):
        yield self.get_application(config={})
        yield self.dispatch(self.mkmsg_in())
        self.assertEqual([], (yield self.get_dispatched_messages()))

from twisted.internet.defer import inlineCallbacks

from vumi.application.tests.helpers import ApplicationHelper
from vumi.demos.static_reply import StaticReplyApplication
from vumi.tests.helpers import VumiTestCase


class TestStaticReplyApplication(VumiTestCase):
    def setUp(self):
        self.app_helper = ApplicationHelper(StaticReplyApplication)
        self.add_cleanup(self.app_helper.cleanup)

    @inlineCallbacks
    def test_receive_message(self):
        yield self.app_helper.get_application({
            'reply_text': 'Your message is important to us.',
        })
        yield self.app_helper.make_dispatch_inbound("Hello")
        [reply] = self.app_helper.get_dispatched_outbound()
        self.assertEqual('Your message is important to us.', reply['content'])
        self.assertEqual(u'close', reply['session_event'])

    @inlineCallbacks
    def test_receive_message_no_reply(self):
        yield self.app_helper.get_application({})
        yield self.app_helper.make_dispatch_inbound("Hello")
        self.assertEqual([], self.app_helper.get_dispatched_outbound())

Switch static_reply tests to new helpers.
Switch static_reply tests to new helpers.

  from twisted.internet.defer import inlineCallbacks
  
- from vumi.application.tests.utils import ApplicationTestCase
+ from vumi.application.tests.helpers import ApplicationHelper
  from vumi.demos.static_reply import StaticReplyApplication
+ from vumi.tests.helpers import VumiTestCase
  
  
- class TestStaticReplyApplication(ApplicationTestCase):
+ class TestStaticReplyApplication(VumiTestCase):
-     application_class = StaticReplyApplication
+     def setUp(self):
+         self.app_helper = ApplicationHelper(StaticReplyApplication)
+         self.add_cleanup(self.app_helper.cleanup)
  
      @inlineCallbacks
      def test_receive_message(self):
-         yield self.get_application(config={
+         yield self.app_helper.get_application({
              'reply_text': 'Your message is important to us.',
          })
-         yield self.dispatch(self.mkmsg_in())
-         [reply] = yield self.get_dispatched_messages()
+         yield self.app_helper.make_dispatch_inbound("Hello")
+         [reply] = self.app_helper.get_dispatched_outbound()
          self.assertEqual('Your message is important to us.', reply['content'])
          self.assertEqual(u'close', reply['session_event'])
  
      @inlineCallbacks
      def test_receive_message_no_reply(self):
-         yield self.get_application(config={})
+         yield self.app_helper.get_application({})
-         yield self.dispatch(self.mkmsg_in())
-         self.assertEqual([], (yield self.get_dispatched_messages()))
+         yield self.app_helper.make_dispatch_inbound("Hello")
+         self.assertEqual([], self.app_helper.get_dispatched_outbound())
  
Switch static_reply tests to new helpers.
## Code Before:
from twisted.internet.defer import inlineCallbacks

from vumi.application.tests.utils import ApplicationTestCase
from vumi.demos.static_reply import StaticReplyApplication


class TestStaticReplyApplication(ApplicationTestCase):
    application_class = StaticReplyApplication

    @inlineCallbacks
    def test_receive_message(self):
        yield self.get_application(config={
            'reply_text': 'Your message is important to us.',
        })
        yield self.dispatch(self.mkmsg_in())
        [reply] = yield self.get_dispatched_messages()
        self.assertEqual('Your message is important to us.', reply['content'])
        self.assertEqual(u'close', reply['session_event'])

    @inlineCallbacks
    def test_receive_message_no_reply(self):
        yield self.get_application(config={})
        yield self.dispatch(self.mkmsg_in())
        self.assertEqual([], (yield self.get_dispatched_messages()))

## Instruction:
Switch static_reply tests to new helpers.
## Code After:
from twisted.internet.defer import inlineCallbacks

from vumi.application.tests.helpers import ApplicationHelper
from vumi.demos.static_reply import StaticReplyApplication
from vumi.tests.helpers import VumiTestCase


class TestStaticReplyApplication(VumiTestCase):
    def setUp(self):
        self.app_helper = ApplicationHelper(StaticReplyApplication)
        self.add_cleanup(self.app_helper.cleanup)

    @inlineCallbacks
    def test_receive_message(self):
        yield self.app_helper.get_application({
            'reply_text': 'Your message is important to us.',
        })
        yield self.app_helper.make_dispatch_inbound("Hello")
        [reply] = self.app_helper.get_dispatched_outbound()
        self.assertEqual('Your message is important to us.', reply['content'])
        self.assertEqual(u'close', reply['session_event'])

    @inlineCallbacks
    def test_receive_message_no_reply(self):
        yield self.app_helper.get_application({})
        yield self.app_helper.make_dispatch_inbound("Hello")
        self.assertEqual([], self.app_helper.get_dispatched_outbound())
