Commit d52ff5ac3b1ce35f5423592781dcb44802715b66
Committed by
Sergio Oliveira
1 parent
db87277a
Exists in
trac_indexing
Tests for Trac Models.
Signed-off-by: Carolina Ramalho <carol15022@hotmail.com>
Showing
4 changed files
with
211 additions
and
5 deletions
Show diff stats
colab/proxy/trac/data_api.py
... | ... | @@ -61,7 +61,7 @@ class TracDataAPI(ProxyDataAPI): |
61 | 61 | for line in ticket_dict: |
62 | 62 | ticket.id = line['id'] |
63 | 63 | ticket.summary = line['summary'] |
64 | - ticket.description = line['description'] | |
64 | + ticket.description_ticket = line['description'] | |
65 | 65 | ticket.milestone = line['milestone'] |
66 | 66 | ticket.priority = line['priority'] |
67 | 67 | ticket.component = line['component'] | ... | ... |
colab/proxy/trac/models.py
... | ... | @@ -68,6 +68,7 @@ class Revision(models.Model, HitCounterModelMixin): |
68 | 68 | class Meta: |
69 | 69 | verbose_name = _('Attachment') |
70 | 70 | verbose_name_plural = _('Attachment') |
71 | + db_table = 'trac_revision' | |
71 | 72 | |
72 | 73 | def get_absolute_url(self): |
73 | 74 | return u'/changeset/{}/{}'.format(self.rev, self.repository_name) |
... | ... | @@ -84,7 +85,7 @@ class Ticket(models.Model, HitCounterModelMixin): |
84 | 85 | type = 'ticket' |
85 | 86 | id = models.IntegerField(primary_key=True) |
86 | 87 | summary = models.TextField(blank=True) |
87 | - description = models.TextField(blank=True) | |
88 | + description_ticket = models.TextField(blank=True) | |
88 | 89 | milestone = models.TextField(blank=True) |
89 | 90 | priority = models.TextField(blank=True) |
90 | 91 | component = models.TextField(blank=True) |
... | ... | @@ -107,7 +108,7 @@ class Ticket(models.Model, HitCounterModelMixin): |
107 | 108 | @property |
108 | 109 | def description(self): |
109 | 110 | return u'{}\n{}\n{}\n{}\n{}\n{}\n{}'.format( |
110 | - self.description, self.milestone, self.component, self.severity, | |
111 | + self.description_ticket, self.milestone, self.component, self.severity, | |
111 | 112 | self.reporter, self.keywords, self.collaborators |
112 | 113 | ) |
113 | 114 | |
... | ... | @@ -150,7 +151,7 @@ class Wiki(Collaboration, HitCounterModelMixin): |
150 | 151 | verbose_name_plural = _('Attachment') |
151 | 152 | |
152 | 153 | def get_absolute_url(self): |
153 | - return u'/wiki/{}'.format(self.name) | |
154 | + return u'/wiki/{}'.format(self.title) | |
154 | 155 | |
155 | 156 | def get_author(self): |
156 | 157 | try: |
... | ... | @@ -160,7 +161,7 @@ class Wiki(Collaboration, HitCounterModelMixin): |
160 | 161 | |
161 | 162 | def get_modified_by(self): |
162 | 163 | try: |
163 | - return User.objects.get(username=self.modified_by) | |
164 | + return User.objects.get(username=self.author) | |
164 | 165 | except User.DoesNotExist: |
165 | 166 | return None |
166 | 167 | ... | ... |
... | ... | @@ -0,0 +1,205 @@ |
1 | +""" | |
2 | +Test Trac class. | |
3 | +Objective: Test parameters and behavior. | |
4 | +""" | |
5 | +from colab.accounts.models import User | |
6 | +from colab.proxy.trac.models import Attachment, Revision, Ticket, Wiki | |
7 | +from django.test import TestCase | |
8 | + | |
9 | + | |
10 | +class AttachmentTest(TestCase): | |
11 | + | |
12 | + def setUp(self): | |
13 | + self.attachment = self.create_attachment() | |
14 | + | |
15 | + def tearDown(self): | |
16 | + pass | |
17 | + | |
18 | + def create_attachment(self): | |
19 | + attachment = Attachment() | |
20 | + attachment.type = 'attachment' | |
21 | + attachment.icon_name = 'file' | |
22 | + attachment.url = 'example.com' | |
23 | + attachment.attach_id = 'attach_id' | |
24 | + attachment.used_by = 'used_by' | |
25 | + attachment.filename = 'filename' | |
26 | + attachment.author = 'author' | |
27 | + attachment.title = 'title' | |
28 | + attachment.description = 'description' | |
29 | + attachment.modified = '1994-11-05T08:15:30-05:00' | |
30 | + attachment.mimetype = 'mimetype' | |
31 | + attachment.size = 20 | |
32 | + attachment.save() | |
33 | + | |
34 | + return attachment | |
35 | + | |
36 | + def test_validade_filepath(self): | |
37 | + file_path = '/mnt/trac/attachments/used_by/attach_id/filename' | |
38 | + self.assertEqual(file_path, self.attachment.filepath) | |
39 | + | |
40 | + def test_validade_absolute_url(self): | |
41 | + absolute_url = u'/raw-attachment/example.com' | |
42 | + self.assertEqual(absolute_url, self.attachment.get_absolute_url()) | |
43 | + | |
44 | + def test_validade_author(self): | |
45 | + author = 'author' | |
46 | + self.user = create_user() | |
47 | + self.assertEqual(author, str(self.attachment.get_author())) | |
48 | + | |
49 | + def test_invalidade_author(self): | |
50 | + self.assertEqual(None, self.attachment.get_author()) | |
51 | + | |
52 | + | |
53 | +class RevisionTest(TestCase): | |
54 | + def setUp(self): | |
55 | + self.revision = self.create_revision() | |
56 | + | |
57 | + def create_revision(self): | |
58 | + revision = Revision() | |
59 | + revision.update_field = 'created' | |
60 | + revision.icon_name = 'align-right' | |
61 | + revision.rev = 'rev' | |
62 | + revision.author = 'author' | |
63 | + revision.message = 'message' | |
64 | + revision.description = 'description' | |
65 | + revision.repository_name = 'repository' | |
66 | + revision.created = '1994-11-05T08:15:30-05:00' | |
67 | + revision.modified = '1994-11-05T08:15:30-05:00' | |
68 | + revision.save() | |
69 | + | |
70 | + return revision | |
71 | + | |
72 | + def test_title(self): | |
73 | + title = 'repository [rev]' | |
74 | + self.assertEqual(title, self.revision.title) | |
75 | + | |
76 | + def test_get_absolute_url(self): | |
77 | + absolute_url = '/changeset/rev/repository' | |
78 | + self.assertEqual(absolute_url, self.revision.get_absolute_url()) | |
79 | + | |
80 | + def test_get_author(self): | |
81 | + author = 'author' | |
82 | + self.user = create_user() | |
83 | + self.assertEqual(author, str(self.revision.get_author())) | |
84 | + | |
85 | + def test_invalid_get_author(self): | |
86 | + self.assertEqual(None, self.revision.get_author()) | |
87 | + | |
88 | + | |
89 | +class TicketTest(TestCase): | |
90 | + def setUp(self): | |
91 | + self.ticket = self.create_ticket() | |
92 | + | |
93 | + def create_ticket(self): | |
94 | + ticket = Ticket() | |
95 | + ticket.icon_name = 'tag' | |
96 | + ticket.type = 'ticket' | |
97 | + ticket.id = 20 | |
98 | + ticket.summary = 'summary' | |
99 | + ticket.description_ticket = 'description' | |
100 | + ticket.milestone = 'milestone' | |
101 | + ticket.priority = 'priority' | |
102 | + ticket.component = 'component' | |
103 | + ticket.version = 'version' | |
104 | + ticket.severity = 'severity' | |
105 | + ticket.reporter = 'reporter' | |
106 | + ticket.author = 'author' | |
107 | + ticket.status = 'status' | |
108 | + ticket.tag = 'tag' | |
109 | + ticket.keywords = 'keywords' | |
110 | + ticket.collaborators = 'collaborators' | |
111 | + ticket.created = '1994-11-05T08:15:30-05:00' | |
112 | + ticket.modified = '1994-11-05T08:15:30-05:00' | |
113 | + ticket.modified_by = 'author' | |
114 | + ticket.save() | |
115 | + | |
116 | + return ticket | |
117 | + | |
118 | + def test_title(self): | |
119 | + title = '#20 - summary' | |
120 | + self.assertEqual(title, self.ticket.title) | |
121 | + | |
122 | + def test_description(self): | |
123 | + description1 = u'description\nmilestone\ncomponent\nseverity' | |
124 | + description2 = '\nreporter\nkeywords\ncollaborators' | |
125 | + description_test = description1 + description2 | |
126 | + self.assertEqual(description_test, self.ticket.description) | |
127 | + | |
128 | + def test_get_absolute_url(self): | |
129 | + absolute_url = '/ticket/20' | |
130 | + self.assertEqual(absolute_url, self.ticket.get_absolute_url()) | |
131 | + | |
132 | + def test_get_author(self): | |
133 | + author = 'author' | |
134 | + self.user = create_user() | |
135 | + self.assertEqual(author, str(self.ticket.get_author())) | |
136 | + | |
137 | + def test_invalid_get_author(self): | |
138 | + author = None | |
139 | + self.assertEqual(author, self.ticket.get_author()) | |
140 | + | |
141 | + def test_get_modified_by(self): | |
142 | + self.user = create_user() | |
143 | + get_modified_by = str(self.ticket.get_modified_by()) | |
144 | + self.assertEqual(self.ticket.modified_by, get_modified_by) | |
145 | + | |
146 | + def test_invalid_get_modified_by(self): | |
147 | + get_modified_by = self.ticket.get_modified_by() | |
148 | + self.assertEqual(None, get_modified_by) | |
149 | + | |
150 | + | |
151 | +class WikiTest(TestCase): | |
152 | + def setUp(self): | |
153 | + self.wiki = self.create_wiki() | |
154 | + | |
155 | + def create_wiki(self): | |
156 | + wiki = Wiki() | |
157 | + wiki.type = "wiki" | |
158 | + wiki.icon_name = "book" | |
159 | + wiki.title = 'title' | |
160 | + wiki.wiki_text = 'wiki_text' | |
161 | + wiki.author = 'author' | |
162 | + wiki.collaborators = 'collaborators' | |
163 | + wiki.created = '1994-11-05T08:15:30-05:00' | |
164 | + wiki.modified = '1994-11-05T08:15:30-05:00' | |
165 | + wiki.save() | |
166 | + | |
167 | + return wiki | |
168 | + | |
169 | + def test_description(self): | |
170 | + description_test = u'wiki_text\ncollaborators' | |
171 | + self.assertEqual(description_test, self.wiki.description) | |
172 | + | |
173 | + def test_get_absolute_url(self): | |
174 | + absolute_url = u'/wiki/title' | |
175 | + self.assertEqual(absolute_url, self.wiki.get_absolute_url()) | |
176 | + | |
177 | + def test_get_author(self): | |
178 | + author = 'author' | |
179 | + self.user = create_user() | |
180 | + self.assertEqual(author, str(self.wiki.get_author())) | |
181 | + | |
182 | + def test_invalid_get_author(self): | |
183 | + author = None | |
184 | + self.assertEqual(author, self.wiki.get_author()) | |
185 | + | |
186 | + def test_get_modified_by(self): | |
187 | + self.user = create_user() | |
188 | + get_modified_by = str(self.wiki.get_modified_by()) | |
189 | + modified_by = "author" | |
190 | + self.assertEqual(modified_by, get_modified_by) | |
191 | + | |
192 | + def test_invalid_get_modified_by(self): | |
193 | + get_modified_by = self.wiki.get_modified_by() | |
194 | + self.assertEqual(None, get_modified_by) | |
195 | + | |
196 | + | |
197 | +def create_user(): | |
198 | + user = User() | |
199 | + user.username = "author" | |
200 | + user.first_name = "FisrtName" | |
201 | + user.last_name = "LastName" | |
202 | + user.modified_by = "author" | |
203 | + user.save() | |
204 | + | |
205 | + return user | ... | ... |