def test_unsubscribe(self): request = self.factory.post( self.path, { 'action': 'Unsubscribe', }, kwargs={'username': self.admin.username}, ) request.user = self.user response = UserView().post(request=request, username=self.admin.username) assert response.status_code == 302 assert response.url == reverse( 'blog:user_view', kwargs={'username': self.admin.username}) mixer.blend(Subscription, author=self.admin, subscriber=self.user) post = mixer.blend(Post, author=self.admin) post.read_by.add(self.user) response = UserView().post(request=request, username=self.admin.username) assert response.status_code == 302 assert response.url == reverse( 'blog:user_view', kwargs={'username': self.admin.username}) assert Subscription.objects.filter(author=self.admin, subscriber=self.user).count() == 0 assert not self.user.user_read.filter(author=self.admin).exists() assert not (Subscription.objects.filter(author=self.admin, subscriber=self.user).exists())
def test_subscribe(self): request = self.factory.post( self.path, { 'action': 'Subscribe', 'author': self.admin.username, 'subscriber': self.user.username, }, kwargs={'username': self.admin.username}, ) request.user = self.user response = UserView().post(request=request, username=self.admin.username) assert response.status_code == 302 assert response.url == reverse( 'blog:user_view', kwargs={'username': self.admin.username}) assert Subscription.objects.filter(author=self.admin).count() == 1 assert (Subscription.objects.filter(author=self.admin, subscriber=self.user).exists()) # if sub already exists response = UserView().post(request=request, username=self.admin.username) assert response.status_code == 302 assert response.url == reverse( 'blog:user_view', kwargs={'username': self.admin.username}) assert Subscription.objects.filter(author=self.admin).count() == 1 assert (Subscription.objects.filter(author=self.admin, subscriber=self.user).exists())
def test_create_post(self): request = self.factory.post( self.path, { 'title': 'title1', 'content': 'content1', }, kwargs={'username': self.admin.username}, ) request.user = self.user response = UserView().post(request=request, username=self.admin.username) assert response.status_code == 302 assert response.url == reverse( 'blog:user_view', kwargs={'username': self.admin.username}) # TODO: google tasks delayed check """
def test_get_user_view_another_authenticated(self): request = self.factory.get(self.path) request.user = self.user response = UserView().get(request=request, username='******') assert response.status_code == 200