Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
class EmbedModelLayoutTestCase(TemplateCompareTestMixin, TestCase):
    fixtures = ['embed_backends']

    def setUp(self):
        # Remove everything but the default Backend
        Backend.objects.exclude(name="default").delete()

        self.embed = Embed(
            url="http://www.testme.com",
            backend=Backend.objects.get(name='default'))
        self.tpl_name = "tpl"
        self.type_name = EmbedType()._meta.object_name.lower()
        self.type_slug = "photo"

    def test_no_backend_uses_fallback_template(self):
        e = Embed(url="http://www.testme.com")
        self.assertFalse(hasattr(e, 'backend'))

        expected = ['%(base)s/%(app)s/%(model)s/%(tpl)s.html']
        self.compare_templates(e, expected, use_fallback=True)

    def test_valid_response_without_a_type(self):
        self.embed.update_response()

        self.assertTrue(self.embed.response.is_valid())
        self.assertIsNone(self.embed.type)

        expected = ['%(base)s/%(app)s/%(model)s/%(tpl)s.html']
        self.compare_templates(self.embed, expected)

    def test_invalid_response_without_a_type_uses_fallback(self):
        response = self.embed.get_response()
        response.is_valid = lambda: False
        self.embed.response = response

        self.assertFalse(self.embed.response.is_valid())
        self.assertIsNone(self.embed.type)

        expected = ['%(base)s/%(app)s/%(model)s/%(tpl)s.html']
        self.compare_templates(self.embed, expected, use_fallback=True)

    def test_invalid_response_with_a_type_uses_fallback(self):
        response = self.embed.get_response()
        response.is_valid = lambda: False
        self.embed.response = response
        self.embed.type = EmbedType(slug=self.type_slug)

        self.assertFalse(self.embed.response.is_valid())

        expected = ['%(base)s/%(app)s/%(model)s/%(tpl)s.html']
        self.compare_templates(self.embed, expected, use_fallback=True, use_type=True)

    def test_valid_response_with_a_type(self):
        self.embed.update_response()
        self.embed.type = EmbedType(slug=self.type_slug)

        self.assertTrue(self.embed.response.is_valid())

        expected = [
            '%(base)s/%(app)s/%(typemodel)s/%(type)s/%(tpl)s.html',
            '%(base)s/%(app)s/%(model)s/%(tpl)s.html']
        self.compare_templates(self.embed, expected, use_type=True)
Exemplo n.º 4
0
 def test_different_response_updates(self):
     data = dict(other='stuff')
     backend = self.backend
     e = Embed(url=self.url, response_cache=data, backend=backend)
     self.assertTrue(e.update_response())
Exemplo n.º 5
0
 def test_duplicate_update_doesnt_update(self):
     e = Embed(url=self.url, backend=self.backend)
     e.update_response()
     self.assertFalse(e.update_response())
Exemplo n.º 6
0
 def test_same_response_doesnt_update(self):
     e = Embed(url=self.url, backend=self.backend)
     e.response = self.response_cls(dict(url=self.url))
     self.assertFalse(e.update_response())
Exemplo n.º 7
0
 def test_new_response_updates(self):
     e = Embed(url=self.url, backend=self.backend)
     self.assertTrue(e.update_response())
Exemplo n.º 8
0
 def test_update_is_false_without_url(self):
     e = Embed(backend=self.backend)
     self.assertFalse(e.update_response())
Exemplo n.º 9
0
 def test_wrapped_response_doesnt_update(self):
     data = dict(url=self.url)
     e = Embed(url=self.url, response_cache=data, backend=self.backend)
     self.assertFalse(e.update_response())