def setUp(self): """Setup the links test""" # Make a popular link and an unpopular link self.popular_link = ShortenedURL(url='http://something.com') self.popular_link.click_count = 10000 self.popular_link.save() self.unpopular_link = ShortenedURL.objects.create( url='http://somethingelse.com')
class GroupLinksTest(ConnectTestMixin, TestCase): """Test the links method""" def setUp(self): """Setup the links test""" super(GroupLinksTest, self).setUp() # Make a popular link and an unpopular link self.popular_link = ShortenedURL(url='http://something.com') self.popular_link.click_count = 10000 self.popular_link.save() self.unpopular_link = ShortenedURL.objects.create( url='http://somethingelse.com') def get_links_message(self, group, links=None): """Make a message that has the links in the specified group.""" # Create a message thread = mommy.make('connectmessages.Thread') message = mommy.make( 'connectmessages.Message', thread=thread, sender=self.create_superuser() ) # Default images if not links: links = [self.popular_link, self.unpopular_link] # Add images to message for link in links: message.links.add(link) # Add message to group message.thread.group = group message.thread.save() return message def test_link_posted_to_group_present(self): """An image posted to the group should be present.""" group = mommy.make('groups.Group') message = self.get_links_message(group) self.assertQuerysetEqual( group.links().all(), [repr(item) for item in message.links.all()], ordered=False ) def test_link_posted_to_another_group_not_present(self): """An image posted to another group should not be present.""" group = mommy.make('groups.Group') other_group = mommy.make('groups.Group') message = self.get_links_message(other_group) for link in message.links.all(): self.assertNotIn(link, group.links())
class GroupLinksTest(ConnectTestMixin, TestCase): """Test the links method""" def setUp(self): """Setup the links test""" super(GroupLinksTest, self).setUp() # Make a popular link and an unpopular link self.popular_link = ShortenedURL(url='http://something.com') self.popular_link.click_count = 10000 self.popular_link.save() self.unpopular_link = ShortenedURL.objects.create( url='http://somethingelse.com') def get_links_message(self, group, links=None): """Make a message that has the links in the specified group.""" # Create a message thread = mommy.make('connectmessages.Thread') message = mommy.make('connectmessages.Message', thread=thread, sender=self.create_superuser()) # Default images if not links: links = [self.popular_link, self.unpopular_link] # Add images to message for link in links: message.links.add(link) # Add message to group message.thread.group = group message.thread.save() return message def test_link_posted_to_group_present(self): """An image posted to the group should be present.""" group = mommy.make('groups.Group') message = self.get_links_message(group) self.assertQuerysetEqual(group.links().all(), [repr(item) for item in message.links.all()], ordered=False) def test_link_posted_to_another_group_not_present(self): """An image posted to another group should not be present.""" group = mommy.make('groups.Group') other_group = mommy.make('groups.Group') message = self.get_links_message(other_group) for link in message.links.all(): self.assertNotIn(link, group.links())
def setUp(self): """Setup the links test""" super(GroupLinksTest, self).setUp() # Make a popular link and an unpopular link self.popular_link = ShortenedURL(url='http://something.com') self.popular_link.click_count = 10000 self.popular_link.save() self.unpopular_link = ShortenedURL.objects.create( url='http://somethingelse.com')