Commit d5d91e364dd40d1c76b73b7177f5ab503f10afd5

Authored by Macartur Sousa
1 parent b2db5aa5

Added test and refactored gitlab_view

fixtures: add fixtures to use colab_association
views: change some names
tests: added tests to gitlab_activities view

Signed-off-by: Carlos Oliveira <carlospecter@gmail.com>
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
src/colab_spb/fixtures/__init__.py 0 → 100644
src/colab_spb/fixtures/colab_spb.json
... ... @@ -379,5 +379,35 @@
379 379 },
380 380 "model": "super_archives.emailaddress",
381 381 "pk": 1
  382 +},
  383 +{
  384 + "fields": {
  385 + "description": null,
  386 + "created_at": "2015-09-29T14:36:58Z",
  387 + "user": null,
  388 + "identifier": "example_community",
  389 + "categories": [],
  390 + "name": "example_community"
  391 + },
  392 + "model": "colab_noosfero.noosferocommunity",
  393 + "pk": 69
  394 +},
  395 +{
  396 + "fields": {
  397 + "path": "example_community",
  398 + "name": "example_community",
  399 + "owner_id": null
  400 + },
  401 + "model": "colab_gitlab.gitlabgroup",
  402 + "pk": 23
  403 +},
  404 +{
  405 + "fields": {
  406 + "mail_list": 1,
  407 + "group": 23,
  408 + "community": 69
  409 + },
  410 + "model": "colab_spb.communityassociations",
  411 + "pk": 2
382 412 }
383 413 ]
... ...
src/colab_spb/templates/gitlab_activity.html
... ... @@ -13,7 +13,7 @@
13 13  
14 14 {% if community_association %}
15 15  
16   - $.getJSON("{{community_association.repository}}",{limit: {{community_association.activities_limit}}, offset: {{community_association.offset}}},function(msg, e){
  16 + $.getJSON("{{community_association.repository}}",{limit: {{community_association.limit}}, offset: {{community_association.offset}}},function(msg, e){
17 17 $tag.html(msg.html);
18 18 $tag.append("<div class=\"see-more-repository\">" +
19 19 "<a href={{community_association.repository}}>" +
... ...
src/colab_spb/views.py
... ... @@ -46,30 +46,38 @@ def mail_list(request):
46 46 message = ("Não foi possível encontrada lista de discussão"
47 47 " associada a está comunidade, para mais"
48 48 " detalhes contate o administrador.")
49   - return HttpResponse(message, status=404)
  49 + return HttpResponse(message, status=200)
50 50  
51 51 return render(request, 'discussion.html', context)
52 52  
53 53  
54 54 def gitlab_activity(request):
55 55 community = request.GET.get('community', "")
  56 + limit = request.GET.get('limit',7)
  57 + offset = request.GET.get('offset',0)
56 58  
57 59 context = {}
58 60 context['message'] = ("Esta comunidade não está associada a"
59   - " nenhum repositório no momento, para mais"
60   - " detalhes contate o administrador")
61   - context['community_association'] = get_community_association(community)
  61 + " nenhum repositório no momento, para mais"
  62 + " detalhes contate o administrador.")
  63 +
  64 + association = get_community_association(community, limit, offset)
  65 + context['community_association'] = association
  66 +
62 67 return render(request, 'gitlab_activity.html', context)
63 68  
64   -def get_community_association(community):
65   - if community:
66   - associations = CommunityAssociations.objects.all()
67   - for community_association in associations:
68   - if community_association.community.name in community:
69   - return { 'community': community_association.community.name,
70   - 'repository': community_association.group.url,
71   - 'mailman_list': community_association.mail_list.name,
72   - 'activities_limit': 7,
73   - 'offset': 0,
74   - }
75   - return {}
  69 +def get_community_association(community,limit=7,offset=0):
  70 + if not community:
  71 + return {}
  72 +
  73 + associations = CommunityAssociations.objects.all()
  74 + for community_association in associations:
  75 + if community_association.community.name in community:
  76 + return { 'community': community_association.community.name,
  77 + 'repository': community_association.group.url,
  78 + 'mailman_list': community_association.mail_list.name,
  79 + 'limit': limit,
  80 + 'offset': offset,
  81 + }
  82 +
  83 + return {}
... ...
tests/test_colab_integration.py 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +# -*- coding: utf-8 -*-
  2 +
  3 +from django.test import TestCase, Client
  4 +
  5 +
  6 +class SPBTest(TestCase):
  7 +
  8 + fixtures = ['colab_spb.json']
  9 +
  10 + def setUp(self):
  11 + super(SPBTest, self).setUp()
  12 + self.client = Client()
  13 +
  14 + def tearDown(self):
  15 + pass
  16 +
  17 + def test_mail_list_without_list(self):
  18 + response = self.client.get("/spb/mail_list/?community=")
  19 + message = ("Não foi possível encontrada lista de discussão"
  20 + " associada a está comunidade, para mais"
  21 + " detalhes contate o administrador.")
  22 + self.assertEqual(message, response.content)
  23 + self.assertEqual(200, response.status_code)
  24 +
  25 + def test_mail_list_with_list(self):
  26 + response = self.client.get("/spb/mail_list/"
  27 + "?community=example_community&MAX=5")
  28 + self.assertEqual(5, len(response.context[1]['latest']))
  29 +
  30 + def test_mail_list_default_MAX(self):
  31 + response = self.client.get("/spb/mail_list/"
  32 + "?community=example_community")
  33 + self.assertEqual(7, len(response.context[1]['latest']))
  34 +
  35 + def test_mail_list_invalid_MAX(self):
  36 + response = self.client.get("/spb/mail_list/"
  37 + "?community=example_community&MAX=")
  38 + self.assertEqual(7, len(response.context[1]['latest']))
  39 +
  40 + def test_gitlab_community_association_with_invalid_community(self):
  41 + response = self.client.get("/spb/gitlab_activity/?community=")
  42 + message = ("Esta comunidade não está associada a"
  43 + " nenhum repositório no momento, para mais"
  44 + " detalhes contate o administrador.")
  45 + self.assertIn(message, response.content)
  46 + self.assertEqual(dict() ,response.context['community_association'])
  47 + self.assertEqual(200, response.status_code)
  48 +
  49 + def test_gitlab_community_association_with_valid_community(self):
  50 + response = self.client.get("/spb/gitlab_activity/"
  51 + "?community=example_community")
  52 +
  53 + result = response.context['community_association']
  54 +
  55 + self.assertEqual(type(result), dict)
  56 + self.assertEqual(result['community'], 'example_community')
  57 + self.assertEqual(result['limit'], 7)
  58 + self.assertEqual(result['offset'], 0)
  59 + self.assertEqual(result['repository'],
  60 + '/gitlab/groups/example_community')
  61 + self.assertEqual(result['mailman_list'], 'ListA')
  62 +
  63 + def test_gitlab_community_association_with_no_default_limit(self):
  64 + response = self.client.get("/spb/gitlab_activity/"
  65 + "?community=example_community"
  66 + "&limit=5")
  67 +
  68 + result = response.context['community_association']
  69 +
  70 + self.assertEqual(type(result), dict)
  71 + self.assertEqual(result['limit'], "5")
  72 +
  73 +
  74 + def test_gitlab_community_association_with_no_default_offset(self):
  75 + response = self.client.get("/spb/gitlab_activity/"
  76 + "?community=example_community"
  77 + "&offset=5")
  78 +
  79 + result = response.context['community_association']
  80 +
  81 + self.assertEqual(result['offset'],"5")
... ...
tests/test_get_list.py
... ... @@ -1,34 +0,0 @@
1   -# -*- coding: utf-8 -*-
2   -from django.test import TestCase, Client
3   -
4   -
5   -class SPBTest(TestCase):
6   -
7   - fixtures = ['colab_spb.json']
8   -
9   - def setUp(self):
10   - super(SPBTest, self).setUp()
11   - self.client = Client()
12   -
13   - def tearDown(self):
14   - pass
15   -
16   - def test_getlist_without_list(self):
17   - response = self.client.get("/spb/get_list/?list_name=")
18   - message = ("Não foi possível encontrada lista de discussão"
19   - " associada a está comunidade, para mais"
20   - " detalhes contate o administrador.")
21   - self.assertEqual(message, response.content)
22   - self.assertEqual(404, response.status_code)
23   -
24   - def test_getlist_with_list(self):
25   - response = self.client.get("/spb/get_list/?list_name=ListA&MAX=5")
26   - self.assertEqual(5, len(response.context[1]['latest']))
27   -
28   - def test_getlist_default_MAX(self):
29   - response = self.client.get("/spb/get_list/?list_name=ListA")
30   - self.assertEqual(7, len(response.context[1]['latest']))
31   -
32   - def test_getlist_invalid_MAX(self):
33   - response = self.client.get("/spb/get_list/?list_name=ListA&MAX=")
34   - self.assertEqual(7, len(response.context[1]['latest']))