Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #234 from praekelt/feature/oneplus-235
Browse files Browse the repository at this point in the history
Feature/oneplus 235
  • Loading branch information
dbreedt committed May 26, 2015
2 parents 51c4f95 + 39907b7 commit 194f1f1
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 163 deletions.
6 changes: 3 additions & 3 deletions oneplus/templates/core/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<div class="menu">
<a href="/welcome"><div class="item text green-back darkgrey-front"><li class="icon welcome"></li><p>Welcome</p></div></a>
<a href="/ontrack"><div class="item text green-back darkgrey-front"><li class="icon ontrack"></li><p>On Track</p></div></a>
<a href="/chat"><div class="item text cyan-back darkgrey-front"><li class="icon chat"></li><p>Chat Groups</p></div></a>
<a href="/changedetails"><div class="item text yellow-back darkgrey-front"><li class="icon change_number"></li><p>Change Number/Email</p></div></a>
<a href="/faq"><div class="item text blue-back darkgrey-front"><li class="icon faq"></li><p>FAQ</p></div></a>
<a href="/chat"><div class="item text blue-back darkgrey-front"><li class="icon chat"></li><p>Chat Groups</p></div></a>
<a href="/changedetails"><div class="item text blue-back darkgrey-front"><li class="icon change_number"></li><p>Change Number/Email</p></div></a>
<a href="/faq"><div class="item text purple-back darkgrey-front"><li class="icon faq"></li><p>FAQ</p></div></a>
<a href="/blog"><div class="item text purple-back darkgrey-front"><li class="icon blog"></li><p>Blog</p></div></a>
<a href="/badges"><div class="item text red-back darkgrey-front"><li class="icon badges"></li><p>Badges</p></div></a>
<a href="/leader"><div class="item text orange-back darkgrey-front"><li class="icon leaderboard"></li><p>Leaderboard</p></div></a>
Expand Down
252 changes: 100 additions & 152 deletions oneplus/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from amqp.basic_message import Message
from celery.app.registry import TaskRegistry
from django.core.urlresolvers import reverse
from datetime import datetime, timedelta, date
from django.contrib.admin.sites import AdminSite
Expand Down Expand Up @@ -113,42 +114,6 @@ def create_and_answer_questions(self, num_questions, prefix, date):

return answers

def create_question_report(self, _user, _question, _issue, _fix):
return Report.objects.create(user=_user, question=_question, issue=_issue, fix=_fix)

def create_post(self, name="Test Post", description="Test", content="Test content"):
return Post.objects.create(
name=name,
description=description,
course=self.course,
content=content,
publishdate=datetime.now(),
moderated=True
)

def create_post_comment(self, post, author, content="Test Content"):
return PostComment.objects.create(
author=author,
post=post,
content=content,
publishdate=datetime.now()
)

def create_chat_group(self, course, name="Test Chat Group", description="Test"):
return ChatGroup.objects.create(
name=name,
description=description,
course=course
)

def create_chat_message(self, chat_group, author, content="Test"):
return ChatMessage.objects.create(
chatgroup=chat_group,
author=author,
content=content,
publishdate=datetime.now()
)

def setUp(self):

self.course = self.create_course()
Expand Down Expand Up @@ -190,8 +155,6 @@ def setUp(self):
password=self.admin_user_password,
mobile='+27111111133')

self.chat_group = self.create_chat_group(self.course)

