def test_existing_embed_doesnt_create_response_on_save(self): e = Embed(url=self.url) e.save() del e.response e.save() self.expect_empty_response_data(e)
def test_new_embed_doesnt_have_to_create_response_on_save(self): def raise_exec(obj): raise InvalidResponseError e = Embed(url=self.url) self.assertIsNone(e.response) with fudge.patched_context(Embed, 'update_response', raise_exec): e.save() self.assertIsNone(e.response)
def test_last_updated_field_doesnt_update_without_new_response(self): e = Embed(url=self.url) e.save() # force an obviously different time e.response_last_updated = e.response_last_updated - timedelta(days=1) dt = e.response_last_updated e.update_response() e.save() self.assertEqual(e.response_last_updated, dt)
def test_last_updated_field_updates_with_new_response(self): e = Embed(url=self.url) e.save() # force an obviously different time e.response_last_updated = e.response_last_updated - timedelta(days=1) dt = e.response_last_updated e.url = self.new_url e.update_response() e.save() self.assertGreater(e.response_last_updated, dt)
def test_last_updated_field_updates_on_save(self): e = Embed(url=self.url) self.assertIsNone(e.response_last_updated) e.save() self.assertIsNotNone(e.response_last_updated) self.assertTrue(isinstance(e.response_last_updated, datetime))
def test_new_embed_creates_response_on_save(self): e = Embed(url=self.url) self.assertIsNone(e.response) e.save() self.assertIsNotNone(e.response) self.assertTrue(isinstance(e.response, self.response_cls))
def test_backend_cant_auto_assign_when_there_are_no_backends(self): Backend.objects.all().delete() e = Embed(url=self.url) with self.assertRaises(ValueError): e.save()
def test_backend_autoassigns_on_save(self): e = Embed(url=self.url) e.save() self.assertTrue(hasattr(e, "backend")) self.assertTrue(isinstance(e.backend, Backend)) self.assertTrue(isinstance(e.backend._backend, self.backend_cls))
def test_embed_requires_backend(self): e = Embed() with self.assertRaises(ValueError): e.save()