-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_models.py
More file actions
56 lines (40 loc) · 2.33 KB
/
Copy pathtest_models.py
File metadata and controls
56 lines (40 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from unittest.mock import patch
from django.test import TestCase
from webmention.models import WebMentionResponse
class WebMentionResponseTestCase(TestCase):
def setUp(self):
self.source = 'http://example.com'
self.target = 'http://mysite.com'
self.response_body = 'foo'
def test_str(self):
webmention = WebMentionResponse.objects.create(source=self.source, response_to=self.target, response_body=self.response_body)
webmention.save()
self.assertEqual(webmention.source, str(webmention))
def test_source_for_admin(self):
webmention = WebMentionResponse.objects.create(source=self.source, response_to=self.target, response_body=self.response_body)
webmention.save()
self.assertEqual('<a href="{href}">{href}</a>'.format(href=webmention.source), webmention.source_for_admin())
def test_response_to_for_admin(self):
webmention = WebMentionResponse.objects.create(source=self.source, response_to=self.target, response_body=self.response_body)
webmention.save()
self.assertEqual('<a href="{href}">{href}</a>'.format(href=webmention.response_to), webmention.response_to_for_admin())
@patch('webmention.models.WebMentionResponse.save')
def test_invalidate_when_not_previously_saved(self, mock_save):
webmention = WebMentionResponse()
webmention.invalidate()
self.assertFalse(mock_save.called)
def test_invalidate_when_previously_saved(self):
webmention = WebMentionResponse.objects.create(source=self.source, response_to=self.target, response_body=self.response_body)
webmention.save()
webmention.invalidate()
self.assertFalse(webmention.current)
@patch('webmention.models.WebMentionResponse.save')
def test_update_when_previously_invalid(self, mock_save):
webmention = WebMentionResponse.objects.create(source='foo', response_to='bar', response_body='baz', current=False)
self.assertEqual(1, mock_save.call_count)
webmention.update(self.source, self.target, self.response_body)
self.assertTrue(webmention.current)
self.assertEqual(self.source, webmention.source)
self.assertEqual(self.target, webmention.response_to)
self.assertEqual(self.response_body, webmention.response_body)
self.assertEqual(2, mock_save.call_count)