def test_create_or_update(self): url = 'foo' Post.create_or_update(url) self.assertEqual(1, Post.objects.count()) Post.create_or_update(url) self.assertEqual(1, Post.objects.count())
def run(cls, city): response = urlopen(urljoin(city.url, cls.path, allow_fragments=True)) html = response.read() posts = CityParser().run(city, html) for post_data in posts: post = Post.create_or_update(urljoin(city.url, post_data)) django_rq.enqueue(PostImporter.run, post)
def test_posted_at_str(self): post = Post.create_or_update('foo') post.posted_at = datetime(2015, 1, 1, 0, 1).replace(tzinfo=utc) post.save() self.assertEqual('2015-01-01 00:01', post.posted_at_str)