-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·30 lines (26 loc) · 1.13 KB
/
Copy pathtest.py
File metadata and controls
executable file
·30 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django.test import TestCase, RequestFactory
from django.contrib.auth.models import User
from django.test.client import Client
# import json
from mock.views import mock_main
# from django.contrib.auth.models import User
# from django.contrib.auth import authenticate, login, logout
# from .models import AlertSetting
class TestAlertView(TestCase):
# call before test
def setUp(self):
# auto deleted after test
self.user = User.objects.create_user(username='django_test', password='testuser')
self.factory = RequestFactory()
self.client = Client()
def test_alert_setting(self):
self.client.login(username='django_test', password='testuser')
response = self.client.get("/accounts/alert_settings/")
print(response.json())
self.assertEqual(response.status_code, 200)
def test_template(self):
request = self.factory.get("/mock_main/")
# request.user = self.user # https://docs.djangoproject.com/en/1.9/topics/testing/advanced/#example
response = mock_main(request)
print(response.content)
self.assertEqual(response.status_code, 200)