Commit 95aa1b8def2efe0c442c116f24cd211430a6e809

Authored by Thiago Ribeiro
Committed by Sergio Oliveira
1 parent 4193a02a
Exists in trac_indexing

Apply Flake8

Signed-off-by: Carolina Ramalho <carol15022@hotmail.com>
colab/proxy/trac/data_api.py
1 from re import match 1 from re import match
2 -from time import mktime  
3 -import datetime  
4 2
5 from django.db import connections 3 from django.db import connections
6 4
7 from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki 5 from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki
8 from colab.proxy.utils.proxy_data_api import ProxyDataAPI 6 from colab.proxy.utils.proxy_data_api import ProxyDataAPI
9 7
  8 +
10 class TracDataAPI(ProxyDataAPI): 9 class TracDataAPI(ProxyDataAPI):
11 10
12 def fetch_data(self): 11 def fetch_data(self):
@@ -32,7 +31,8 @@ class TracDataAPI(ProxyDataAPI): @@ -32,7 +31,8 @@ class TracDataAPI(ProxyDataAPI):
32 attachment.ipnr = line['ipnr'] 31 attachment.ipnr = line['ipnr']
33 attachment.url = attachment.used_by + "/" + attachment.id \ 32 attachment.url = attachment.used_by + "/" + attachment.id \
34 + "/" + attachment.filename 33 + "/" + attachment.filename
35 - attachment.created = self.get_attachment_created(cursor, line['id']) 34 + attachment.created = self.get_attachment_created(cursor,
  35 + line['id'])
