##// END OF EJS Templates
Made SyncManager's methods static
neko259 -
r1236:124750d7 decentral
parent child Browse files
Show More
@@ -39,7 +39,7 b' class Command(BaseCommand):'
39 h = httplib2.Http()
39 h = httplib2.Http()
40 response, content = h.request(url, method="POST", body=xml)
40 response, content = h.request(url, method="POST", body=xml)
41
41
42 SyncManager().parse_response_get(content)
42 SyncManager.parse_response_get(content)
43 else:
43 else:
44 raise Exception('Invalid global ID')
44 raise Exception('Invalid global ID')
45 else:
45 else:
@@ -31,9 +31,9 b" ATTR_MIMETYPE = 'mimetype'"
31 STATUS_SUCCESS = 'success'
31 STATUS_SUCCESS = 'success'
32
32
33
33
34 # TODO Make this fully static
35 class SyncManager:
34 class SyncManager:
36 def generate_response_get(self, model_list: list):
35 @staticmethod
36 def generate_response_get(model_list: list):
37 response = et.Element(TAG_RESPONSE)
37 response = et.Element(TAG_RESPONSE)
38
38
39 status = et.SubElement(response, TAG_STATUS)
39 status = et.SubElement(response, TAG_STATUS)
@@ -88,8 +88,9 b' class SyncManager:'
88
88
89 return et.tostring(response, ENCODING_UNICODE)
89 return et.tostring(response, ENCODING_UNICODE)
90
90
91 @staticmethod
91 @transaction.atomic
92 @transaction.atomic
92 def parse_response_get(self, response_xml):
93 def parse_response_get(response_xml):
93 tag_root = et.fromstring(response_xml)
94 tag_root = et.fromstring(response_xml)
94 tag_status = tag_root.find(TAG_STATUS)
95 tag_status = tag_root.find(TAG_STATUS)
95 if STATUS_SUCCESS == tag_status.text:
96 if STATUS_SUCCESS == tag_status.text:
@@ -56,7 +56,7 b' class KeyTest(TestCase):'
56 text='[post]%d[/post]' % post.id,
56 text='[post]%d[/post]' % post.id,
57 thread=post.get_thread())
57 thread=post.get_thread())
58
58
59 response = SyncManager().generate_response_get([reply_post])
59 response = SyncManager.generate_response_get([reply_post])
60 logger.debug(response)
60 logger.debug(response)
61
61
62 key = KeyPair.objects.get(primary=True)
62 key = KeyPair.objects.get(primary=True)
@@ -51,10 +51,10 b' class SyncTest(TestCase):'
51
51
52 post.delete()
52 post.delete()
53
53
54 SyncManager().parse_response_get(response)
54 SyncManager.parse_response_get(response)
55 self.assertEqual(1, Post.objects.count(),
55 self.assertEqual(1, Post.objects.count(),
56 'Post was not created from XML response.')
56 'Post was not created from XML response.')
57
57
58 SyncManager().parse_response_get(response)
58 SyncManager.parse_response_get(response)
59 self.assertEqual(1, Post.objects.count(),
59 self.assertEqual(1, Post.objects.count(),
60 'The same post was imported twice.')
60 'The same post was imported twice.')
@@ -254,5 +254,5 b' def sync_pull(request):'
254 else:
254 else:
255 pass # TODO Parse the XML and get filters from it
255 pass # TODO Parse the XML and get filters from it
256
256
257 xml = SyncManager().generate_response_get(posts)
257 xml = SyncManager.generate_response_get(posts)
258 return HttpResponse(content=xml)
258 return HttpResponse(content=xml)
@@ -28,7 +28,7 b' def response_get(request):'
28 if exists:
28 if exists:
29 posts.append(Post.objects.get(global_id=global_id))
29 posts.append(Post.objects.get(global_id=global_id))
30
30
31 response_xml = SyncManager().generate_response_get(posts)
31 response_xml = SyncManager.generate_response_get(posts)
32
32
33 return HttpResponse(content=response_xml)
33 return HttpResponse(content=response_xml)
34
34
@@ -40,7 +40,7 b' def get_post_sync_data(request, post_id)'
40 raise Http404()
40 raise Http404()
41
41
42 content = 'Global ID: %s\n\nXML: %s' \
42 content = 'Global ID: %s\n\nXML: %s' \
43 % (post.global_id, SyncManager().generate_response_get([post]))
43 % (post.global_id, SyncManager.generate_response_get([post]))
44
44
45
45
46 return HttpResponse(
46 return HttpResponse(
General Comments 0
You need to be logged in to leave comments. Login now