Django Channels doesn't run basic test case











up vote
0
down vote

favorite












I'm trying to test my consumers with the testing framework from django channels, but even a basic test doesn't seem to work



This is what my test case looks like:



from channels import Channel
from channels.test import ChannelTestCase, HttpClient, apply_routes
from rci.consumers import Demultiplexer
from rosbridge.consumers import OtherWebSocketConsumer

class ChannelTestCase(ChannelTestCase):

def test_channel(self):
client = HttpClient()
client.send_and_consume('websocket.connect', '/new/') # <--- here's the error
self.assertIsNone(client.receive())


This is my routing:



http_routing = [
route("http.request", admin.site.urls, path=r"^/admin/", method=r"^$"),
#...and so on
]

channel_routing = [Demultiplexer.as_route(path=r"^/sock/")]


This is my consumer:



class Demultiplexer(WebsocketDemultiplexer):
channel_session_user = True

consumers = {
"rosbridge": ROSWebSocketConsumer,
"setting": SettingsConsumer,
}


This gives me the following error:




ERROR: test_ros_channel
(robot_configuration_interface.tests.unit.test_channels.ROSChannelTestCase)
---------------------------------------------------------------------- Traceback (most recent call last): File
"/home/cjds/development/robot_configuration_interface/robot_configuration_interface/tests/unit/test_channels.py", line 36, in test_ros_channel
client.send_and_consume('websocket.connect', '/new/') File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
94, in send_and_consume
self.send(channel, content, text, path) File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
79, in send
content.setdefault('reply_channel', self.reply_channel) AttributeError: 'str' object has no attribute 'setdefault'




I'm trying to follow this tutorial here:




http://channels.readthedocs.io/en/stable/testing.html#clients