36 if match("\.(\w+)$", attachment.filename): 36 if match("\.(\w+)$", attachment.filename):
37 attachment.mimetype = attachment.filename.lower() 37 attachment.mimetype = attachment.filename.lower()
38 attachment.save() 38 attachment.save()
@@ -92,7 +92,7 @@ class TracDataAPI(ProxyDataAPI): @@ -92,7 +92,7 @@ class TracDataAPI(ProxyDataAPI):
92 if line['author'] not in collaborators: 92 if line['author'] not in collaborators:
93 collaborators.append(line['author']) 93 collaborators.append(line['author'])
94 wiki.collaborators = collaborators 94 wiki.collaborators = collaborators
95 - wiki.created =self.get_wiki_created(cursor, line['name']) 95 + wiki.created = self.get_wiki_created(cursor, line['name'])
96 wiki.modified = self.get_wiki_modified(cursor, line['name']) 96 wiki.modified = self.get_wiki_modified(cursor, line['name'])
97 97
98 wiki.save() 98 wiki.save()
@@ -125,37 +125,56 @@ class TracDataAPI(ProxyDataAPI): @@ -125,37 +125,56 @@ class TracDataAPI(ProxyDataAPI):
125 return cursor 125 return cursor
126 126
127 def get_wiki_modified(self, cursor, wiki_name): 127 def get_wiki_modified(self, cursor, wiki_name):
128 - cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MAX(wiki.time)/1000000) * INTERVAL '1s', name from wiki where(name=\'"""+ wiki_name + """\') group by name; """)  
129 - matriz_data_wiki = cursor.fetchall() 128 + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
  129 + (MAX(wiki.time)/1000000) * INTERVAL '1s', \
  130 + name from wiki where(name=\'""" + wiki_name + """\') \
  131 + group by name; """)
  132 + matriz_data_wiki = cursor.fetchall()
130 modified_data = matriz_data_wiki[0][0] 133 modified_data = matriz_data_wiki[0][0]
131 return modified_data 134 return modified_data
132 135
133 def get_wiki_created(self, cursor, wiki_name): 136 def get_wiki_created(self, cursor, wiki_name):
134 - cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(wiki.time)/1000000) * INTERVAL '1s', name from wiki where(name=\'"""+ wiki_name + """\') group by name; """)  
135 - matrix_data_wiki = cursor.fetchall()  
136 - modified_data = matrix_data_wiki[0][0] 137 + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
  138 + (MIN(wiki.time)/1000000) * INTERVAL '1s', \
  139 + name from wiki where(name=\'""" + wiki_name + """\') \
  140 + group by name; """)
  141 + matriz_data_wiki = cursor.fetchall()
  142 + modified_data = matriz_data_wiki[0][0]
137 return modified_data 143 return modified_data
138 144
139 def get_attachment_created(self, cursor, attachment_id): 145 def get_attachment_created(self, cursor, attachment_id):
140 - cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(attachment.time)/1000000) * INTERVAL '1s', id from attachment where(id=\'"""+ attachment_id + """\') group by id; """) 146 + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
  147 + (MIN(attachment.time)/1000000) * INTERVAL '1s', \
  148 + id from attachment \
  149 + where(id=\'""" + attachment_id + """\') \
  150 + group by id; """)
141 matriz_data_attachment = cursor.fetchall() 151 matriz_data_attachment = cursor.fetchall()
142 modified_data = matriz_data_attachment[0][0] 152 modified_data = matriz_data_attachment[0][0]
143 return modified_data 153 return modified_data
144 154
145 def get_revision_created(self, cursor, revision): 155 def get_revision_created(self, cursor, revision):
146 - cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(revision.time)/1000000) * INTERVAL '1s', rev from revision where(rev=\'"""+ revision + """\') group by rev; """) 156 + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
  157 + (MIN(revision.time)/1000000) * INTERVAL '1s', \
  158 + rev from revision where(rev=\'""" + revision + """\') \
  159 + group by rev; """)
147 matriz_data_revision = cursor.fetchall() 160 matriz_data_revision = cursor.fetchall()
148 modified_data = matriz_data_revision[0][0] 161 modified_data = matriz_data_revision[0][0]
149 return modified_data 162 return modified_data
150 163
151 def get_ticket_created(self, cursor, ticket_id): 164 def get_ticket_created(self, cursor, ticket_id):
152 - cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MIN(ticket.time)/1000000) * INTERVAL '1s', id from ticket where(id="""+ str(ticket_id) + """) group by id; """) 165 + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
  166 + (MIN(ticket.time)/1000000) * INTERVAL '1s', \
  167 + id from ticket where(id=""" + str(ticket_id) + """) \
  168 + group by id; """)
153 matriz_data_ticket = cursor.fetchall() 169 matriz_data_ticket = cursor.fetchall()
154 modified_data = matriz_data_ticket[0][0] 170 modified_data = matriz_data_ticket[0][0]
155 return modified_data 171 return modified_data
156 172
157 def get_ticket_modified(self, cursor, ticket_id): 173 def get_ticket_modified(self, cursor, ticket_id):
158 - cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (MAX(ticket.time)/1000000) * INTERVAL '1s', id from ticket where(id="""+ str(ticket_id) + """) group by id; """) 174 + cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
  175 + (MAX(ticket.time)/1000000) * INTERVAL '1s', \
  176 + id from ticket where(id=""" + str(ticket_id) + """) \
  177 + group by id; """)
159 matriz_data_ticket = cursor.fetchall() 178 matriz_data_ticket = cursor.fetchall()
160 modified_data = matriz_data_ticket[0][0] 179 modified_data = matriz_data_ticket[0][0]
161 return modified_data 180 return modified_data
colab/proxy/trac/tests/test_data_api.py
@@ -11,6 +11,7 @@ from django.test import TestCase @@ -11,6 +11,7 @@ from django.test import TestCase
11 class TracDataAPITest(TestCase): 11 class TracDataAPITest(TestCase):
12 12
13 fixtures = ["trac_data.json"] 13 fixtures = ["trac_data.json"]
  14 +
14 def setUp(self): 15 def setUp(self):
15 self.connection = connections['default'] 16 self.connection = connections['default']
16 self.cursor = self.connection.cursor() 17 self.cursor = self.connection.cursor()
@@ -19,13 +20,13 @@ class TracDataAPITest(TestCase): @@ -19,13 +20,13 @@ class TracDataAPITest(TestCase):
19 self.connection.close() 20 self.connection.close()
20 21
21 def test_dict_fetch_all(self): 22 def test_dict_fetch_all(self):
22 - trac_dict= TracDataAPI() 23 + trac_dict = TracDataAPI()
23 self.cursor.execute(''' SELECT * FROM trac_wiki;''') 24 self.cursor.execute(''' SELECT * FROM trac_wiki;''')
24 dict_result = trac_dict.dictfetchall(self.cursor) 25 dict_result = trac_dict.dictfetchall(self.cursor)
25 self.assertIn('collaborators', dict_result[0]) 26 self.assertIn('collaborators', dict_result[0])
26 27
27 def test_dict_fetch_all_is_dict(self): 28 def test_dict_fetch_all_is_dict(self):
28 - trac_dict= TracDataAPI() 29 + trac_dict = TracDataAPI()
29 self.cursor.execute(''' SELECT * FROM trac_wiki;''') 30 self.cursor.execute(''' SELECT * FROM trac_wiki;''')
30 dict_result = trac_dict.dictfetchall(self.cursor) 31 dict_result = trac_dict.dictfetchall(self.cursor)
31 self.assertIsInstance(dict_result[0], dict) 32 self.assertIsInstance(dict_result[0], dict)