def test_post_return_invalid_channel(self):
     data = {"user_id": "UB9AVTDT3", "text": "abc,test"}
     request = self.factory.post('/', data)
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'), 'text/plain')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'invalid channel')
Beispiel #2
0
 def test_home_page(self):
     request = self.factory.get('/')
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'),
                      'text/html; charset=utf-8')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'Congratulations')
 def test_post_return_no_message(self):
     data = {"user_id": "UB9AVTDT3", "text": "prj-slackapp-test,"}
     request = self.factory.post('/', data)
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'), 'text/plain')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'no message')
 def test_post_return_no_parameter(self):
     data = {"user_id": "UB9AVTDT3"}
     request = self.factory.post('/', data)
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'), 'text/plain')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'no parameter')
 def test_post_return_unauthorized_user(self):
     data = {"user_id": "123"}
     request = self.factory.post('/', data)
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'), 'text/plain')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'unauthorized user')
Beispiel #6
0
 def test_post_return_invalid_parameter(self):
     data = {
         "user_id": "UB9AVTDT3",
         "channel_name": "prj-slackapp",
         "text": "#prj-slackapp-test"
     }
     request = self.factory.post('/', data)
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'), 'text/plain')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'invalid parameter')
    def test_post_call_chat_postMessage(self):
        client = slack.WebClient(token=slackbot_settings.API_TOKEN)
        slack.WebClient = mock.MagicMock(return_value=client)
        client.chat_postMessage = mock.MagicMock()

        data = {"user_id": "UB9AVTDT3", "text": "prj-slackapp-test,test"}
        request = self.factory.post('/', data)
        response = HomePageView.as_view()(request)
        self.assertEqual(response.get('content-type'), 'text/plain')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'test')
        client.chat_postMessage.assert_called_with(channel="CHXS0FH5M",text="test",as_user=True)
Beispiel #8
0
from django.urls import path
from helloworld.views import HomePageView

urlpatterns = [
    path('', HomePageView.as_view(), name='index'),
]
Beispiel #9
0
"""mywebapp URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.urls import re_path
from helloworld.views import HomePageView

urlpatterns = [
    re_path(r'^$', HomePageView.as_view(), name='home'),
]
Beispiel #10
0
 def test_home_page(self):
     request = self.factory.get('/')
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'), 'text/html; charset=utf-8')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'Congratulations')
Beispiel #11
0
 def test_home_page(self):
     request = self.factory.get('/')
     response = HomePageView.as_view()(request)
     self.assertEqual(response.get('content-type'), 'application/json')
     self.assertEqual(response.status_code, 200)