From 027ebb2bea1e41a9c29789f156b8c41b8803a0b4 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Tue, 11 Aug 2015 20:28:29 +0000 Subject: [PATCH] Added Tests and fixing discussion --- colab_spb/fixtures/test_data.json | 368 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ colab_spb/templates/discussion.html | 2 -- colab_spb/tests/test_get_list.py | 10 +++++----- colab_spb/views.py | 13 +++++++------ tests/settings.py | 7 ++++--- 5 files changed, 384 insertions(+), 16 deletions(-) create mode 100644 colab_spb/fixtures/test_data.json diff --git a/colab_spb/fixtures/test_data.json b/colab_spb/fixtures/test_data.json new file mode 100644 index 0000000..75568ca --- /dev/null +++ b/colab_spb/fixtures/test_data.json @@ -0,0 +1,368 @@ +[ +{ + "fields": { + "description": "List A description.", + "email": "listA@example.com", + "logo": "", + "last_imported_index": 0, + "is_private": false, + "name": "ListA" + }, + "model": "super_archives.mailinglist", + "pk": 1 +}, +{ + "fields": { + "description": "List B description.", + "email": "listB@example.com", + "logo": "", + "last_imported_index": 0, + "is_private": false, + "name": "ListB" + }, + "model": "super_archives.mailinglist", + "pk": 2 +}, +{ + "fields": { + "description": "List C description", + "email": "listC@example.com", + "logo": "", + "last_imported_index": 0, + "is_private": false, + "name": "ListC" + }, + "model": "super_archives.mailinglist", + "pk": 3 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_1_on_List_A", + "mailinglist": 1, + "score": 31, + "latest_message": 3 + }, + "model": "super_archives.thread", + "pk": 1 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_1_on_List_B", + "mailinglist": 2, + "score": 0, + "latest_message": 4 + }, + "model": "super_archives.thread", + "pk": 3 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_1_on_List_C", + "mailinglist": 3, + "score": 0, + "latest_message": 8 + }, + "model": "super_archives.thread", + "pk": 4 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_2_on_List_A ", + "mailinglist": 1, + "score": 24, + "latest_message": null + }, + "model": "super_archives.thread", + "pk": 5 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_3_on_List_A ", + "mailinglist": 1, + "score": 24, + "latest_message": null + }, + "model": "super_archives.thread", + "pk": 6 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_4_on_List_A ", + "mailinglist": 1, + "score": 24, + "latest_message": null + }, + "model": "super_archives.thread", + "pk": 7 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_5_on_List_A ", + "mailinglist": 1, + "score": 24, + "latest_message": null + }, + "model": "super_archives.thread", + "pk": 8 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_6_on_List_A ", + "mailinglist": 1, + "score": 24, + "latest_message": null + }, + "model": "super_archives.thread", + "pk": 9 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_7_on_List_A ", + "mailinglist": 1, + "score": 24, + "latest_message": null + }, + "model": "super_archives.thread", + "pk": 10 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_8_on_List_A ", + "mailinglist": 1, + "score": 24, + "latest_message": null + }, + "model": "super_archives.thread", + "pk": 11 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list A", + "received_time": "2015-01-28T12:43:00.752Z", + "from_address": 1, + "thread": 1, + "spam": false, + "subject_clean": "Response to Thread 1A", + "message_id": "response_t1a", + "subject": "Response to Thread 1A" + }, + "model": "super_archives.message", + "pk": 3 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list B", + "received_time": "2015-01-28T12:57:22.180Z", + "from_address": 1, + "thread": 3, + "spam": false, + "subject_clean": "Response to Thread 1B", + "message_id": "response_t1b", + "subject": "Message 1 on Thread 1B" + }, + "model": "super_archives.message", + "pk": 4 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list C", + "received_time": "2015-01-28T13:02:12.903Z", + "from_address": 1, + "thread": 4, + "spam": false, + "subject_clean": "Response to Thread 1C", + "message_id": "response_1t1c", + "subject": "Message 1 on Thread 1C" + }, + "model": "super_archives.message", + "pk": 5 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list C", + "received_time": "2015-01-28T13:02:12.903Z", + "from_address": 1, + "thread": 4, + "spam": false, + "subject_clean": "Response 2 to Thread C", + "message_id": "response_2t1c", + "subject": "Message 2 to Thread 1C" + }, + "model": "super_archives.message", + "pk": 6 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list C", + "received_time": "2015-01-28T13:02:12.903Z", + "from_address": 1, + "thread": 4, + "spam": false, + "subject_clean": "Response 3 to Thread C", + "message_id": "response_3t1c", + "subject": "Message 3 to Thread 1C" + }, + "model": "super_archives.message", + "pk": 7 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list C", + "received_time": "2015-01-28T13:02:12.903Z", + "from_address": 1, + "thread": 4, + "spam": false, + "subject_clean": "Response 4 to Thread C", + "message_id": "response_4t1c", + "subject": "Message 4 to Thread 1C" + }, + "model": "super_archives.message", + "pk": 8 +}, +{ + "fields": { + "last_name": "Administrator", + "webpage": "", + "twitter": "", + "is_staff": true, + "user_permissions": [], + "date_joined": "2015-01-28T12:34:58.770Z", + "google_talk": "", + "first_name": "Admin", + "is_superuser": true, + "last_login": "2015-01-28T12:35:39.621Z", + "verification_hash": null, + "role": "", + "email": "admin@mail.com", + "username": "admin", + "bio": "", + "needs_update": true, + "is_active": true, + "facebook": "", + "groups": [], + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", + "institution": "", + "github": "", + "modified": "2015-01-28T12:45:27.375Z" + }, + "model": "accounts.user", + "pk": 1 +}, +{ + "fields": { + "last_name": "Norris", + "webpage": "", + "twitter": "", + "is_staff": true, + "user_permissions": [], + "date_joined": "2015-01-28T12:34:58.770Z", + "google_talk": "", + "first_name": "Chuck", + "is_superuser": true, + "last_login": "2015-01-28T12:35:39.621Z", + "verification_hash": null, + "role": "", + "email": "chucknorris@mail.com", + "username": "chucknorris", + "bio": "", + "needs_update": true, + "is_active": true, + "facebook": "", + "groups": [], + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", + "institution": "", + "github": "", + "modified": "2015-01-28T12:45:27.375Z" + }, + "model": "accounts.user", + "pk": 2 +}, +{ + "fields": { + "last_name": "Norris", + "webpage": "", + "twitter": "", + "is_staff": true, + "user_permissions": [], + "date_joined": "2015-01-28T12:34:58.770Z", + "google_talk": "", + "first_name": "Heisenberg", + "is_superuser": true, + "last_login": "2015-01-28T12:35:39.621Z", + "verification_hash": null, + "role": "", + "email": "heisenberg@mail.com", + "username": "heisenbergnorris", + "bio": "", + "needs_update": true, + "is_active": true, + "facebook": "", + "groups": [], + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", + "institution": "", + "github": "", + "modified": "2015-01-28T12:45:27.375Z" + }, + "model": "accounts.user", + "pk": 3 +}, +{ + "fields": { + "last_name": "macartur", + "webpage": "", + "twitter": "", + "is_staff": false, + "user_permissions": [], + "date_joined": "2015-08-06T19:23:53Z", + "google_talk": "", + "first_name": "macartur", + "is_superuser": false, + "last_login": "2015-08-10T19:30:49.564Z", + "verification_hash": null, + "role": null, + "email": "macartur.sc@gmail.com", + "username": "macartur", + "bio": null, + "needs_update": false, + "is_active": true, + "facebook": "", + "groups": [], + "password": "pbkdf2_sha256$15000$nK2UEWhXi0pK$82RfvAo2pyarmmig8C5rjSq9s5CQihi4myKazIuozj0=", + "institution": null, + "github": null, + "modified": "2015-08-06T19:25:34.683Z" + }, + "model": "accounts.user", + "pk": 4 +}, +{ + "fields": { + "real_name": "", + "user": 1, + "md5": "edb0e96701c209ab4b50211c856c50c4", + "address": "admin@mail.com" + }, + "model": "super_archives.emailaddress", + "pk": 1 +}, +{ + "fields": { + "validation_key": "78e8af5ec02c44cba40db50d720b06fc", + "created": "2015-08-06T19:23:53.473Z", + "user": 4, + "address": "macartur.sc@gmail.com" + }, + "model": "super_archives.emailaddressvalidation", + "pk": 1 +} +] diff --git a/colab_spb/templates/discussion.html b/colab_spb/templates/discussion.html index c2fbb92..7662c5a 100644 --- a/colab_spb/templates/discussion.html +++ b/colab_spb/templates/discussion.html @@ -30,7 +30,5 @@ - - {% endif %} {% endfor %} diff --git a/colab_spb/tests/test_get_list.py b/colab_spb/tests/test_get_list.py index 728f7dc..ae54fb6 100644 --- a/colab_spb/tests/test_get_list.py +++ b/colab_spb/tests/test_get_list.py @@ -4,7 +4,7 @@ from django.test import TestCase, Client class ColabSPB(TestCase): - fixtures = ['colab_data.json'] + fixtures = ['test_data.json'] def setUp(self): super(ColabSPB, self).setUp() @@ -15,13 +15,13 @@ class ColabSPB(TestCase): def test_getlist_without_list(self): response = self.client.get("/spb/get_list/?list_name=") - self.assertEqual("x",response.content) + self.assertEqual("",response.content) + self.assertEqual(404,response.status_code) def test_getlist_with_list(self): response = self.client.get("/spb/get_list/?list_name=ListA&MAX=5") - self.assertEqual("x",response.content) + self.assertEqual(5,len(response.context[1]['latest'])) def test_getlist_default_MAX(self): response = self.client.get("/spb/get_list/?list_name=ListA") - self.assertEqual("x",response.content) - + self.assertEqual(7,len(response.context[1]['latest'])) diff --git a/colab_spb/views.py b/colab_spb/views.py index f195506..79c84ec 100644 --- a/colab_spb/views.py +++ b/colab_spb/views.py @@ -1,16 +1,14 @@ from django.shortcuts import render +from django.http import HttpResponse from django.utils.translation import ugettext as _ from colab.super_archives.models import MailingList, Thread from colab.accounts.utils import mailman from colab.accounts.models import User def get_list(request): - list_name = None - MAX = 0 - if request.GET.get('list_name'): - list_name = request.GET['list_name'] - if request.GET.get('MAX'): - MAX = request.GET['MAX'] + + list_name = request.GET.get('list_name',None) + MAX = request.GET.get('MAX',7) context = {} @@ -39,4 +37,7 @@ def get_list(request): len(mailman.list_users(list_.name)), )) + if len(context['lists']) == 0: + return HttpResponse('',status=404) + return render(request,"discussion.html",context) diff --git a/tests/settings.py b/tests/settings.py index 3ddd7a0..35fd8d0 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -31,7 +31,8 @@ LOGGING = { HAYSTACK_CONNECTIONS = { 'default': { - 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', - 'URL': 'http://127.0.0.1:8983/solr' - }, + 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', + 'PATH': os.path.join(BASE_DIR, 'whoosh_index'), + } } + -- libgit2 0.21.2