Show More
@@ -1,72 +1,101 b'' | |||
|
1 | 1 | from boards.models import KeyPair, Post, Tag |
|
2 | 2 | from boards.models.post.sync import SyncManager |
|
3 | 3 | from boards.tests.mocks import MockRequest |
|
4 | 4 | from boards.views.sync import response_get |
|
5 | 5 | |
|
6 | 6 | __author__ = 'neko259' |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | from django.test import TestCase |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | class SyncTest(TestCase): |
|
13 | 13 | def test_get(self): |
|
14 | 14 | """ |
|
15 | 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 | 19 | tag = Tag.objects.create(name='tag1') |
|
20 | 20 | post = Post.objects.create_post(title='test_title', text='test_text', |
|
21 | 21 | tags=[tag]) |
|
22 | 22 | |
|
23 | 23 | request = MockRequest() |
|
24 | 24 | request.body = ( |
|
25 | 25 | '<request type="get" version="1.0">' |
|
26 | 26 | '<model name="post" version="1.0">' |
|
27 | 27 | '<id key="%s" local-id="%d" type="%s" />' |
|
28 | 28 | '</model>' |
|
29 | 29 | '</request>' % (post.global_id.key, |
|
30 | 30 | post.id, |
|
31 | 31 | post.global_id.key_type) |
|
32 | 32 | ) |
|
33 | 33 | |
|
34 | 34 | response = response_get(request).content.decode() |
|
35 | 35 | self.assertTrue( |
|
36 | 36 | '<status>success</status>' |
|
37 | 37 | '<models>' |
|
38 | 38 | '<model name="post">' |
|
39 | 39 | '<content>' |
|
40 | 40 | '<id key="%s" local-id="%d" type="%s" />' |
|
41 | 41 | '<title>%s</title>' |
|
42 | 42 | '<text>%s</text>' |
|
43 | 43 | '<tags><tag>%s</tag></tags>' |
|
44 | 44 | '<pub-time>%s</pub-time>' |
|
45 | 45 | '</content>' % ( |
|
46 | 46 | post.global_id.key, |
|
47 | post.id, | |
|
47 | post.global_id.local_id, | |
|
48 | 48 | post.global_id.key_type, |
|
49 | 49 | post.title, |
|
50 | 50 | post.get_raw_text(), |
|
51 | 51 | post.get_thread().get_tags().first().name, |
|
52 | 52 | post.get_pub_time_str(), |
|
53 |
) in response |
|
|
53 | ) in response, | |
|
54 | 54 | 'Wrong response generated for the GET request.') |
|
55 | 55 | |
|
56 | 56 | post.delete() |
|
57 | key.delete() | |
|
58 | ||
|
59 | KeyPair.objects.generate_key(primary=True) | |
|
57 | 60 | |
|
58 | 61 | SyncManager.parse_response_get(response) |
|
59 | 62 | self.assertEqual(1, Post.objects.count(), |
|
60 | 63 | 'Post was not created from XML response.') |
|
61 | 64 | |
|
62 | 65 | parsed_post = Post.objects.first() |
|
63 | 66 | self.assertEqual('tag1', |
|
64 | 67 | parsed_post.get_thread().get_tags().first().name, |
|
65 | 68 | 'Invalid tag was parsed.') |
|
66 | 69 | |
|
67 | 70 | SyncManager.parse_response_get(response) |
|
68 | 71 | self.assertEqual(1, Post.objects.count(), |
|
69 | 72 | 'The same post was imported twice.') |
|
70 | 73 | |
|
71 | 74 | self.assertEqual(1, parsed_post.global_id.signature_set.count(), |
|
72 | 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