Commit 95aa1b8def2efe0c442c116f24cd211430a6e809
Committed by
Sergio Oliveira
1 parent
4193a02a
Exists in
trac_indexing
Apply Flake8
Signed-off-by: Carolina Ramalho <carol15022@hotmail.com>
Showing
2 changed files
with
35 additions
and
15 deletions
Show diff stats
colab/proxy/trac/data_api.py
1 | 1 | from re import match |
2 | -from time import mktime | |
3 | -import datetime | |
4 | 2 | |
5 | 3 | from django.db import connections |
6 | 4 | |
7 | 5 | from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki |
8 | 6 | from colab.proxy.utils.proxy_data_api import ProxyDataAPI |
9 | 7 | |
8 | + | |
10 | 9 | class TracDataAPI(ProxyDataAPI): |
11 | 10 | |
12 | 11 | def fetch_data(self): |
... | ... | @@ -32,7 +31,8 @@ class TracDataAPI(ProxyDataAPI): |
32 | 31 | attachment.ipnr = line['ipnr'] |
33 | 32 | attachment.url = attachment.used_by + "/" + attachment.id \ |
34 | 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 | 36 | if match("\.(\w+)$", attachment.filename): |
37 | 37 | attachment.mimetype = attachment.filename.lower() |
38 | 38 | attachment.save() |
... | ... | @@ -92,7 +92,7 @@ class TracDataAPI(ProxyDataAPI): |
92 | 92 | if line['author'] not in collaborators: |
93 | 93 | collaborators.append(line['author']) |
94 | 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 | 96 | wiki.modified = self.get_wiki_modified(cursor, line['name']) |
97 | 97 | |
98 | 98 | wiki.save() |
... | ... | @@ -125,37 +125,56 @@ class TracDataAPI(ProxyDataAPI): |
125 | 125 | return cursor |
126 | 126 | |
127 | 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 | 133 | modified_data = matriz_data_wiki[0][0] |
131 | 134 | return modified_data |
132 | 135 | |
133 | 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 | 143 | return modified_data |
138 | 144 | |
139 | 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 | 151 | matriz_data_attachment = cursor.fetchall() |
142 | 152 | modified_data = matriz_data_attachment[0][0] |
143 | 153 | return modified_data |
144 | 154 | |
145 | 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 | 160 | matriz_data_revision = cursor.fetchall() |
148 | 161 | modified_data = matriz_data_revision[0][0] |
149 | 162 | return modified_data |
150 | 163 | |
151 | 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 | 169 | matriz_data_ticket = cursor.fetchall() |
154 | 170 | modified_data = matriz_data_ticket[0][0] |
155 | 171 | return modified_data |
156 | 172 | |
157 | 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 | 178 | matriz_data_ticket = cursor.fetchall() |
160 | 179 | modified_data = matriz_data_ticket[0][0] |
161 | 180 | return modified_data | ... | ... |
colab/proxy/trac/tests/test_data_api.py
... | ... | @@ -11,6 +11,7 @@ from django.test import TestCase |
11 | 11 | class TracDataAPITest(TestCase): |
12 | 12 | |
13 | 13 | fixtures = ["trac_data.json"] |
14 | + | |
14 | 15 | def setUp(self): |
15 | 16 | self.connection = connections['default'] |
16 | 17 | self.cursor = self.connection.cursor() |
... | ... | @@ -19,13 +20,13 @@ class TracDataAPITest(TestCase): |
19 | 20 | self.connection.close() |
20 | 21 | |
21 | 22 | def test_dict_fetch_all(self): |
22 | - trac_dict= TracDataAPI() | |
23 | + trac_dict = TracDataAPI() | |
23 | 24 | self.cursor.execute(''' SELECT * FROM trac_wiki;''') |
24 | 25 | dict_result = trac_dict.dictfetchall(self.cursor) |
25 | 26 | self.assertIn('collaborators', dict_result[0]) |
26 | 27 | |
27 | 28 | def test_dict_fetch_all_is_dict(self): |
28 | - trac_dict= TracDataAPI() | |
29 | + trac_dict = TracDataAPI() | |
29 | 30 | self.cursor.execute(''' SELECT * FROM trac_wiki;''') |
30 | 31 | dict_result = trac_dict.dictfetchall(self.cursor) |
31 | 32 | self.assertIsInstance(dict_result[0], dict) | ... | ... |