share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm trying to test my consumers with the testing framework from django channels, but even a basic test doesn't seem to work



    This is what my test case looks like:



    from channels import Channel
    from channels.test import ChannelTestCase, HttpClient, apply_routes
    from rci.consumers import Demultiplexer
    from rosbridge.consumers import OtherWebSocketConsumer

    class ChannelTestCase(ChannelTestCase):

    def test_channel(self):
    client = HttpClient()
    client.send_and_consume('websocket.connect', '/new/') # <--- here's the error
    self.assertIsNone(client.receive())


    This is my routing:



    http_routing = [
    route("http.request", admin.site.urls, path=r"^/admin/", method=r"^$"),
    #...and so on
    ]

    channel_routing = [Demultiplexer.as_route(path=r"^/sock/")]


    This is my consumer:



    class Demultiplexer(WebsocketDemultiplexer):
    channel_session_user = True

    consumers = {
    "rosbridge": ROSWebSocketConsumer,
    "setting": SettingsConsumer,
    }


    This gives me the following error:




    ERROR: test_ros_channel
    (robot_configuration_interface.tests.unit.test_channels.ROSChannelTestCase)
    ---------------------------------------------------------------------- Traceback (most recent call last): File
    "/home/cjds/development/robot_configuration_interface/robot_configuration_interface/tests/unit/test_channels.py", line 36, in test_ros_channel
    client.send_and_consume('websocket.connect', '/new/') File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
    94, in send_and_consume
    self.send(channel, content, text, path) File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
    79, in send
    content.setdefault('reply_channel', self.reply_channel) AttributeError: 'str' object has no attribute 'setdefault'




    I'm trying to follow this tutorial here:




    http://channels.readthedocs.io/en/stable/testing.html#clients











    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to test my consumers with the testing framework from django channels, but even a basic test doesn't seem to work



      This is what my test case looks like:



      from channels import Channel
      from channels.test import ChannelTestCase, HttpClient, apply_routes
      from rci.consumers import Demultiplexer
      from rosbridge.consumers import OtherWebSocketConsumer

      class ChannelTestCase(ChannelTestCase):

      def test_channel(self):
      client = HttpClient()
      client.send_and_consume('websocket.connect', '/new/') # <--- here's the error
      self.assertIsNone(client.receive())


      This is my routing:



      http_routing = [
      route("http.request", admin.site.urls, path=r"^/admin/", method=r"^$"),
      #...and so on
      ]

      channel_routing = [Demultiplexer.as_route(path=r"^/sock/")]


      This is my consumer:



      class Demultiplexer(WebsocketDemultiplexer):
      channel_session_user = True

      consumers = {
      "rosbridge": ROSWebSocketConsumer,
      "setting": SettingsConsumer,
      }


      This gives me the following error:




      ERROR: test_ros_channel
      (robot_configuration_interface.tests.unit.test_channels.ROSChannelTestCase)
      ---------------------------------------------------------------------- Traceback (most recent call last): File
      "/home/cjds/development/robot_configuration_interface/robot_configuration_interface/tests/unit/test_channels.py", line 36, in test_ros_channel
      client.send_and_consume('websocket.connect', '/new/') File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
      94, in send_and_consume
      self.send(channel, content, text, path) File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
      79, in send
      content.setdefault('reply_channel', self.reply_channel) AttributeError: 'str' object has no attribute 'setdefault'




      I'm trying to follow this tutorial here:




      http://channels.readthedocs.io/en/stable/testing.html#clients











      share|improve this question













      I'm trying to test my consumers with the testing framework from django channels, but even a basic test doesn't seem to work



      This is what my test case looks like:



      from channels import Channel
      from channels.test import ChannelTestCase, HttpClient, apply_routes
      from rci.consumers import Demultiplexer
      from rosbridge.consumers import OtherWebSocketConsumer

      class ChannelTestCase(ChannelTestCase):

      def test_channel(self):
      client = HttpClient()
      client.send_and_consume('websocket.connect', '/new/') # <--- here's the error
      self.assertIsNone(client.receive())


      This is my routing:



      http_routing = [
      route("http.request", admin.site.urls, path=r"^/admin/", method=r"^$"),
      #...and so on
      ]

      channel_routing = [Demultiplexer.as_route(path=r"^/sock/")]


      This is my consumer:



      class Demultiplexer(WebsocketDemultiplexer):
      channel_session_user = True

      consumers = {
      "rosbridge": ROSWebSocketConsumer,
      "setting": SettingsConsumer,
      }


      This gives me the following error:




      ERROR: test_ros_channel
      (robot_configuration_interface.tests.unit.test_channels.ROSChannelTestCase)
      ---------------------------------------------------------------------- Traceback (most recent call last): File
      "/home/cjds/development/robot_configuration_interface/robot_configuration_interface/tests/unit/test_channels.py", line 36, in test_ros_channel
      client.send_and_consume('websocket.connect', '/new/') File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
      94, in send_and_consume
      self.send(channel, content, text, path) File "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", line
      79, in send
      content.setdefault('reply_channel', self.reply_channel) AttributeError: 'str' object has no attribute 'setdefault'




      I'm trying to follow this tutorial here:




      http://channels.readthedocs.io/en/stable/testing.html#clients








      python django unit-testing django-channels






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 31 '17 at 18:24









      cjds

      5,67733264




      5,67733264
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          channels 1.x



          You are calling send_and_consume with two positional arguments which results in effect in this call (which is exactly why there happens an error during execution in this line):



          # AGAIN this is wrong code this is what is written in the question
          # only difference is the naming of the (previously positional) arguments
          client.send_and_consume(channel='websocket.connect', content='/new/')


          and here is the explanation why there is an error:



          However, the implementation of send_and_consume expects content to be a dictionary:



          def send_and_consume(self, channel, content={}, text=None, path='/', fail_on_none=True, check_accept=True):
          """
          Reproduce full life cycle of the message
          """
          self.send(channel, content, text, path)
          return self.consume(channel, fail_on_none=fail_on_none, check_accept=check_accept)


          Implementation code taken from: https://github.com/django/channels/blob/master/channels/test/http.py#L92



          channels 2.x



          See https://channels.readthedocs.io/en/latest/topics/testing.html, as mentioned in the comment by Paul Whipp.






          share|improve this answer























          • Marking this down for now because the answers wrong in many ways. For eg. content='/new/' is not correct but path='/new/' is would be correct. I appreciate the effort, and If you can incorporate github.com/django/channels/issues/586 into your answer and remove mistakes I'll mark it right
            – cjds
            Jun 10 '17 at 0:05












          • Well, if you could read the text around the wrong call you would understand that the line you complain about, especially content='/new' is your line of code, and - of course - it is wrong because content has to be a dictionary as I have already stated in my answer above.
            – Risadinha
            Jun 12 '17 at 15:07










          • @cjds: You should reconsider whats written in the answer, this looks correct to me!
            – Amir Hadi
            Oct 2 '17 at 18:52










          • Thanks @AmirHadi I didn't see the edit. Marking correct
            – cjds
            Oct 2 '17 at 19:33










          • This question and answer apply to channels 1.x. For 2.x see channels.readthedocs.io/en/latest/topics/testing.html
            – Paul Whipp
            Nov 18 at 19:42











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43147315%2fdjango-channels-doesnt-run-basic-test-case%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          channels 1.x



          You are calling send_and_consume with two positional arguments which results in effect in this call (which is exactly why there happens an error during execution in this line):



          # AGAIN this is wrong code this is what is written in the question
          # only difference is the naming of the (previously positional) arguments
          client.send_and_consume(channel='websocket.connect', content='/new/')


          and here is the explanation why there is an error:



          However, the implementation of send_and_consume expects content to be a dictionary:



          def send_and_consume(self, channel, content={}, text=None, path='/', fail_on_none=True, check_accept=True):
          """
          Reproduce full life cycle of the message
          """
          self.send(channel, content, text, path)
          return self.consume(channel, fail_on_none=fail_on_none, check_accept=check_accept)


          Implementation code taken from: https://github.com/django/channels/blob/master/channels/test/http.py#L92



          channels 2.x



          See https://channels.readthedocs.io/en/latest/topics/testing.html, as mentioned in the comment by Paul Whipp.






          share|improve this answer























          • Marking this down for now because the answers wrong in many ways. For eg. content='/new/' is not correct but path='/new/' is would be correct. I appreciate the effort, and If you can incorporate github.com/django/channels/issues/586 into your answer and remove mistakes I'll mark it right
            – cjds
            Jun 10 '17 at 0:05












          • Well, if you could read the text around the wrong call you would understand that the line you complain about, especially content='/new' is your line of code, and - of course - it is wrong because content has to be a dictionary as I have already stated in my answer above.
            – Risadinha
            Jun 12 '17 at 15:07










          • @cjds: You should reconsider whats written in the answer, this looks correct to me!
            – Amir Hadi
            Oct 2 '17 at 18:52










          • Thanks @AmirHadi I didn't see the edit. Marking correct
            – cjds
            Oct 2 '17 at 19:33










          • This question and answer apply to channels 1.x. For 2.x see channels.readthedocs.io/en/latest/topics/testing.html
            – Paul Whipp
            Nov 18 at 19:42















          up vote
          2
          down vote



          accepted










          channels 1.x



          You are calling send_and_consume with two positional arguments which results in effect in this call (which is exactly why there happens an error during execution in this line):



          # AGAIN this is wrong code this is what is written in the question
          # only difference is the naming of the (previously positional) arguments
          client.send_and_consume(channel='websocket.connect', content='/new/')


          and here is the explanation why there is an error:



          However, the implementation of send_and_consume expects content to be a dictionary:



          def send_and_consume(self, channel, content={}, text=None, path='/', fail_on_none=True, check_accept=True):
          """
          Reproduce full life cycle of the message
          """
          self.send(channel, content, text, path)
          return self.consume(channel, fail_on_none=fail_on_none, check_accept=check_accept)


          Implementation code taken from: https://github.com/django/channels/blob/master/channels/test/http.py#L92



          channels 2.x



          See https://channels.readthedocs.io/en/latest/topics/testing.html, as mentioned in the comment by Paul Whipp.






          share|improve this answer























          • Marking this down for now because the answers wrong in many ways. For eg. content='/new/' is not correct but path='/new/' is would be correct. I appreciate the effort, and If you can incorporate github.com/django/channels/issues/586 into your answer and remove mistakes I'll mark it right
            – cjds
            Jun 10 '17 at 0:05












          • Well, if you could read the text around the wrong call you would understand that the line you complain about, especially content='/new' is your line of code, and - of course - it is wrong because content has to be a dictionary as I have already stated in my answer above.
            – Risadinha
            Jun 12 '17 at 15:07










          • @cjds: You should reconsider whats written in the answer, this looks correct to me!
            – Amir Hadi
            Oct 2 '17 at 18:52










          • Thanks @AmirHadi I didn't see the edit. Marking correct
            – cjds
            Oct 2 '17 at 19:33










          • This question and answer apply to channels 1.x. For 2.x see channels.readthedocs.io/en/latest/topics/testing.html
            – Paul Whipp
            Nov 18 at 19:42













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          channels 1.x



          You are calling send_and_consume with two positional arguments which results in effect in this call (which is exactly why there happens an error during execution in this line):



          # AGAIN this is wrong code this is what is written in the question
          # only difference is the naming of the (previously positional) arguments
          client.send_and_consume(channel='websocket.connect', content='/new/')


          and here is the explanation why there is an error:



          However, the implementation of send_and_consume expects content to be a dictionary:



          def send_and_consume(self, channel, content={}, text=None, path='/', fail_on_none=True, check_accept=True):
          """
          Reproduce full life cycle of the message
          """
          self.send(channel, content, text, path)
          return self.consume(channel, fail_on_none=fail_on_none, check_accept=check_accept)


          Implementation code taken from: https://github.com/django/channels/blob/master/channels/test/http.py#L92



          channels 2.x



          See https://channels.readthedocs.io/en/latest/topics/testing.html, as mentioned in the comment by Paul Whipp.






          share|improve this answer














          channels 1.x



          You are calling send_and_consume with two positional arguments which results in effect in this call (which is exactly why there happens an error during execution in this line):



          # AGAIN this is wrong code this is what is written in the question
          # only difference is the naming of the (previously positional) arguments
          client.send_and_consume(channel='websocket.connect', content='/new/')


          and here is the explanation why there is an error:



          However, the implementation of send_and_consume expects content to be a dictionary:



          def send_and_consume(self, channel, content={}, text=None, path='/', fail_on_none=True, check_accept=True):
          """
          Reproduce full life cycle of the message
          """
          self.send(channel, content, text, path)
          return self.consume(channel, fail_on_none=fail_on_none, check_accept=check_accept)


          Implementation code taken from: https://github.com/django/channels/blob/master/channels/test/http.py#L92



          channels 2.x



          See https://channels.readthedocs.io/en/latest/topics/testing.html, as mentioned in the comment by Paul Whipp.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered Mar 31 '17 at 18:46









          Risadinha

          8,81115058




          8,81115058












          • Marking this down for now because the answers wrong in many ways. For eg. content='/new/' is not correct but path='/new/' is would be correct. I appreciate the effort, and If you can incorporate github.com/django/channels/issues/586 into your answer and remove mistakes I'll mark it right
            – cjds
            Jun 10 '17 at 0:05












          • Well, if you could read the text around the wrong call you would understand that the line you complain about, especially content='/new' is your line of code, and - of course - it is wrong because content has to be a dictionary as I have already stated in my answer above.
            – Risadinha
            Jun 12 '17 at 15:07










          • @cjds: You should reconsider whats written in the answer, this looks correct to me!
            – Amir Hadi
            Oct 2 '17 at 18:52










          • Thanks @AmirHadi I didn't see the edit. Marking correct
            – cjds
            Oct 2 '17 at 19:33










          • This question and answer apply to channels 1.x. For 2.x see channels.readthedocs.io/en/latest/topics/testing.html
            – Paul Whipp
            Nov 18 at 19:42


















          • Marking this down for now because the answers wrong in many ways. For eg. content='/new/' is not correct but path='/new/' is would be correct. I appreciate the effort, and If you can incorporate github.com/django/channels/issues/586 into your answer and remove mistakes I'll mark it right
            – cjds
            Jun 10 '17 at 0:05












          • Well, if you could read the text around the wrong call you would understand that the line you complain about, especially content='/new' is your line of code, and - of course - it is wrong because content has to be a dictionary as I have already stated in my answer above.
            – Risadinha
            Jun 12 '17 at 15:07










          • @cjds: You should reconsider whats written in the answer, this looks correct to me!
            – Amir Hadi
            Oct 2 '17 at 18:52










          • Thanks @AmirHadi I didn't see the edit. Marking correct
            – cjds
            Oct 2 '17 at 19:33










          • This question and answer apply to channels 1.x. For 2.x see channels.readthedocs.io/en/latest/topics/testing.html
            – Paul Whipp
            Nov 18 at 19:42
















          Marking this down for now because the answers wrong in many ways. For eg. content='/new/' is not correct but path='/new/' is would be correct. I appreciate the effort, and If you can incorporate github.com/django/channels/issues/586 into your answer and remove mistakes I'll mark it right
          – cjds
          Jun 10 '17 at 0:05






          Marking this down for now because the answers wrong in many ways. For eg. content='/new/' is not correct but path='/new/' is would be correct. I appreciate the effort, and If you can incorporate github.com/django/channels/issues/586 into your answer and remove mistakes I'll mark it right
          – cjds
          Jun 10 '17 at 0:05














          Well, if you could read the text around the wrong call you would understand that the line you complain about, especially content='/new' is your line of code, and - of course - it is wrong because content has to be a dictionary as I have already stated in my answer above.
          – Risadinha
          Jun 12 '17 at 15:07




          Well, if you could read the text around the wrong call you would understand that the line you complain about, especially content='/new' is your line of code, and - of course - it is wrong because content has to be a dictionary as I have already stated in my answer above.
          – Risadinha
          Jun 12 '17 at 15:07












          @cjds: You should reconsider whats written in the answer, this looks correct to me!
          – Amir Hadi
          Oct 2 '17 at 18:52




          @cjds: You should reconsider whats written in the answer, this looks correct to me!
          – Amir Hadi
          Oct 2 '17 at 18:52












          Thanks @AmirHadi I didn't see the edit. Marking correct
          – cjds
          Oct 2 '17 at 19:33




          Thanks @AmirHadi I didn't see the edit. Marking correct
          – cjds
          Oct 2 '17 at 19:33












          This question and answer apply to channels 1.x. For 2.x see channels.readthedocs.io/en/latest/topics/testing.html
          – Paul Whipp
          Nov 18 at 19:42




          This question and answer apply to channels 1.x. For 2.x see channels.readthedocs.io/en/latest/topics/testing.html
          – Paul Whipp
          Nov 18 at 19:42


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43147315%2fdjango-channels-doesnt-run-basic-test-case%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'