2016-12-03 12:22:14 +00:00
|
|
|
from utils.api.tests import APITestCase
|
|
|
|
|
|
|
|
from .models import Announcement
|
2016-10-29 18:17:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AnnouncementAdminTest(APITestCase):
|
|
|
|
def setUp(self):
|
2016-11-19 05:47:59 +00:00
|
|
|
self.user = self.create_super_admin()
|
2016-11-19 04:32:23 +00:00
|
|
|
self.url = self.reverse("announcement_admin_api")
|
2016-10-29 18:17:35 +00:00
|
|
|
|
|
|
|
def test_announcement_list(self):
|
|
|
|
response = self.client.get(self.url)
|
|
|
|
self.assertSuccess(response)
|
|
|
|
|
|
|
|
def create_announcement(self):
|
|
|
|
return self.client.post(self.url, data={"title": "test", "content": "test"})
|
|
|
|
|
|
|
|
def test_create_announcement(self):
|
2016-11-19 05:47:59 +00:00
|
|
|
resp = self.create_announcement()
|
|
|
|
self.assertSuccess(resp)
|
2016-12-03 12:22:14 +00:00
|
|
|
return resp
|
2016-10-29 18:17:35 +00:00
|
|
|
|
|
|
|
def test_edit_announcement(self):
|
|
|
|
data = {"id": self.create_announcement().data["data"]["id"], "title": "ahaha", "content": "test content",
|
|
|
|
"visible": False}
|
2016-11-19 05:47:59 +00:00
|
|
|
resp = self.client.put(self.url, data=data)
|
|
|
|
self.assertSuccess(resp)
|
|
|
|
resp_data = resp.data["data"]
|
2016-10-29 18:17:35 +00:00
|
|
|
self.assertEqual(resp_data["title"], "ahaha")
|
|
|
|
self.assertEqual(resp_data["content"], "test content")
|
|
|
|
self.assertEqual(resp_data["visible"], False)
|
2016-12-03 12:22:14 +00:00
|
|
|
|
|
|
|
def test_delete_announcemen(self):
|
|
|
|
id = self.test_create_announcement().data["data"]["id"]
|
|
|
|
resp = self.client.delete(self.url, data={'id': id})
|
|
|
|
self.assertSuccess(resp)
|
|
|
|
self.assertFalse(Announcement.objects.filter(id=id).exists())
|