def test_get_my_group_topics(self): self.client.login(username=self.user.mobile, password='******') other_user = UserFactory() group1 = UserGroupFactory(create_user=other_user) group2 = UserGroupFactory(create_user=other_user) UserInGroup.objects.add_user(self.user, group1) my_topics = MessageFactory.create_batch(3, create_user=self.user, group=self.group, is_topic=True) my_group_topics = MessageFactory.create_batch(3, create_user=other_user, group=group1, is_topic=True) not_topics = MessageFactory.create_batch(4, create_user=self.user, group=self.group, is_topic=False) not_my_topics = MessageFactory.create_batch(5, create_user=other_user, group=group2, is_topic=True) url = self.url + '?filter=my_group' rsp = self.client.get(url) self.assertResponseRaiseCode(rsp, '0') self.assertEqual(rsp.data['result']['count'], 6)
def test_add_user_to_group(self): self.client.login(username=self.user.mobile, password='******') group = UserGroupFactory() url = self.url + str(group.id) + '/add-user/' rsp = self.client.post(url) self.assertResponseRaiseCode(rsp, '0') self.assertTrue(group in self.user.member_groups.all())
def test_update_group_success(self): self.client.login(username=self.user.mobile, password='******') group = UserGroupFactory(create_user=self.user) url = self.url + str(group.id) + '/' data = {'brief': 'wooo'} rsp = self.client.put(url, data=data, format='json') self.assertResponseRaiseCode(rsp, '0')
def test_get_group_users(self): user1 = UserFactory() user2 = UserFactory() user3 = UserFactory() group = UserGroupFactory(create_user=user1) UserInGroup.objects.add_user(user2, group) url = self.url + str(group.id) + '/group-users/' rsp = self.client.get(url) self.assertResponseRaiseCode(rsp, '0') self.assertEqual(rsp.data['result']['count'], 2)
def test_search_groups_with_q(self): groups1 = UserGroupFactory.create_batch(4, heat=1, tags=['小说', 'abc', '大家好']) groups2 = UserGroupFactory.create_batch(3, heat=2, tags=['哦哦', '气质']) groups3 = UserGroupFactory(heat=1, name='小说那么长') url = self.url + '?q=小说' rsp = self.client.get(url) self.assertResponseRaiseCode(rsp, '0') self.assertEqual(rsp.data['result']['count'], 5)
def test_add_topic_to_group_raise_1010_when_not_group_member(self): self.client.login(username=self.user.mobile, password='******') group = UserGroupFactory() url = self.url + str(group.id) + '/add-topic/' content = '哟哟呀我黑' data = { 'title': 'lala拉', 'content': content, 'index_pic': 'https://wulala.com' } rsp = self.client.post(url, data=data, format='json') self.assertResponseRaiseCode(rsp, '1010')
def test_add_topic_to_group_success(self): self.client.login(username=self.user.mobile, password='******') group = UserGroupFactory(create_user=self.user) url = self.url + str(group.id) + '/add-topic/' content = '哟哟呀我黑' data = { 'title': 'lala拉', 'brief': '哦哦', 'content': content, 'index_pic': 'https://wulala.com' } rsp = self.client.post(url, data=data, format='json') self.assertResponseRaiseCode(rsp, '0') self.assertEqual(rsp.data['result']['content'], content)
def setUp(self): super().setUp() self.url = '/api/forum/topics/my/' self.user = UserFactory(password='******') self.group = UserGroupFactory(create_user=self.user)
def test_retrieve_group(self): group = UserGroupFactory() url = self.url + str(group.id) + '/' rsp = self.client.get(url) self.assertResponseRaiseCode(rsp, '0') self.assertEqual(rsp.data['result']['id'], group.id)