def test_channel_url_constraint(self): c = create_channel() e1 = create_entry(channel=c, url='http://host.com/1') e2 = Entry(channel=c, **ENTRY_DEFAULTS) e2.url = 'http://host.com/1' with self.assertRaises(Exception): e2.save()
def test_batch_insert(self): old_num_queries = len(connection.queries) with self.buf as buffer: for i in range(5): entry = Entry(channel=self.channel, **ENTRY_DEFAULTS) entry.url = 'http://ho.st/%d' % i buffer.add(entry) num_queries = len(connection.queries) - old_num_queries self.assertEqual(len(self.channel.entry_set.all()), 5) self.assertEqual(num_queries, 2) self.assertEqual(len(self.buf), 0)
def test_returns_only_new_entries(self): self.channel.save() entry_fields = ENTRY_DEFAULTS.copy() entry_fields['url'] = 'http://old_url.com' e = Entry(channel=self.channel, **entry_fields).save() self.future.set_result((FakeResponse(), self.GOOD_HTML)) rv = process_channel(self.channel, self.future) self.assertEqual(len(rv), 1)
def test_track_returns_only_new_entries(self): new_entry = Entry(channel=self.channel, **ENTRY_DEFAULTS) new_entry.url = 'http://new.host.com/' rv = Entry.objects.track_entries(self.channel, [new_entry, self.old_entry]) self.assertEqual(rv, [new_entry])
def setUp(self): self.entry = Entry(**ENTRY_DEFAULTS) self.future = FutureLite()
def test_entry_site(self): e = Entry(url='http://somehost.com/doc.html') rv = entry_site(e) self.assertIn('somehost.com', rv)
def test_entry_title_with_link(self): e = Entry(title='blah', url='http://host.com') rv = entry_title_with_link(e) self.assertIn(e.title, rv) self.assertIn(e.url, rv)
def test_len(self): for _ in range(2): self.buf.add(Entry(channel=self.channel, **ENTRY_DEFAULTS)) self.assertEquals(len(self.buf), 2)