def test_follow_unfollow_or_unfollow(self): """Make sure posts are only added to the stream while we're following someone.""" self.create_posts() self.login('john.example.com', user_id='1') response = self.client.get(reverse('dash')) self.assertEqual(['t3', 't1'], [p.text for p in response.context['posts']]) self.client.post(reverse('follow', args=('bob',))) Post.create(author=self.b2, text="b2", friends=self.b2.friends()) response = self.client.get(reverse('dash')) self.assertEqual(['b2', 't3', 't1'], [p.text for p in response.context['posts']]) # a second post to the follow view unfollows self.client.post(reverse('follow', args=('bob',))) Post.create(author=self.b2, text="b3", friends=self.b2.friends()) response = self.client.get(reverse('dash')) self.assertEqual(['b2', 't3', 't1'], [p.text for p in response.context['posts']])
def create_posts(self): self.p1 = Post.create(author=self.b1, text="t1", friends=self.b1.friends()) self.p2 = Post.create(author=self.b2, text="t2", friends=self.b2.friends()) self.p3 = Post.create(author=self.b1, text="t3", friends=self.b1.friends())
def save(self): Post.create(author=self.blog, text=self.cleaned_data['text'], friends=self.blog.friends() )