##// END OF EJS Templates
Fixed issues in sync test
neko259 -
r1503:135b5a86 decentral
parent child Browse files
Show More
@@ -1,72 +1,101 b''
1 from boards.models import KeyPair, Post, Tag
1 from boards.models import KeyPair, Post, Tag
2 from boards.models.post.sync import SyncManager
2 from boards.models.post.sync import SyncManager
3 from boards.tests.mocks import MockRequest
3 from boards.tests.mocks import MockRequest
4 from boards.views.sync import response_get
4 from boards.views.sync import response_get
5
5
6 __author__ = 'neko259'
6 __author__ = 'neko259'
7
7
8
8
9 from django.test import TestCase
9 from django.test import TestCase
10
10
11
11
12 class SyncTest(TestCase):
12 class SyncTest(TestCase):
13 def test_get(self):
13 def test_get(self):
14 """
14 """
15 Forms a GET request of a post and checks the response.
15 Forms a GET request of a post and checks the response.
16 """
16 """
17
17
18 KeyPair.objects.generate_key(primary=True)
18 key = KeyPair.objects.generate_key(primary=True)
19 tag = Tag.objects.create(name='tag1')
19 tag = Tag.objects.create(name='tag1')
20 post = Post.objects.create_post(title='test_title', text='test_text',
20 post = Post.objects.create_post(title='test_title', text='test_text',
21 tags=[tag])
21 tags=[tag])
22
22
23 request = MockRequest()
23 request = MockRequest()
24 request.body = (
24 request.body = (
25 '<request type="get" version="1.0">'
25 '<request type="get" version="1.0">'
26 '<model name="post" version="1.0">'
26 '<model name="post" version="1.0">'
27 '<id key="%s" local-id="%d" type="%s" />'
27 '<id key="%s" local-id="%d" type="%s" />'
28 '</model>'
28 '</model>'
29 '</request>' % (post.global_id.key,
29 '</request>' % (post.global_id.key,
30 post.id,
30 post.id,
31 post.global_id.key_type)
31 post.global_id.key_type)
32 )
32 )
33
33
34 response = response_get(request).content.decode()
34 response = response_get(request).content.decode()
35 self.assertTrue(
35 self.assertTrue(
36 '<status>success</status>'
36 '<status>success</status>'
37 '<models>'
37 '<models>'
38 '<model name="post">'
38 '<model name="post">'
39 '<content>'
39 '<content>'
40 '<id key="%s" local-id="%d" type="%s" />'
40 '<id key="%s" local-id="%d" type="%s" />'
41 '<title>%s</title>'
41 '<title>%s</title>'
42 '<text>%s</text>'
42 '<text>%s</text>'
43 '<tags><tag>%s</tag></tags>'
43 '<tags><tag>%s</tag></tags>'
44 '<pub-time>%s</pub-time>'
44 '<pub-time>%s</pub-time>'
45 '</content>' % (
45 '</content>' % (
46 post.global_id.key,
46 post.global_id.key,
47 post.id,
47 post.global_id.local_id,
48 post.global_id.key_type,
48 post.global_id.key_type,
49 post.title,
49 post.title,
50 post.get_raw_text(),
50 post.get_raw_text(),
51 post.get_thread().get_tags().first().name,
51 post.get_thread().get_tags().first().name,
52 post.get_pub_time_str(),
52 post.get_pub_time_str(),
53 ) in response_get(request).content.decode(),
53 ) in response,
54 'Wrong response generated for the GET request.')
54 'Wrong response generated for the GET request.')
55
55
56 post.delete()
56 post.delete()
57 key.delete()
58
59 KeyPair.objects.generate_key(primary=True)
57
60
58 SyncManager.parse_response_get(response)
61 SyncManager.parse_response_get(response)
59 self.assertEqual(1, Post.objects.count(),
62 self.assertEqual(1, Post.objects.count(),
60 'Post was not created from XML response.')
63 'Post was not created from XML response.')
61
64
62 parsed_post = Post.objects.first()
65 parsed_post = Post.objects.first()
63 self.assertEqual('tag1',
66 self.assertEqual('tag1',
64 parsed_post.get_thread().get_tags().first().name,
67 parsed_post.get_thread().get_tags().first().name,
65 'Invalid tag was parsed.')
68 'Invalid tag was parsed.')
66
69
67 SyncManager.parse_response_get(response)
70 SyncManager.parse_response_get(response)
68 self.assertEqual(1, Post.objects.count(),
71 self.assertEqual(1, Post.objects.count(),
69 'The same post was imported twice.')
72 'The same post was imported twice.')
70
73
71 self.assertEqual(1, parsed_post.global_id.signature_set.count(),
74 self.assertEqual(1, parsed_post.global_id.signature_set.count(),
72 'Signature was not saved.')
75 'Signature was not saved.')
76
77 post = parsed_post
78
79 # Trying to sync the same once more
80 response = response_get(request).content.decode()
81
82 self.assertTrue(
83 '<status>success</status>'
84 '<models>'
85 '<model name="post">'
86 '<content>'
87 '<id key="%s" local-id="%d" type="%s" />'
88 '<title>%s</title>'
89 '<text>%s</text>'
90 '<tags><tag>%s</tag></tags>'
91 '<pub-time>%s</pub-time>'
92 '</content>' % (
93 post.global_id.key,
94 post.global_id.local_id,
95 post.global_id.key_type,
96 post.title,
97 post.get_raw_text(),
98 post.get_thread().get_tags().first().name,
99 post.get_pub_time_str(),
100 ) in response,
101 'Wrong response generated for the GET request.')
General Comments 0
You need to be logged in to leave comments. Login now