Skip to content

Commit

Permalink
Fixed error due to Django Guardian middleware having an AnynomousUser…
Browse files Browse the repository at this point in the history
… injected into User.object.all()
  • Loading branch information
myth committed Jan 28, 2015
1 parent 45c04e5 commit 3d85cbb
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions apps/feedback/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

class SimpleTest(TestCase):

#Feedback mail
#Feedback mail
def setUp(self):

self.logger = logging.getLogger()

#Setup users
Expand All @@ -37,29 +38,29 @@ def setUp(self):

self.user1.set_password("Herpaderp123")
self.user1.save()

def yesterday(self):
return timezone.now() - timedelta(days=1)

def tomorow(self):
return timezone.now() + timedelta(days=1)


def create_feedback_relation(self, end_date=False, event_type=2,
def create_feedback_relation(self, end_date=False, event_type=2,
feedback=None, deadline= False):
if not end_date:
end_date = self.yesterday()

if not deadline:
deadline = timezone.now().date() + timedelta(days=4)
event = Event.objects.create(title="-", event_start = self.yesterday(),

event = Event.objects.create(title="-", event_start = self.yesterday(),
event_end = end_date, event_type = event_type, author = self.user1)

attendance_event = AttendanceEvent.objects.create(registration_start = timezone.now(),
unattend_deadline = timezone.now(),
registration_end = timezone.now(),
event = event,
attendance_event = AttendanceEvent.objects.create(registration_start = timezone.now(),
unattend_deadline = timezone.now(),
registration_end = timezone.now(),
event = event,
max_capacity=30)

feedback = Feedback.objects.create(author = self.user1)
Expand All @@ -78,7 +79,9 @@ def create_void_feedback_relation(self):

def test_users_mail_addresses(self):
feedback_relation = self.create_feedback_relation()
user_mails = [user.email for user in User.objects.all()]

# The below if user.id check is due to Django Guardian middleware needing an AnonymousUser, that has ID -1
user_mails = [user.email for user in User.objects.all() if user.id >= 0]

message = FeedbackMail.generate_message(feedback_relation, self.logger)
self.assertEqual(set(message.attended_mails), set(user_mails))
Expand Down Expand Up @@ -144,13 +147,13 @@ def test_no_message(self):

self.assertEqual(message.status, "No message generated")
self.assertFalse(message.send)

def test_committee_mails(self):
#Sosialt
feedback_relation = self.create_feedback_relation(event_type=1)
email = FeedbackMail.get_committee_email(feedback_relation)
self.assertEqual(email, settings.EMAIL_ARRKOM)

#Bedkom
feedback_relation = self.create_feedback_relation(event_type=2)
email = FeedbackMail.get_committee_email(feedback_relation)
Expand All @@ -160,7 +163,7 @@ def test_committee_mails(self):
feedback_relation = self.create_feedback_relation(event_type=3)
email = FeedbackMail.get_committee_email(feedback_relation)
self.assertEqual(email, settings.EMAIL_FAGKOM)

#Utflukt
feedback_relation = self.create_feedback_relation(event_type=4)
email = FeedbackMail.get_committee_email(feedback_relation)
Expand All @@ -170,17 +173,17 @@ def test_committee_mails(self):
feedback_relation = self.create_feedback_relation(event_type=5)
email = FeedbackMail.get_committee_email(feedback_relation)
self.assertEqual(email, settings.EMAIL_EKSKOM)

#Default
feedback_relation = self.create_feedback_relation(event_type=6)
email = FeedbackMail.get_committee_email(feedback_relation)
self.assertEqual(email, settings.DEFAULT_FROM_EMAIL)

#Not existing
feedback_relation = self.create_void_feedback_relation()
email = FeedbackMail.get_committee_email(feedback_relation)
self.assertEqual(email, "missing mail")

def test_date(self):
feedback_relation = self.create_feedback_relation()
date = FeedbackMail.end_date(feedback_relation)
Expand Down

0 comments on commit 3d85cbb

Please sign in to comment.