def test_get_next_question(self):
self.create_test_question('question1', self.module)
learnerstate = LearnerState.objects.create(
Expand Down Expand Up @@ -255,11 +218,6 @@ def test_terms(self):
resp = self.client.post(reverse('misc.terms'), follow=True)
self.assertEquals(resp.status_code, 200)

def check_logs(self, msg):
logs = self.handler.logs
contains = [True for s in logs if msg == s.msg]
return contains

def assert_in_metric_logs(self, metric, aggr, value):
msg = "Metric: '%s' [%s] -> %d" % (metric, aggr, value)
logs = self.handler.logs
Expand Down Expand Up @@ -723,9 +681,6 @@ def test_smspassword_get(self):
resp = self.client.get(reverse('auth.smspassword'), follow=True)
self.assertEquals(resp.status_code, 200)

def save_send_text_values(self, to_addr, content):
self.outgoing_vumi_text.append((to_addr, content))

def test_smspassword_post(self):
#invalid form
resp = self.client.post(
Expand Down Expand Up @@ -1268,13 +1223,30 @@ def test_about_screen(self):
resp = self.client.post(reverse('misc.about'), follow=True)
self.assertEquals(resp.status_code, 200)

def fake_mail_managers(subject, message, fail_silently):
pass

@patch("django.core.mail.mail_managers", fake_mail_managers)
def test_contact_screen(self):
resp = self.client.get(reverse('misc.contact'))
self.assertEquals(resp.status_code, 200)

resp = self.client.post(reverse('misc.contact'), follow=True)
self.assertContains(resp, "Please complete the following fields:")

resp = self.client.post(
reverse("misc.contact"),
follow=True,
data={
"fname": "Test",
"sname": "test",
"contact": "0123456789",
"comment": "test",
"school": "Test School",
}
)
self.assertContains(resp, "Your message has been sent. We will get back to you in the next 24 hours")

def test_get_week_day(self):
day = get_week_day()
self.assertLess(day, 7)
Expand Down Expand Up @@ -1480,9 +1452,6 @@ def test_smspassword_get2(self):
resp = self.client.get(reverse('auth.smspassword'), follow=True)
self.assertEquals(resp.status_code, 200)

def save_send_text_values2(self, to_addr, content):
self.outgoing_vumi_text.append((to_addr, content))

def test_bloghero_screen(self):
self.client.get(reverse(
'auth.autologin',
Expand Down Expand Up @@ -1624,6 +1593,12 @@ def make_content(ftype, region=None):
self.assertContains(resp, 'MSISDN,First Name,Last Name,School,Region,Questions Completed,Percentage Correct')
self.assertNotContains(resp, '+27123456789')

# wrong mode
resp = c.get(reverse("reports.learner", kwargs={"mode": 3, "region": ""}))
self.assertEquals(resp.get("Content-Type"), "text/html; charset=utf-8")
self.assertEquals(resp.get("location"), "http://testserver/reports")
self.assertEquals(resp.status_code, 302)

def test_report_learner_unique_area(self):
c = Client()
c.login(username=self.admin_user.username, password=self.admin_user_password)
Expand Down Expand Up @@ -2217,56 +2192,6 @@ def test_is_monday_after_training(self, mock_get_today):
self.learner_state.QUESTIONS_PER_DAY + 1))


class MockRequest(object):
pass


class MockSuperUser(object):
def has_perm(self, perm):
return True


@override_settings(VUMI_GO_FAKE=True)
class OneplusAdminMetricTest(TestCase):
def create_course(self, name="course name", **kwargs):
return Course.objects.create(name=name, **kwargs)

def create_module(self, name, course, **kwargs):
module = Module.objects.create(name=name, **kwargs)
rel = CourseModuleRel.objects.create(course=course, module=module)
module.save()
rel.save()
return module

def create_class(self, name, course, **kwargs):
return Class.objects.create(name=name, course=course, **kwargs)

def create_organisation(self, name='organisation name', **kwargs):
return Organisation.objects.create(name=name, **kwargs)

def create_school(self, name, organisation, **kwargs):
return School.objects.create(
name=name, organisation=organisation, **kwargs)

def create_learner(self, school, **kwargs):
return Learner.objects.create(school=school, **kwargs)

def setUp(self):
self.site = AdminSite()
self.request = MockRequest()
self.course = self.create_course()
self.classs = self.create_class('class name', self.course)
self.organisation = self.create_organisation()
self.school = self.create_school('school name', self.organisation)
self.learner = self.create_learner(
self.school,
username="+27123456789",
mobile="+27123456789",
country="country",
unique_token='abc123',
unique_token_expiry=datetime.now() + timedelta(days=30))


class MessageTest(TestCase):
def create_organisation(self, name='organisation name', **kwargs):
return Organisation.objects.create(name=name, **kwargs)
Expand All @@ -2293,9 +2218,6 @@ def create_learner(self, school, **kwargs):
def create_participant(self, learner, classs, **kwargs):
return Participant.objects.create(learner=learner, classs=classs, **kwargs)

def create_message(self, author, course, **kwargs):
return Message.objects.create(author=author, course=course, **kwargs)

def setUp(self):
self.organisation = self.create_organisation()
self.school = self.create_school("abc", self.organisation)
Expand Down Expand Up @@ -2703,11 +2625,6 @@ def test_view_sms(self):


class ExtraAdminBitTests(TestCase):
def create_test_question(self, name, module, **kwargs):
return TestingQuestion.objects.create(name=name,
module=module,
**kwargs)

def create_course(self, name="course name", **kwargs):
return Course.objects.create(name=name, **kwargs)

Expand Down Expand Up @@ -2751,50 +2668,6 @@ def create_badgetemplate(self, name='badge template name', **kwargs):
def create_message(self, author, course, **kwargs):
return Message.objects.create(author=author, course=course, **kwargs)

def create_test_question_option(self, name, question, correct=True):
return TestingQuestionOption.objects.create(
name=name, question=question, correct=correct)

def create_test_answer(
self,
participant,
question,
option_selected,
answerdate):
return ParticipantQuestionAnswer.objects.create(
participant=participant,
question=question,
option_selected=option_selected,
answerdate=answerdate,
correct=False
)

def create_and_answer_questions(self, num_questions, prefix, date):
answers = []
for x in range(0, num_questions):
# Create a question
question = self.create_test_question(
'q' + prefix + str(x), self.module)

question.save()
option = self.create_test_question_option(
'option_' + prefix + str(x),
question)
option.save()
answer = self.create_test_answer(
participant=self.participant,
question=question,
option_selected=option,
answerdate=date
)
answer.save()
answers.append(answer)

return answers

def create_question_report(self, _user, _question, _issue, _fix):
return Report.objects.create(user=_user, question=_question, issue=_issue, fix=_fix)

def create_post(self, name="Test Post", description="Test", content="Test content"):
return Post.objects.create(
name=name,
Expand Down Expand Up @@ -3501,4 +3374,79 @@ def test_admin_chat_response_selected(self):
self.assertEquals(c2.response.moderated, True)
self.assertEquals(c2.response.author, self.admin_user)
# because we are posting to the same chat group only one reply is made
self.assertEquals(c1.response.id, c2.response.id)
self.assertEquals(c1.response.id, c2.response.id)

def admin_page_test_helper(self, c, page):
resp = c.get(page)
self.assertEquals(resp.status_code, 200)

def test_auth_admin_pages_render(self):
c = Client()
c.login(username=self.admin_user.username, password=self.admin_user_password)

self.admin_page_test_helper(c, "/admin/")

self.admin_page_test_helper(c, "/admin/auth/")
self.admin_page_test_helper(c, "/admin/auth/coursemanager/")
self.admin_page_test_helper(c, "/admin/auth/coursementor/")
self.admin_page_test_helper(c, "/admin/auth/group/")
self.admin_page_test_helper(c, "/admin/auth/learnerview/")
self.admin_page_test_helper(c, "/admin/auth/teacher/")
self.admin_page_test_helper(c, "/admin/auth/schoolmanager/")
self.admin_page_test_helper(c, "/admin/auth/systemadministrator/")

def test_communication_admin_pages_render(self):
c = Client()
c.login(username=self.admin_user.username, password=self.admin_user_password)

self.admin_page_test_helper(c, "/admin/communication/")
self.admin_page_test_helper(c, "/admin/communication/ban/")
self.admin_page_test_helper(c, "/admin/communication/chatgroup/")
self.admin_page_test_helper(c, "/admin/communication/chatmessage/")
self.admin_page_test_helper(c, "/admin/communication/discussion/")
self.admin_page_test_helper(c, "/admin/communication/message/")
self.admin_page_test_helper(c, "/admin/communication/moderation/")
self.admin_page_test_helper(c, "/admin/communication/postcomment/")
self.admin_page_test_helper(c, "/admin/communication/post/")
self.admin_page_test_helper(c, "/admin/communication/smsqueue/")
self.admin_page_test_helper(c, "/admin/communication/reportresponse/")
self.admin_page_test_helper(c, "/admin/communication/report/")
self.admin_page_test_helper(c, "/admin/communication/sms/")

def test_content_admin_pages_render(self):
c = Client()
c.login(username=self.admin_user.username, password=self.admin_user_password)

self.admin_page_test_helper(c, "/admin/content/")
self.admin_page_test_helper(c, "/admin/content/learningchapter/")
self.admin_page_test_helper(c, "/admin/content/mathml/")
self.admin_page_test_helper(c, "/admin/content/testingquestionoption/")
self.admin_page_test_helper(c, "/admin/content/testingquestion/")

def test_core_admin_pages_render(self):
c = Client()
c.login(username=self.admin_user.username, password=self.admin_user_password)

self.admin_page_test_helper(c, "/admin/core/")
self.admin_page_test_helper(c, "/admin/core/class/")
self.admin_page_test_helper(c, "/admin/core/participantquestionanswer/")
self.admin_page_test_helper(c, "/admin/core/participant/")

def test_gamification_admin_pages_render(self):
c = Client()
c.login(username=self.admin_user.username, password=self.admin_user_password)

self.admin_page_test_helper(c, "/admin/gamification/")
self.admin_page_test_helper(c, "/admin/gamification/gamificationbadgetemplate/")
self.admin_page_test_helper(c, "/admin/gamification/gamificationpointbonus/")
self.admin_page_test_helper(c, "/admin/gamification/gamificationscenario/")

def test_organisation_admin_pages_render(self):
c = Client()
c.login(username=self.admin_user.username, password=self.admin_user_password)

self.admin_page_test_helper(c, "/admin/organisation/")
self.admin_page_test_helper(c, "/admin/organisation/course/")
self.admin_page_test_helper(c, "/admin/organisation/module/")
self.admin_page_test_helper(c, "/admin/organisation/organisation/")
self.admin_page_test_helper(c, "/admin/organisation/school/")
11 changes: 3 additions & 8 deletions oneplus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2134,16 +2134,14 @@ def post():
state['valid'] = False
state['valid_message'].append("Last Name")

if "contact" in request.POST.keys() and len(
request.POST["contact"]) >= 3:
if "contact" in request.POST.keys() and len(request.POST["contact"]) >= 3:
_contact = request.POST["contact"]
state['contact'] = _contact
else:
state['valid'] = False
state['valid_message'].append("Mobile number or Email")

if "comment" in request.POST.keys() and len(
request.POST["comment"]) >= 3:
if "comment" in request.POST.keys() and len(request.POST["comment"]) >= 3:
_comment = request.POST["comment"]
state['comment'] = _comment
else:
Expand Down Expand Up @@ -3146,10 +3144,7 @@ def get_classes(request, course):
try:
course = int(course)
current_course = Course.objects.get(id=course)
if current_course:
classes = Class.objects.all().filter(course=current_course)
else:
classes = None
classes = Class.objects.all().filter(course=current_course)
except (ValueError, Course.DoesNotExist):
classes = None

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ requests_testadapter
mock
xlwt
python-dateutil
coverage

0 comments on commit 194f1f1

Please sign in to comment.