##// END OF EJS Templates
Added a generator for the 'get' request for sync
neko259 -
r810:6bdf5d6a decentral
parent child Browse files
Show More
@@ -0,0 +1,56 b''
1 import xml.etree.ElementTree as et
2
3 TAG_MODEL = 'model'
4 TAG_REQUEST = 'request'
5 TAG_ID = 'id'
6
7 TYPE_GET = 'get'
8
9 ATTR_VERSION = 'version'
10 ATTR_TYPE = 'type'
11 ATTR_NAME = 'name'
12 ATTR_KEY = 'key'
13 ATTR_KEY_TYPE = 'type'
14 ATTR_LOCAL_ID = 'local-id'
15
16
17 class ModelId:
18 """
19 Model ID describes a global ID that consists of sender's key (with the key
20 type) and local ID on the sender node.
21 """
22
23 def __init__(self, key, key_type, local_id):
24 self.key = key
25 self.key_type = key_type
26 self.local_id = local_id
27
28
29 def respond_pull(request):
30 pass
31
32
33 def respond_get(request):
34 pass
35
36
37 def generate_request_get(id_list: list):
38 """
39 Form a get request from a list of ModelId objects.
40 """
41
42 request = et.Element(TAG_REQUEST)
43 request.set(ATTR_TYPE, TYPE_GET)
44 request.set(ATTR_VERSION, '1.0')
45
46 model = et.SubElement(request, TAG_MODEL)
47 model.set(ATTR_VERSION, '1.0')
48 model.set(ATTR_NAME, 'post')
49
50 for model_id in id_list:
51 tag_id = et.SubElement(model, TAG_ID)
52 tag_id.set(ATTR_KEY, model_id.key)
53 tag_id.set(ATTR_KEY_TYPE, model_id.key_type)
54 tag_id.set(ATTR_LOCAL_ID, model_id.local_id)
55
56 return et.tostring(request, 'unicode') No newline at end of file
@@ -14,6 +14,7 b' from boards import urls'
14 from boards import settings
14 from boards import settings
15 from boards.views.api import api_get_threaddiff
15 from boards.views.api import api_get_threaddiff
16 from boards.utils import datetime_to_epoch
16 from boards.utils import datetime_to_epoch
17 from boards.views.sync import ModelId, generate_request_get
17 import neboard
18 import neboard
18
19
19 TEST_TAG = 'test_tag'
20 TEST_TAG = 'test_tag'
@@ -146,7 +147,7 b' class PagesTest(TestCase):'
146 def test_404(self):
147 def test_404(self):
147 """Test receiving error 404 when opening a non-existent page"""
148 """Test receiving error 404 when opening a non-existent page"""
148
149
149 tag_name = u'test_tag'
150 tag_name = 'test_tag'
150 tag = Tag.objects.create(name=tag_name)
151 tag = Tag.objects.create(name=tag_name)
151 client = Client()
152 client = Client()
152
153
@@ -156,22 +157,22 b' class PagesTest(TestCase):'
156 response_existing = client.get(THREAD_PAGE + str(existing_post_id) +
157 response_existing = client.get(THREAD_PAGE + str(existing_post_id) +
157 '/')
158 '/')
158 self.assertEqual(HTTP_CODE_OK, response_existing.status_code,
159 self.assertEqual(HTTP_CODE_OK, response_existing.status_code,
159 u'Cannot open existing thread')
160 'Cannot open existing thread')
160
161
161 response_not_existing = client.get(THREAD_PAGE + str(
162 response_not_existing = client.get(THREAD_PAGE + str(
162 existing_post_id + 1) + '/')
163 existing_post_id + 1) + '/')
163 self.assertEqual(PAGE_404, response_not_existing.templates[0].name,
164 self.assertEqual(PAGE_404, response_not_existing.templates[0].name,
164 u'Not existing thread is opened')
165 'Not existing thread is opened')
165
166
166 response_existing = client.get(TAG_PAGE + tag_name + '/')
167 response_existing = client.get(TAG_PAGE + tag_name + '/')
167 self.assertEqual(HTTP_CODE_OK,
168 self.assertEqual(HTTP_CODE_OK,
168 response_existing.status_code,
169 response_existing.status_code,
169 u'Cannot open existing tag')
170 'Cannot open existing tag')
170
171
171 response_not_existing = client.get(TAG_PAGE + u'not_tag' + '/')
172 response_not_existing = client.get(TAG_PAGE + 'not_tag' + '/')
172 self.assertEqual(PAGE_404,
173 self.assertEqual(PAGE_404,
173 response_not_existing.templates[0].name,
174 response_not_existing.templates[0].name,
174 u'Not existing tag is opened')
175 'Not existing tag is opened')
175
176
176 reply_id = Post.objects.create_post('', TEST_TEXT,
177 reply_id = Post.objects.create_post('', TEST_TEXT,
177 thread=Post.objects.all()[0]
178 thread=Post.objects.all()[0]
@@ -180,15 +181,15 b' class PagesTest(TestCase):'
180 reply_id) + '/')
181 reply_id) + '/')
181 self.assertEqual(PAGE_404,
182 self.assertEqual(PAGE_404,
182 response_not_existing.templates[0].name,
183 response_not_existing.templates[0].name,
183 u'Reply is opened as a thread')
184 'Reply is opened as a thread')
184
185
185
186
186 class FormTest(TestCase):
187 class FormTest(TestCase):
187 def test_post_validation(self):
188 def test_post_validation(self):
188 client = Client()
189 client = Client()
189
190
190 valid_tags = u'tag1 tag_2 тег_3'
191 valid_tags = 'tag1 tag_2 тег_3'
191 invalid_tags = u'$%_356 ---'
192 invalid_tags = '$%_356 ---'
192
193
193 response = client.post(NEW_THREAD_PAGE, {'title': 'test title',
194 response = client.post(NEW_THREAD_PAGE, {'title': 'test title',
194 'text': TEST_TEXT,
195 'text': TEST_TEXT,
@@ -213,13 +214,13 b' class FormTest(TestCase):'
213 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
214 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
214 'tags': valid_tags})
215 'tags': valid_tags})
215 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
216 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
216 msg=u'Posting new message failed: got code ' +
217 msg='Posting new message failed: got code ' +
217 str(response.status_code))
218 str(response.status_code))
218 # Restore posting delay
219 # Restore posting delay
219 neboard.settings.POSTING_DELAY = old_posting_delay
220 neboard.settings.POSTING_DELAY = old_posting_delay
220
221
221 self.assertEqual(2, Post.objects.count(),
222 self.assertEqual(2, Post.objects.count(),
222 msg=u'No posts were created')
223 msg='No posts were created')
223
224
224
225
225 class ViewTest(TestCase):
226 class ViewTest(TestCase):
@@ -258,7 +259,7 b' class AbstractTest(TestCase):'
258
259
259 settings_manager.set_setting('test_setting', 'test_value')
260 settings_manager.set_setting('test_setting', 'test_value')
260 self.assertEqual('test_value', settings_manager.get_setting(
261 self.assertEqual('test_value', settings_manager.get_setting(
261 'test_setting'), u'Setting update failed.')
262 'test_setting'), 'Setting update failed.')
262
263
263
264
264 class MockRequest:
265 class MockRequest:
@@ -292,7 +293,15 b' class KeyTest(TestCase):'
292 ' one primary key.')
293 ' one primary key.')
293 except Exception:
294 except Exception:
294 pass
295 pass
295
296
297 def test_request_get(self):
298 model_id = ModelId('111', '222', '333')
299 self.assertTrue('<request type="get" version="1.0"><model '
300 'name="post" version="1.0"><id key="111" '
301 'local-id="333" type="222" /></model></request>' in
302 generate_request_get([model_id]),
303 'Wrong XML generated for the GET request.')
304
296
305
297 class ApiTest(TestCase):
306 class ApiTest(TestCase):
298 def test_thread_diff(self):
307 def test_thread_diff(self):
@@ -1,7 +1,7 b''
1 <?xml version="1.1" encoding="UTF-8" ?>
1 <?xml version="1.1" encoding="UTF-8" ?>
2 <request version="1.0" type="get">
2 <request version="1.0" type="get">
3 <model version="1.0" name="post">
3 <model version="1.0" name="post">
4 <id key="id1" local-id="1" />
4 <id key="id1" type="ecdsa" local-id="1" />
5 <id key="id1" local-id="2" />
5 <id key="id1" type="ecdsa" local-id="2" />
6 </model>
6 </model>
7 </request>
7 </request>
@@ -2,9 +2,9 b''
2 <response>
2 <response>
3 <status>success</status>
3 <status>success</status>
4 <models>
4 <models>
5 <id key="id1" local-id="1" />
5 <id key="id1" type="ecdsa" local-id="1" />
6 <id key="id1" local-id="2" />
6 <id key="id1" type="ecdsa" local-id="2" />
7 <id key="id2" local-id="1" />
7 <id key="id2" type="ecdsa" local-id="1" />
8 <id key="id2" local-id="5" />
8 <id key="id2" type="ecdsa" local-id="5" />
9 </models>
9 </models>
10 </response>
10 </response>
@@ -1,3 +1,4 b''
1 simplejson
1 south>=0.8.4
2 south>=0.8.4
2 haystack
3 haystack
3 pillow
4 pillow
General Comments 0
You need to be logged in to leave comments. Login now