Exemplo n.º 1
0
    def test_membership_number_custom(self):
        new_member = Member(name="Member two", email="*****@*****.**")
        new_member.number = "Orange squash"
        new_member.save()

        new_member = Member.objects.get(id=new_member.pk)
        self.assertEqual(new_member.number, "Orange squash")
Exemplo n.º 2
0
    def test_membership_number_custom(self):
        new_member = Member(name="Member two", email="*****@*****.**")
        new_member.number = "Orange squash"
        new_member.save()

        new_member = Member.objects.get(id=new_member.pk)
        self.assertEqual(new_member.number, "Orange squash")
Exemplo n.º 3
0
    def test_membership_number_exists(self):
        old_member = Member.objects.get(id=1)
        old_member.number = "2"
        old_member.save()

        new_member = Member(name="Member two", email="*****@*****.**")
        new_member.save()
        self.assertEqual("100002", new_member.number)
Exemplo n.º 4
0
    def test_membership_number_exists(self):
        old_member = Member.objects.get(id=1)
        old_member.number = "2"
        old_member.save()

        new_member = Member(name="Member two", email="*****@*****.**")
        new_member.save()
        self.assertEqual("100002", new_member.number)
Exemplo n.º 5
0
    def setUp(self):
        self.useFixture(ToolkitUsersFixture())

        self.url = reverse("mailout-test-send")

        self.member = Member(name="Member One",
                             email="*****@*****.**",
                             number="1",
                             postcode="BS1 1AA")
        self.member.save()
        # Log in:
        self.client.login(username="******", password="******")

        self.send_patch = patch("toolkit.members.tasks.send_mailout_to")
        self.send_mock = self.send_patch.start()
Exemplo n.º 6
0
def add_member(request):
    # If this view is called with GET then display the form to enter a new
    # member. If called with POST then take parameters out of the body of
    # the request and create a new member
    if request.method == 'POST':
        # Create new member object
        instance = Member()
        # Create form object to process the submitted data (data is pulled
        # out of the request.POST automatically)
        form = NewMemberForm(request.POST, instance=instance)
        # Validate form fields
        if form.is_valid():
            # Form is valid, save data:
            logger.info(u"Adding member '{0} <{1}>'".format(
                instance.name, instance.email))
            member = form.save(commit=False)
            member.gdpr_opt_in = timezone.now()
            member.save()
            # Member added ok, new blank form:
            form = NewMemberForm()
            messages.add_message(request, messages.SUCCESS,
                                 u"Added member: {0}".format(instance.number))
            return HttpResponseRedirect(reverse("add-member"))
    elif request.method == 'GET':
        # GET request; create form object with default values
        form = NewMemberForm()

    context = {
        'form': form,
    }
    return render(request, 'form_new_member.html', context)
Exemplo n.º 7
0
    def test_membership_number_exists_twice(self):
        old_member = Member.objects.get(id=1)
        old_member.number = "3"
        old_member.save()

        new_member_one = Member(name="Member two", email="*****@*****.**")
        new_member_one.save()
        new_member_one.number = "100003"
        new_member_one.save()

        new_member_two = Member(name="Member two", email="*****@*****.**")
        new_member_two.save()
        self.assertEqual("200003", new_member_two.number)
Exemplo n.º 8
0
    def test_default_expiry_expiry_disabled(self):
        new_member = Member(name="New Member")
        new_member.save()

        new_member.refresh_from_db()
        self.assertIsNone(new_member.membership_expires)
        self.assertFalse(new_member.has_expired())
Exemplo n.º 9
0
    def test_default_expiry_expiry_disabled(self):
        new_member = Member(name="New Member")
        new_member.save()

        new_member.refresh_from_db()
        self.assertIsNone(new_member.membership_expires)
        self.assertFalse(new_member.has_expired())
Exemplo n.º 10
0
    def test_default_expiry_expiry_enabled(self, now_mock):
        now_mock.return_value.date.return_value = \
            datetime.date(day=1, month=1, year=2000)

        new_member = Member(name="New Member")
        new_member.save()

        new_member.refresh_from_db()
        self.assertEqual(new_member.membership_expires,
                         datetime.date(2000, 4, 10))
        self.assertFalse(new_member.has_expired())
Exemplo n.º 11
0
    def setUp(self):
        self.useFixture(ToolkitUsersFixture())

        self.url = reverse("mailout-test-send")

        self.member = Member(name="Member One", email="*****@*****.**",
                             number="1", postcode="BS1 1AA")
        self.member.save()
        # Log in:
        self.client.login(username="******", password="******")

        self.send_patch = patch("toolkit.members.tasks.send_mailout_to")
        self.send_mock = self.send_patch.start()
Exemplo n.º 12
0
    def test_default_expiry_expiry_enabled(self, now_mock):
        now_mock.return_value.date.return_value = \
            datetime.date(day=1, month=1, year=2000)

        new_member = Member(name="New Member")
        new_member.save()

        new_member.refresh_from_db()
        self.assertEqual(new_member.membership_expires,
                         datetime.date(2000, 4, 10))
        self.assertFalse(new_member.has_expired())
Exemplo n.º 13
0
def edit_volunteer(request, volunteer_id, create_new=False):
    # If called from the "add" url, then create_new will be True. If called
    # from the edit url then it'll be False

    # Depending on which way this method was called, either create a totally
    # new volunteer object with default values (add) or load the volunteer
    # object with the given volunteer_id from the database:
    if not create_new:
        # Called from "edit" url
        volunteer = get_object_or_404(Volunteer, id=volunteer_id)
        member = volunteer.member
        new_training_record = TrainingRecord(volunteer=volunteer)
    else:
        # Called from "add" url
        volunteer = Volunteer()
        member = Member()
        volunteer.member = Member()
        new_training_record = None

    # Now, if the view was loaded with "GET" then display the edit form, and
    # if it was called with POST then read the updated volunteer data from the
    # form data and update and save the volunteer object:
    if request.method == 'POST':
        # Three forms, one for each set of data
        vol_form = VolunteerForm(
            request.POST,
            request.FILES,
            instance=volunteer
        )
        mem_form = MemberFormWithoutNotes(
            request.POST,
            instance=member
        )
        if vol_form.is_valid() and mem_form.is_valid():
            member = mem_form.save(commit=False)
            member.gdpr_opt_in = timezone.now()
            member.save()
            volunteer.member = member
            vol_form.save()

            logger.info(u"Saving changes to volunteer '{0}' (id: {1})".format(
                volunteer.member.name, str(volunteer.pk)))

            messages.add_message(
                request,
                messages.SUCCESS,
                u"{0} volunteer '{1}'".format(
                    u"Created" if create_new else u"Updated", member.name
                )
            )

            if create_new:
                # Email admin
                admin_body = (
                    u"I'm delighted to inform you that %s has just added "
                    u"new volunteer\n\n"
                    u"%s <%s>\n\n"
                    u"to the toolkit.\n\n"
                    u"Please add them to the volunteers mailing list "
                    u"at your earliest convenience." % (
                        request.user.last_name,
                        volunteer.member.name,
                        volunteer.member.email)
                )
                send_mail(
                     ('[%s] New volunteer %s' %
                         (settings.VENUE['longname'],
                          volunteer.member.name)),
                     admin_body,
                     settings.VENUE['mailout_from_address'],
                     settings.VENUE['vols_admin_address'],
                     fail_silently=False,
                )
            # Go to the volunteer list view:
            return HttpResponseRedirect(reverse("view-volunteer-summary"))
    else:
        vol_form = VolunteerForm(instance=volunteer)
        mem_form = MemberFormWithoutNotes(instance=volunteer.member)

    if new_training_record:
        training_record_form = TrainingRecordForm(
           prefix="training", instance=new_training_record)
    else:
        training_record_form = None

    context = {
        'pagetitle': 'Add Volunteer' if create_new else 'Edit Volunteer',
        'default_mugshot': settings.DEFAULT_MUGSHOT,
        'volunteer': volunteer,
        'vol_form': vol_form,
        'mem_form': mem_form,
        'training_record_form': training_record_form,
        'dawn_of_toolkit': settings.DAWN_OF_TOOLKIT,
    }
    return render(request, 'form_volunteer.html', context)
Exemplo n.º 14
0
class MailoutTestSendViewTests(TestCase, fixtures.TestWithFixtures):
    def setUp(self):
        self.useFixture(ToolkitUsersFixture())

        self.url = reverse("mailout-test-send")

        self.member = Member(name="Member One",
                             email="*****@*****.**",
                             number="1",
                             postcode="BS1 1AA")
        self.member.save()
        # Log in:
        self.client.login(username="******", password="******")

        self.send_patch = patch("toolkit.members.tasks.send_mailout_to")
        self.send_mock = self.send_patch.start()

    def tearDown(self):
        self.send_patch.stop()

    def test_no_get(self):
        response = self.client.get(self.url)
        # 405 Method Not Allowed
        self.assertEqual(response.status_code, 405)

    @override_settings(HTML_MAILOUT_ENABLED=False)
    @patch("toolkit.diary.mailout_views.Member")
    def test_success_html_disabled(self, member_mock):
        self.send_mock.return_value = (False, 1, None)
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'address': u"*****@*****.**",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': None,
        })
        self.send_mock.assert_called_once_with(
            u"Yet another member's mailout",
            u"Let the bodies hit the floor\netc.", None,
            member_mock.objects.filter.return_value.__getitem__.return_value)

    @override_settings(HTML_MAILOUT_ENABLED=True)
    @patch("toolkit.diary.mailout_views.Member")
    def test_success_html_enabled(self, member_mock):
        self.send_mock.return_value = (False, 1, None)
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'body_html': u"<h1>My HTML email</h1>",
                                        'send_html': u"true",
                                        'address': u"*****@*****.**",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': None,
        })
        self.send_mock.assert_called_once_with(
            u"Yet another member's mailout",
            u"Let the bodies hit the floor\netc.", u"<h1>My HTML email</h1>",
            member_mock.objects.filter.return_value.__getitem__.return_value)

    @override_settings(HTML_MAILOUT_ENABLED=True)
    @patch("toolkit.diary.mailout_views.Member")
    def test_success_html_enabled_do_not_send_html(self, member_mock):
        self.send_mock.return_value = (False, 1, None)
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'body_html': u"<h1>My HTML email</h1>",
                                        'send_html': u"false",
                                        'address': u"*****@*****.**",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': None,
        })
        self.send_mock.assert_called_once_with(
            u"Yet another member's mailout",
            u"Let the bodies hit the floor\netc.", None,
            member_mock.objects.filter.return_value.__getitem__.return_value)

    @override_settings(HTML_MAILOUT_ENABLED=True)
    def test_missing_html(self):
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'address': u"*****@*****.**",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(
            response.content.decode("utf-8"), {
                u'errors': u'body_html: '
                u'<ul class="errorlist"><li>This field is required.</li></ul>',
                u'status': u'error'
            })
        self.send_mock.assert_not_called()

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_success_with_message(self):
        self.send_mock.return_value = (False, 1, "Message of success")
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'address': u"*****@*****.**",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': "Message of success",
        })

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_failed_send(self):
        self.send_mock.return_value = (True, None, u"Failed for some reason")
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'address': u"*****@*****.**",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'error',
            'errors': 'Failed for some reason',
        })

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_no_member(self):
        self.send_mock.return_value = (False, None, None)
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'address': u"*****@*****.**",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(
            response.content.decode("utf-8"), {
                'status': 'error',
                'errors': 'No member found with given email address',
            })

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_bad_email(self):
        self.send_mock.return_value = (False, None, None)
        response = self.client.post(self.url,
                                    data={
                                        'subject':
                                        u"Yet another member's mailout",
                                        'body_text':
                                        u"Let the bodies hit the floor\netc.",
                                        'address': u"dodgy",
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(
            response.content.decode("utf-8"), {
                'status':
                'error',
                'errors':
                u'address: <ul class="errorlist"><li>'
                u'Enter a valid email address.</li></ul>'
            })
Exemplo n.º 15
0
    def test_membership_number_exists_twice(self):
        old_member = Member.objects.get(id=1)
        old_member.number = "3"
        old_member.save()

        new_member_one = Member(name="Member two", email="*****@*****.**")
        new_member_one.save()
        new_member_one.number = "100003"
        new_member_one.save()

        new_member_two = Member(name="Member two", email="*****@*****.**")
        new_member_two.save()
        self.assertEqual("200003", new_member_two.number)
Exemplo n.º 16
0
def edit_volunteer(request, volunteer_id, create_new=False):
    # If called from the "add" url, then create_new will be True. If called
    # from the edit url then it'll be False

    # Depending on which way this method was called, either create a totally
    # new volunteer object with default values (add) or load the volunteer
    # object with the given volunteer_id from the database:
    if not create_new:
        # Called from "edit" url
        volunteer = get_object_or_404(Volunteer, id=volunteer_id)
        member = volunteer.member
        new_training_record = TrainingRecord(volunteer=volunteer)
    else:
        # Called from "add" url
        volunteer = Volunteer()
        member = Member()
        volunteer.member = Member()
        new_training_record = None

    # Now, if the view was loaded with "GET" then display the edit form, and
    # if it was called with POST then read the updated volunteer data from the
    # form data and update and save the volunteer object:
    if request.method == 'POST':
        # Three forms, one for each set of data
        vol_form = VolunteerForm(request.POST,
                                 request.FILES,
                                 instance=volunteer)
        mem_form = MemberFormWithoutNotes(request.POST, instance=member)
        if vol_form.is_valid() and mem_form.is_valid():
            logger.info(u"Saving changes to volunteer '{0}' (id: {1})".format(
                volunteer.member.name, str(volunteer.pk)))
            member = mem_form.save(commit=False)
            member.gdpr_opt_in = timezone.now()
            member.save()
            volunteer.member = member
            vol_form.save()
            messages.add_message(
                request, messages.SUCCESS, u"{0} volunteer '{1}'".format(
                    u"Created" if create_new else u"Updated", member.name))
            # Go to the volunteer list view:
            return HttpResponseRedirect(reverse("view-volunteer-list"))
    else:
        vol_form = VolunteerForm(instance=volunteer)
        mem_form = MemberFormWithoutNotes(instance=volunteer.member)

    if new_training_record:
        training_record_form = TrainingRecordForm(prefix="training",
                                                  instance=new_training_record)
    else:
        training_record_form = None

    context = {
        'pagetitle': 'Add Volunteer' if create_new else 'Edit Volunteer',
        'default_mugshot': settings.DEFAULT_MUGSHOT,
        'volunteer': volunteer,
        'vol_form': vol_form,
        'mem_form': mem_form,
        'training_record_form': training_record_form,
        'dawn_of_toolkit': settings.DAWN_OF_TOOLKIT,
    }
    return render(request, 'form_volunteer.html', context)
Exemplo n.º 17
0
 def test_membership_number_no_existing(self):
     new_member = Member(name="Member two", email="*****@*****.**")
     new_member.save()
     self.assertEqual(str(new_member.pk), new_member.number)
Exemplo n.º 18
0
class MembersTestsMixin(object):

    def setUp(self):
        self._setup_test_data()
        self._setup_test_users()

        return super(MembersTestsMixin, self).setUp()

    def _setup_test_data(self):
        # Roles:
        r1 = Role(name="Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name="Role 2 (nonstandard)", read_only=False, standard=False)
        r2.save()
        r3 = Role(name="Role 3", read_only=False, standard=False)
        r3.save()

        # Members:
        self.mem_1 = Member(name=u"Member On\u0205",
                            email="*****@*****.**", number="1",
                            postcode="BS1 1AA")
        self.mem_1.save()
        self.mem_2 = Member(name=u"Tw\u020d Member",
                            email="*****@*****.**", number="02",
                            postcode="",
                            membership_expires=date(day=31, month=5, year=2010)
                            )
        self.mem_2.save()
        self.mem_3 = Member(name=u"Some Third Chap",
                            email="*****@*****.**", number="000",
                            postcode="NORAD",
                            membership_expires=date(day=1, month=6, year=2010))
        self.mem_3.save()
        self.mem_4 = Member(name="Volunteer One", email="*****@*****.**",
                            number="3", phone="0800 000 000", address="1 Road",
                            posttown="Town of towns", postcode="BS6 123",
                            country="UKountry", website="http://1.foo.test/")
        self.mem_4.save()
        self.mem_5 = Member(name="Volunteer Two", email="", number="4",
                            phone="", altphone="", address="", posttown="",
                            postcode="", country="",
                            website="http://two.foo.test/")
        self.mem_5.save()
        self.mem_6 = Member(name="Volunteer Three", email="*****@*****.**",
                            number="4", phone="", altphone="", address="",
                            posttown="", postcode="", country="", website="")
        self.mem_6.save()
        self.mem_7 = Member(name="Volunteer Four", email="*****@*****.**",
                            number="o4", phone="", altphone="", address="",
                            posttown="", postcode="", country="", website="")
        self.mem_7.save()
        self.mem_8 = Member(name=u"Number Eight, No mailout please",
                            email="*****@*****.**", number="010",
                            mailout=False)
        self.mem_8.save()
        self.mem_8 = Member(name=u"Number Nine, mailout failed",
                            email="*****@*****.**", number="010",
                            mailout_failed=True)
        self.mem_8.save()

        # Volunteers:
        self.vol_1 = Volunteer(
            member=self.mem_4, notes=u'Likes the $, the \u00a3 and the \u20ac',
            portrait=settings.MEDIA_ROOT + "/path/to/portrait"
        )
        self.vol_1.save()
        self.vol_1.roles.set([r1, r3])
        self.vol_1.save()

        self.vol_2 = Volunteer(member=self.mem_5)
        self.vol_2.save()

        self.vol_3 = Volunteer(member=self.mem_6)
        self.vol_3.save()
        self.vol_3.roles.set([r3])
        self.vol_3.save()

        self.vol_4 = Volunteer(
            member=self.mem_7, active=False,
            notes=u"Subliminal, superluminous")
        self.vol_4.save()
        self.vol_4.roles.set([r3])
        self.vol_4.save()

    def _setup_test_users(self):
        # Read/write user:
        user_rw = auth_models.User.objects.create_user(
            'admin', 'toolkit_admin@localhost', 'T3stPassword!')
        # read only user:
        user_r = auth_models.User.objects.create_user(
            'read_only', 'toolkit_admin@localhost', 'T3stPassword!1')
        # no permission user:
        auth_models.User.objects.create_user(
            'no_perm', 'toolkit_admin@localhost', 'T3stPassword!2')
        # Create dummy ContentType:
        ct = contenttypes.models.ContentType.objects.get_or_create(
            model='',
            app_label='toolkit'
        )[0]
        # Create 'read' and 'write' permissions:
        write_permission = auth_models.Permission.objects.get_or_create(
            name='Write access to all toolkit content',
            content_type=ct,
            codename='write'
        )[0]

        read_permission = auth_models.Permission.objects.get_or_create(
            name='Read access to all toolkit content',
            content_type=ct,
            codename='read'
        )[0]
        # Set user permissions, r/w:
        user_rw.user_permissions.add(write_permission)
        user_rw.user_permissions.add(read_permission)
        # read only:
        user_r.user_permissions.add(read_permission)
Exemplo n.º 19
0
    def _setup_test_data(self):
        # Roles:
        r1 = Role(name="Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name="Role 2 (nonstandard)", read_only=False, standard=False)
        r2.save()
        r3 = Role(name="Role 3", read_only=False, standard=False)
        r3.save()

        # Members:
        self.mem_1 = Member(name=u"Member On\u0205",
                            email="*****@*****.**", number="1",
                            postcode="BS1 1AA")
        self.mem_1.save()
        self.mem_2 = Member(name=u"Tw\u020d Member",
                            email="*****@*****.**", number="02",
                            postcode="",
                            membership_expires=date(day=31, month=5, year=2010)
                            )
        self.mem_2.save()
        self.mem_3 = Member(name=u"Some Third Chap",
                            email="*****@*****.**", number="000",
                            postcode="NORAD",
                            membership_expires=date(day=1, month=6, year=2010))
        self.mem_3.save()
        self.mem_4 = Member(name="Volunteer One", email="*****@*****.**",
                            number="3", phone="0800 000 000", address="1 Road",
                            posttown="Town of towns", postcode="BS6 123",
                            country="UKountry", website="http://1.foo.test/")
        self.mem_4.save()
        self.mem_5 = Member(name="Volunteer Two", email="", number="4",
                            phone="", altphone="", address="", posttown="",
                            postcode="", country="",
                            website="http://two.foo.test/")
        self.mem_5.save()
        self.mem_6 = Member(name="Volunteer Three", email="*****@*****.**",
                            number="4", phone="", altphone="", address="",
                            posttown="", postcode="", country="", website="")
        self.mem_6.save()
        self.mem_7 = Member(name="Volunteer Four", email="*****@*****.**",
                            number="o4", phone="", altphone="", address="",
                            posttown="", postcode="", country="", website="")
        self.mem_7.save()
        self.mem_8 = Member(name=u"Number Eight, No mailout please",
                            email="*****@*****.**", number="010",
                            mailout=False)
        self.mem_8.save()
        self.mem_8 = Member(name=u"Number Nine, mailout failed",
                            email="*****@*****.**", number="010",
                            mailout_failed=True)
        self.mem_8.save()

        # Volunteers:
        self.vol_1 = Volunteer(
            member=self.mem_4, notes=u'Likes the $, the \u00a3 and the \u20ac',
            portrait=settings.MEDIA_ROOT + "/path/to/portrait"
        )
        self.vol_1.save()
        self.vol_1.roles.set([r1, r3])
        self.vol_1.save()

        self.vol_2 = Volunteer(member=self.mem_5)
        self.vol_2.save()

        self.vol_3 = Volunteer(member=self.mem_6)
        self.vol_3.save()
        self.vol_3.roles.set([r3])
        self.vol_3.save()

        self.vol_4 = Volunteer(
            member=self.mem_7, active=False,
            notes=u"Subliminal, superluminous")
        self.vol_4.save()
        self.vol_4.roles.set([r3])
        self.vol_4.save()
Exemplo n.º 20
0
class MembersTestsMixin(object):
    def setUp(self):
        self._setup_test_data()
        self._setup_test_users()

        return super(MembersTestsMixin, self).setUp()

    def _setup_test_data(self):
        # Roles:
        r1 = Role(name="Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name="Role 2 (nonstandard)", read_only=False, standard=False)
        r2.save()
        r3 = Role(name="Role 3", read_only=False, standard=False)
        r3.save()

        # Members:
        self.mem_1 = Member(name=u"Member On\u0205",
                            email="*****@*****.**",
                            number="1",
                            postcode="BS1 1AA")
        self.mem_1.save()
        self.mem_2 = Member(name=u"Tw\u020d Member",
                            email="*****@*****.**",
                            number="02",
                            postcode="",
                            membership_expires=date(day=31, month=5,
                                                    year=2010))
        self.mem_2.save()
        self.mem_3 = Member(name=u"Some Third Chap",
                            email="*****@*****.**",
                            number="000",
                            postcode="NORAD",
                            membership_expires=date(day=1, month=6, year=2010))
        self.mem_3.save()
        self.mem_4 = Member(name="Volunteer One",
                            email="*****@*****.**",
                            number="3",
                            phone="0800 000 000",
                            address="1 Road",
                            posttown="Town of towns",
                            postcode="BS6 123",
                            country="UKountry",
                            website="http://1.foo.test/")
        self.mem_4.save()
        self.mem_5 = Member(name="Volunteer Two",
                            email="",
                            number="4",
                            phone="",
                            altphone="",
                            address="",
                            posttown="",
                            postcode="",
                            country="",
                            website="http://two.foo.test/")
        self.mem_5.save()
        self.mem_6 = Member(name="Volunteer Three",
                            email="*****@*****.**",
                            number="4",
                            phone="",
                            altphone="",
                            address="",
                            posttown="",
                            postcode="",
                            country="",
                            website="")
        self.mem_6.save()
        self.mem_7 = Member(name="Volunteer Four",
                            email="*****@*****.**",
                            number="o4",
                            phone="",
                            altphone="",
                            address="",
                            posttown="",
                            postcode="",
                            country="",
                            website="")
        self.mem_7.save()
        self.mem_8 = Member(name=u"Number Eight, No mailout please",
                            email="*****@*****.**",
                            number="010",
                            mailout=False)
        self.mem_8.save()
        self.mem_8 = Member(name=u"Number Nine, mailout failed",
                            email="*****@*****.**",
                            number="010",
                            mailout_failed=True)
        self.mem_8.save()

        # Volunteers:
        self.vol_1 = Volunteer(member=self.mem_4,
                               notes=u'Likes the $, the \u00a3 and the \u20ac',
                               portrait=settings.MEDIA_ROOT +
                               "/path/to/portrait")
        self.vol_1.save()
        self.vol_1.roles.set([r1, r3])
        self.vol_1.save()

        self.vol_2 = Volunteer(member=self.mem_5)
        self.vol_2.save()

        self.vol_3 = Volunteer(member=self.mem_6)
        self.vol_3.save()
        self.vol_3.roles.set([r3])
        self.vol_3.save()

        self.vol_4 = Volunteer(member=self.mem_7,
                               active=False,
                               notes=u"Subliminal, superluminous")
        self.vol_4.save()
        self.vol_4.roles.set([r3])
        self.vol_4.save()

    def _setup_test_users(self):
        # Read/write user:
        user_rw = auth_models.User.objects.create_user(
            'admin', 'toolkit_admin@localhost', 'T3stPassword!')
        # read only user:
        user_r = auth_models.User.objects.create_user(
            'read_only', 'toolkit_admin@localhost', 'T3stPassword!1')
        # no permission user:
        auth_models.User.objects.create_user('no_perm',
                                             'toolkit_admin@localhost',
                                             'T3stPassword!2')
        # Create dummy ContentType:
        ct = contenttypes.models.ContentType.objects.get_or_create(
            model='', app_label='toolkit')[0]
        # Create 'read' and 'write' permissions:
        write_permission = auth_models.Permission.objects.get_or_create(
            name='Write access to all toolkit content',
            content_type=ct,
            codename='write')[0]

        read_permission = auth_models.Permission.objects.get_or_create(
            name='Read access to all toolkit content',
            content_type=ct,
            codename='read')[0]
        # Set user permissions, r/w:
        user_rw.user_permissions.add(write_permission)
        user_rw.user_permissions.add(read_permission)
        # read only:
        user_r.user_permissions.add(read_permission)
Exemplo n.º 21
0
    def _setup_test_data(self):

        self._fake_now = pytz.timezone("Europe/London").localize(datetime(2013, 6, 1, 11, 00))

        # Roles:
        r1 = Role(name=u"Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name=u"Role 2 (nonstandard)", read_only=False, standard=False)
        r2.save()
        r3 = Role(name=u"Role 3", read_only=False, standard=False)
        r3.save()

        # Tags:
        t1 = EventTag(name=u"tag one", slug=u"tag-one", read_only=False)
        t1.save()
        t2 = EventTag(name=u"tag two", slug=u"tag-two", read_only=False)
        t2.save()
        # 'ag-three' is what slugify() gives for that name:
        t3 = EventTag(name=u"\u0167ag \u0165hre\u0119", slug=u"ag-three", read_only=False)
        t3.save()

        """
        Event  outside_hire   private   Tags
        ---------------------------------------
        e1     True           False
        e2     False          False
        e3     False          False    t2
        e4     False          False    t2
        e5     False          True
        e6     True           True     t3

        Showing  Event  Date    Confirmed  Hidden  Cancelled  Discount|E: outside  private
        --------------------------------------------------------------|-------------------
        e2s1       e2    1/4/13   F          F       F          F     |   F        F
        e2s2       e2    2/4/13   T          F       F          F     |   F        F
        e2s3       e2    3/4/13   T          F       T          F     |   F        F
        e2s4       e2    4/4/13   T          T       F          F     |   F        F
        e2s5       e2    5/4/13   T          T       T          F     |   F        F

        s2       e3    13/4/13  T          F       F          F       |   F        F
        s3       e4    9/6/13   T          F       F          F       |   F        F
        s4       e4    14/9/13  F          F       F          F       |   F        F
        s5       e5    14/2/13  T          F       F          F       |   F        T
        s6       e1    15/2/13  T          T       F          F       |   F        F
        """

        # Events:
        e1 = Event(
            name="Event one title",
            copy="Event one copy",
            copy_summary="Event one copy summary",
            duration="01:30:00",
            outside_hire=True,
        )
        e1.save()

        e2 = Event(
            name="Event two title",
            copy="Event\n two\n copy",  # newlines will be stripped at legacy conversion
            copy_summary="Event two\n copy summary",
            duration="01:30:00",
            legacy_id="100",
            legacy_copy=True,
        )
        e2.save()

        e3 = Event(
            name="Event three title",
            copy="Event three Copy",
            copy_summary="Copy three summary",
            duration="03:00:00",
            notes="Notes",
        )
        e3.save()
        e3.tags = [t2, ]
        e3.save()

        e4 = Event(
            name=u"Event four titl\u0113",
            copy=u"Event four C\u014dpy",
            copy_summary=u"\u010copy four summary",
            terms=u"Terminal price: \u00a31 / \u20ac3",
            duration="01:00:00",
            notes="\u0147otes on event fou\u0159",
        )
        e4.save()
        e4.tags = [t2, ]
        e4.save()

        e5 = Event(
            name=u"PRIVATE Event FIVE titl\u0113!",
            copy=u"PRIVATE Event 5ive C\u014dpy",
            copy_summary=u"\u010copy five summary",
            terms=u"More terms; price: \u00a32 / \u20ac5",
            duration="10:00:00",
            notes="\u0147otes on event five",
            private=True
        )
        e5.save()

        e6 = Event(
            name=u"PRIVATE OUTSIDE Event (Six)",
            copy=u"PRIVATE OUTSIDE Event 6ix copy",
            copy_summary=u"OUTSIDE PRIVATE \u010copy six summary",
            terms=u"Ever More terms; price: \u00a32 / \u20ac5",
            duration="4:00:00",
            notes="\u0147otes on private/outwide event six",
            outside_hire=True,
            private=True
        )
        e6.save()
        e6.tags = [t3, ]
        e6.save()

        # Showings:
        self.e2s1 = Showing(  # pk :1
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 1, 19, 00)),
            event=e2, booked_by="User",
            confirmed=False, hide_in_programme=False, cancelled=False, discounted=False)
        self.e2s1.save(force=True)
        self.e2s2 = Showing(  # pk :2
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 2, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=False, cancelled=False, discounted=False)
        self.e2s2.save(force=True)
        e2s3 = Showing(  # pk :3
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 3, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=False, cancelled=True, discounted=False)
        e2s3.save(force=True)
        e2s4 = Showing(  # pk :4
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 4, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=True, cancelled=False, discounted=False)
        e2s4.save(force=True)
        e2s5 = Showing(  # pk :5
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 5, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=True, cancelled=True, discounted=False)
        e2s5.save(force=True)

        s2 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 13, 18, 00)),
            event=e3,
            booked_by="User Two",
            confirmed=True
        )
        s2.save(force=True)  # Force start date in the past

        # When the clock is patched to claim that it's 1/6/2013, this showing
        # will be in the future:
        self.e4s3 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 6, 9, 18, 00)),
            event=e4,
            booked_by=u"\u0102nother \u0170ser",
            confirmed=True
        )
        self.e4s3.save(force=True)  # Force start date in the past

        s4 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 9, 14, 18, 00)),
            event=e4,
            booked_by="User Two",
            hide_in_programme=True,
            confirmed=False
        )
        s4.save(force=True)  # Force start date in the past

        s5 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 2, 14, 18, 00)),
            event=e5,
            booked_by="Yet another user",
            confirmed=True,
        )
        s5.save(force=True)

        s6 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 2, 15, 18, 00)),
            event=e1,
            booked_by="Blah blah",
            confirmed=True,
            hide_in_programme=True,
        )
        s6.save(force=True)

        # Rota items:
        RotaEntry(showing=self.e2s1, role=r2, rank=1).save()
        RotaEntry(showing=self.e2s1, role=r3, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=2).save()
        RotaEntry(showing=s2, role=r1, rank=3).save()
        RotaEntry(showing=s2, role=r1, rank=4).save()
        RotaEntry(showing=s2, role=r1, rank=5).save()
        RotaEntry(showing=s2, role=r1, rank=6).save()
        RotaEntry(showing=self.e4s3, role=r2, rank=1).save()

        # Ideas:
        i = DiaryIdea(
            ideas="April 2013 ideas",
            month=date(year=2013, month=4, day=1)
        )
        i.save()
        i = DiaryIdea(
            ideas="May 2013 ideas",
            month=date(year=2013, month=5, day=1)
        )
        i.save()

        # Templates:
        tmpl = EventTemplate(name="Template 1")
        tmpl.save()
        tmpl.roles = [r1]
        tmpl.tags = [t1]
        tmpl.save()

        tmpl = EventTemplate(name="Template 2")
        tmpl.save()
        tmpl.roles = [r2]
        tmpl.tags = [t2]
        tmpl.save()

        tmpl = EventTemplate(name="Template 3")
        tmpl.save()
        tmpl.roles = [r1, r2, r3]
        tmpl.save()

        # Members:
        m1 = Member(name="Member One", email="*****@*****.**", number="1",
                    postcode="BS1 1AA")
        m1.save()
        m2 = Member(name="Two Member", email="*****@*****.**", number="2",
                    postcode="")
        m2.save()
        m3 = Member(name="Volunteer One", email="*****@*****.**", number="3",
                    phone="0800 000 000", address="1 Road", posttown="Town",
                    postcode="BS6 123", country="UK", website="http://foo.test/")
        m3.save()
        m4 = Member(name="Volunteer Two", email="", number="4",
                    phone="", altphone="", address="", posttown="", postcode="",
                    country="", website="http://foo.test/")
        m4.save()
        m5 = Member(name="Volunteer Three", email="*****@*****.**", number="4",
                    phone="", altphone="", address="", posttown="", postcode="",
                    country="", website="")
        m5.save()

        # Volunteers:
        v1 = Volunteer(member=m3)
        v1.save()
        v1.roles = [r1, r3]
        v1.save()

        v2 = Volunteer(member=m4)
        v2.save()

        v3 = Volunteer(member=m5)
        v3.save()
        v3.roles = [r3]
        v3.save()

        # System user:
        user_rw = auth_models.User.objects.create_user('admin', 'toolkit_admin@localhost', 'T3stPassword!')
        # Create dummy ContentType:
        ct = contenttypes.models.ContentType.objects.get_or_create(
            model='',
            app_label='toolkit'
        )[0]
        # Create 'write' permission:
        write_permission = auth_models.Permission.objects.get_or_create(
            name='Write access to all toolkit content',
            content_type=ct,
            codename='write'
        )[0]
        # Give "admin" user the write permission:
        user_rw.user_permissions.add(write_permission)
Exemplo n.º 22
0
 def setUp(self):
     member_one = Member(name="Member One",
                         number="1",
                         email="*****@*****.**")
     member_one.save()
Exemplo n.º 23
0
 def setUp(self):
     member_one = Member(name="Member One", number="1",
                         email="*****@*****.**")
     member_one.save()
Exemplo n.º 24
0
 def test_membership_number_no_existing(self):
     new_member = Member(name="Member two", email="*****@*****.**")
     new_member.save()
     self.assertEqual(str(new_member.pk), new_member.number)
Exemplo n.º 25
0
    def _setup_test_data(self):

        self._fake_now = pytz.timezone(
            "Europe/London").localize(datetime(2013, 6, 1, 11, 00))

        # Roles:
        r1 = Role(name=u"Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name=u"Role 2 (nonstandard)",
                  read_only=False, standard=False)
        r2.save()
        r3 = Role(name=u"Role 3", read_only=False, standard=False)
        r3.save()

        # Tags:
        t1 = EventTag(name=u"tag one", slug=u"tag-one", read_only=False)
        t1.save()
        t2 = EventTag(name=u"tag two", slug=u"tag-two",
                      promoted=True, sort_order=2, read_only=False)
        t2.save()
        # 'ag-three' is what slugify() gives for that name:
        t3 = EventTag(name=u"tag three",
                      slug=u"tag-three", sort_order=1, promoted=True,
                      read_only=False)
        t3.save()

        Room(name="Room one", colour="#Ff0000").save()
        self.room_2 = Room(name="Room two", colour="#00abcd")
        self.room_2.save()

        # Event  outside_hire   private   Tags
        # ---------------------------------------
        # e1     True           False
        # e2     False          False
        # e3     False          False    t2
        # e4     False          False    t2
        # e5     False          True
        # e6     True           True     t3

        # Showing Event  Date    Confirmed  Hiddn  Cnclld  Dscnt|E: oside pvate
        # ------------------------------------------------------|--------------
        # e2s1    e2    1/4/13   F          F      F      F     |   F      F
        # e2s2    e2    2/4/13   T          F      F      F     |   F      F
        # e2s3    e2    3/4/13   T          F      T      F     |   F      F
        # e2s4    e2    4/4/13   T          T      F      F     |   F      F
        # e2s5    e2    5/4/13   T          T      T      F     |   F      F

        # s2      e3    13/4/13  T          F      F      F     |   F      F
        # s3      e4    9/6/13   T          F      F      F     |   F      F
        # s4      e4    14/9/13  F          F      F      F     |   F      F
        # s5      e5    14/2/13  T          F      F      F     |   F      T
        # s6      e1    15/2/13  T          T      F      F     |   F      F

        # Events:
        e1 = Event(
            name="Event one title",
            pricing="PRICING_ONE",
            copy="Event one copy",
            pre_title="PRETITLE One",
            post_title="POSTTITLE One",
            film_information="FILM_INFO_One",
            copy_summary="Event one copy summary",
            duration="01:30:00",
            outside_hire=True,
        )
        e1.save()

        self.e2 = Event(
            name="Event two title",
            # newlines will be stripped at legacy conversion:
            copy="Event\n two\n copy",
            pricing="Pricing TWO",
            copy_summary="Event two\n copy summary",
            duration="01:30:00",
            legacy_id="100",
            legacy_copy=True,
        )
        self.e2.save()

        e3 = Event(
            name="Event three title",
            pricing="Pricing THREE",
            copy="Event three Copy",
            pre_title="PRETITLE THREE",
            post_title="POSTTITLE THREE",
            film_information="FILM_INFO_THREE",
            copy_summary="Copy three summary",
            duration="03:00:00",
            notes="Notes",
        )
        e3.save()
        e3.tags.set([t2, ])
        e3.save()

        e4 = Event(
            name=u"Event four titl\u0113",
            copy=u"Event four C\u014dpy",
            pricing=u"\u00a3milliion per thing",
            pre_title=u"Pretitle four",
            post_title=u"Posttitle four",
            film_information=u"Film info for four",
            copy_summary=u"\u010copy four summary",
            terms=u"Terminal price: \u00a31 / \u20ac3",
            duration="01:00:00",
            notes=u"\u0147otes on event fou\u0159",
        )
        e4.save()
        e4.tags.set([t2, ])
        e4.save()

        e5 = Event(
            name=u"PRIVATE Event FIVE titl\u0113!",
            copy=u"PRIVATE Event 5ive C\u014dpy",
            copy_summary=u"\u010copy five summary",
            terms=u"More terms; price: \u00a32 / \u20ac5",
            duration="10:00:00",
            notes=u"\u0147otes on event five",
            private=True
        )
        e5.save()

        e6 = Event(
            name=u"PRIVATE OUTSIDE Event (Six)",
            copy=u"PRIVATE OUTSIDE Event 6ix copy",
            copy_summary=u"OUTSIDE PRIVATE \u010copy six summary",
            terms=u"Ever More terms; price: \u00a32 / \u20ac5",
            duration="4:00:00",
            notes=u"\u0147otes on private/outwide event six",
            outside_hire=True,
            private=True
        )
        e6.save()
        e6.tags.set([t3, ])
        e6.save()

        # Showings:
        self.e2s1 = Showing(  # pk :1
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 1, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=False, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s1.save(force=True)
        self.e2s2 = Showing(  # pk :2
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 2, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s2.save(force=True)
        e2s3 = Showing(  # pk :3
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 3, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=True, discounted=False)
        e2s3.save(force=True)
        e2s4 = Showing(  # pk :4
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 4, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=False, discounted=False)
        e2s4.save(force=True)
        e2s5 = Showing(  # pk :5
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 5, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=True, discounted=False)
        e2s5.save(force=True)

        s2 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 13, 18, 00)),
            event=e3,
            booked_by="User Two",
            confirmed=True
        )
        s2.save(force=True)  # Force start date in the past

        # When the clock is patched to claim that it's 1/6/2013, this showing
        # will be in the future:
        self.e4s3 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 6, 9, 18, 00)),
            event=e4,
            booked_by=u"\u0102nother \u0170ser",
            confirmed=True,
            rota_notes="Some notes about the Rota!",
        )
        self.e4s3.save(force=True)  # Force start date in the past

        s4 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 9, 14, 18, 00)),
            event=e4,
            booked_by="User Two",
            hide_in_programme=True,
            confirmed=False
        )
        s4.save(force=True)  # Force start date in the past

        s5 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 14, 18, 00)),
            event=e5,
            booked_by="Yet another user",
            confirmed=True,
        )
        s5.save(force=True)

        s6 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 15, 18, 00)),
            event=e1,
            booked_by="Blah blah",
            confirmed=True,
            hide_in_programme=True,
        )
        s6.save(force=True)

        # Rota items:
        RotaEntry(showing=self.e2s1, role=r2, rank=1).save()
        RotaEntry(showing=self.e2s1, role=r3, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=2).save()
        RotaEntry(showing=s2, role=r1, rank=3).save()
        RotaEntry(showing=s2, role=r1, rank=4).save()
        RotaEntry(showing=s2, role=r1, rank=5).save()
        RotaEntry(showing=s2, role=r1, rank=6).save()
        RotaEntry(showing=self.e4s3, role=r2, rank=1).save()

        # Ideas:
        i = DiaryIdea(
            ideas="April 2013 ideas",
            month=date(year=2013, month=4, day=1)
        )
        i.save()
        i = DiaryIdea(
            ideas="May 2013 ideas",
            month=date(year=2013, month=5, day=1)
        )
        i.save()

        # Templates:
        # One role, one tag, pricing
        self.tmpl1 = EventTemplate(name="Template 1")
        self.tmpl1.save()
        self.tmpl1.roles.set([r1])
        self.tmpl1.tags.set([t1])
        self.tmpl1.pricing = u"Entry: \u00a35 / \u20ac10"
        self.tmpl1.save()

        # Two roles, two tags
        self.tmpl2 = EventTemplate(name="Template 2")
        self.tmpl2.save()
        self.tmpl2.roles.set([r1, r2])
        self.tmpl2.tags.set([t1, t3])
        self.tmpl2.save()

        # No roles, no tags, no pricing
        self.tmpl3 = EventTemplate(name="Template 3")
        self.tmpl3.save()

        # Members:
        m1 = Member(name="Member One", email="*****@*****.**", number="1",
                    postcode="BS1 1AA")
        m1.save()
        m2 = Member(name="Two Member", email="*****@*****.**", number="2",
                    postcode="")
        m2.save()
        m3 = Member(name="Volunteer One", email="*****@*****.**", number="3",
                    phone="0800 000 000", address="1 Road", posttown="Town",
                    postcode="BS6 123", country="UK",
                    website="http://foo.test/")
        m3.save()
        m4 = Member(name="Volunteer Two", email="", number="4",
                    phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="http://foo.test/")
        m4.save()
        m5 = Member(name="Volunteer Three", email="*****@*****.**",
                    number="4", phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="")
        m5.save()

        # Volunteers:
        v1 = Volunteer(member=m3)
        v1.save()
        v1.roles.set([r1, r3])
        v1.save()

        v2 = Volunteer(member=m4)
        v2.save()

        v3 = Volunteer(member=m5)
        v3.save()
        v3.roles.set([r3])
        v3.save()
Exemplo n.º 26
0
    def _setup_test_data(self):
        # Roles:
        r1 = Role(name="Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name="Role 2 (nonstandard)", read_only=False, standard=False)
        r2.save()
        r3 = Role(name="Role 3", read_only=False, standard=False)
        r3.save()

        # Members:
        self.mem_1 = Member(name=u"Member On\u0205",
                            email="*****@*****.**",
                            number="1",
                            postcode="BS1 1AA")
        self.mem_1.save()
        self.mem_2 = Member(name=u"Tw\u020d Member",
                            email="*****@*****.**",
                            number="02",
                            postcode="",
                            membership_expires=date(day=31, month=5,
                                                    year=2010))
        self.mem_2.save()
        self.mem_3 = Member(name=u"Some Third Chap",
                            email="*****@*****.**",
                            number="000",
                            postcode="NORAD",
                            membership_expires=date(day=1, month=6, year=2010))
        self.mem_3.save()
        self.mem_4 = Member(name="Volunteer One",
                            email="*****@*****.**",
                            number="3",
                            phone="0800 000 000",
                            address="1 Road",
                            posttown="Town of towns",
                            postcode="BS6 123",
                            country="UKountry",
                            website="http://1.foo.test/")
        self.mem_4.save()
        self.mem_5 = Member(name="Volunteer Two",
                            email="",
                            number="4",
                            phone="",
                            altphone="",
                            address="",
                            posttown="",
                            postcode="",
                            country="",
                            website="http://two.foo.test/")
        self.mem_5.save()
        self.mem_6 = Member(name="Volunteer Three",
                            email="*****@*****.**",
                            number="4",
                            phone="",
                            altphone="",
                            address="",
                            posttown="",
                            postcode="",
                            country="",
                            website="")
        self.mem_6.save()
        self.mem_7 = Member(name="Volunteer Four",
                            email="*****@*****.**",
                            number="o4",
                            phone="",
                            altphone="",
                            address="",
                            posttown="",
                            postcode="",
                            country="",
                            website="")
        self.mem_7.save()
        self.mem_8 = Member(name=u"Number Eight, No mailout please",
                            email="*****@*****.**",
                            number="010",
                            mailout=False)
        self.mem_8.save()
        self.mem_8 = Member(name=u"Number Nine, mailout failed",
                            email="*****@*****.**",
                            number="010",
                            mailout_failed=True)
        self.mem_8.save()

        # Volunteers:
        self.vol_1 = Volunteer(member=self.mem_4,
                               notes=u'Likes the $, the \u00a3 and the \u20ac',
                               portrait=settings.MEDIA_ROOT +
                               "/path/to/portrait")
        self.vol_1.save()
        self.vol_1.roles.set([r1, r3])
        self.vol_1.save()

        self.vol_2 = Volunteer(member=self.mem_5)
        self.vol_2.save()

        self.vol_3 = Volunteer(member=self.mem_6)
        self.vol_3.save()
        self.vol_3.roles.set([r3])
        self.vol_3.save()

        self.vol_4 = Volunteer(member=self.mem_7,
                               active=False,
                               notes=u"Subliminal, superluminous")
        self.vol_4.save()
        self.vol_4.roles.set([r3])
        self.vol_4.save()
Exemplo n.º 27
0
    def _setup_test_data(self):

        self._fake_now = pytz.timezone(
            "Europe/London").localize(datetime(2013, 6, 1, 11, 00))

        # Roles:
        r1 = Role(name=u"Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name=u"Role 2 (nonstandard)",
                  read_only=False, standard=False)
        r2.save()
        r3 = Role(name=u"Role 3", read_only=False, standard=False)
        r3.save()

        # Tags:
        t1 = EventTag(name=u"tag one", slug=u"tag-one", read_only=False)
        t1.save()
        t2 = EventTag(name=u"tag two", slug=u"tag-two",
                      promoted=True, sort_order=2, read_only=False)
        t2.save()
        # 'ag-three' is what slugify() gives for that name:
        t3 = EventTag(name=u"\u0167ag \u0165hre\u0119",
                      slug=u"ag-three", sort_order=1, promoted=True,
                      read_only=False)
        t3.save()

        Room(name="Room one", colour="#Ff0000").save()
        self.room_2 = Room(name="Room two", colour="#00abcd")
        self.room_2.save()

        # Event  outside_hire   private   Tags
        # ---------------------------------------
        # e1     True           False
        # e2     False          False
        # e3     False          False    t2
        # e4     False          False    t2
        # e5     False          True
        # e6     True           True     t3

        # Showing Event  Date    Confirmed  Hiddn  Cnclld  Dscnt|E: oside pvate
        # ------------------------------------------------------|--------------
        # e2s1    e2    1/4/13   F          F      F      F     |   F      F
        # e2s2    e2    2/4/13   T          F      F      F     |   F      F
        # e2s3    e2    3/4/13   T          F      T      F     |   F      F
        # e2s4    e2    4/4/13   T          T      F      F     |   F      F
        # e2s5    e2    5/4/13   T          T      T      F     |   F      F

        # s2      e3    13/4/13  T          F      F      F     |   F      F
        # s3      e4    9/6/13   T          F      F      F     |   F      F
        # s4      e4    14/9/13  F          F      F      F     |   F      F
        # s5      e5    14/2/13  T          F      F      F     |   F      T
        # s6      e1    15/2/13  T          T      F      F     |   F      F

        # Events:
        e1 = Event(
            name="Event one title",
            pricing="PRICING_ONE",
            copy="Event one copy",
            pre_title="PRETITLE One",
            post_title="POSTTITLE One",
            film_information="FILM_INFO_One",
            copy_summary="Event one copy summary",
            duration="01:30:00",
            outside_hire=True,
        )
        e1.save()

        self.e2 = Event(
            name="Event two title",
            # newlines will be stripped at legacy conversion:
            copy="Event\n two\n copy",
            pricing="Pricing TWO",
            copy_summary="Event two\n copy summary",
            duration="01:30:00",
            legacy_id="100",
            legacy_copy=True,
        )
        self.e2.save()

        e3 = Event(
            name="Event three title",
            pricing="Pricing THREE",
            copy="Event three Copy",
            pre_title="PRETITLE THREE",
            post_title="POSTTITLE THREE",
            film_information="FILM_INFO_THREE",
            copy_summary="Copy three summary",
            duration="03:00:00",
            notes="Notes",
        )
        e3.save()
        e3.tags.set([t2, ])
        e3.save()

        e4 = Event(
            name=u"Event four titl\u0113",
            copy=u"Event four C\u014dpy",
            pricing=u"\u00a3milliion per thing",
            pre_title=u"Pretitle four",
            post_title=u"Posttitle four",
            film_information=u"Film info for four",
            copy_summary=u"\u010copy four summary",
            terms=u"Terminal price: \u00a31 / \u20ac3",
            duration="01:00:00",
            notes=u"\u0147otes on event fou\u0159",
        )
        e4.save()
        e4.tags.set([t2, ])
        e4.save()

        e5 = Event(
            name=u"PRIVATE Event FIVE titl\u0113!",
            copy=u"PRIVATE Event 5ive C\u014dpy",
            copy_summary=u"\u010copy five summary",
            terms=u"More terms; price: \u00a32 / \u20ac5",
            duration="10:00:00",
            notes=u"\u0147otes on event five",
            private=True
        )
        e5.save()

        e6 = Event(
            name=u"PRIVATE OUTSIDE Event (Six)",
            copy=u"PRIVATE OUTSIDE Event 6ix copy",
            copy_summary=u"OUTSIDE PRIVATE \u010copy six summary",
            terms=u"Ever More terms; price: \u00a32 / \u20ac5",
            duration="4:00:00",
            notes=u"\u0147otes on private/outwide event six",
            outside_hire=True,
            private=True
        )
        e6.save()
        e6.tags.set([t3, ])
        e6.save()

        # Showings:
        self.e2s1 = Showing(  # pk :1
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 1, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=False, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s1.save(force=True)
        self.e2s2 = Showing(  # pk :2
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 2, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s2.save(force=True)
        e2s3 = Showing(  # pk :3
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 3, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=True, discounted=False)
        e2s3.save(force=True)
        e2s4 = Showing(  # pk :4
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 4, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=False, discounted=False)
        e2s4.save(force=True)
        e2s5 = Showing(  # pk :5
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 5, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=True, discounted=False)
        e2s5.save(force=True)

        s2 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 13, 18, 00)),
            event=e3,
            booked_by="User Two",
            confirmed=True
        )
        s2.save(force=True)  # Force start date in the past

        # When the clock is patched to claim that it's 1/6/2013, this showing
        # will be in the future:
        self.e4s3 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 6, 9, 18, 00)),
            event=e4,
            booked_by=u"\u0102nother \u0170ser",
            confirmed=True,
            rota_notes="Some notes about the Rota!",
        )
        self.e4s3.save(force=True)  # Force start date in the past

        s4 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 9, 14, 18, 00)),
            event=e4,
            booked_by="User Two",
            hide_in_programme=True,
            confirmed=False
        )
        s4.save(force=True)  # Force start date in the past

        s5 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 14, 18, 00)),
            event=e5,
            booked_by="Yet another user",
            confirmed=True,
        )
        s5.save(force=True)

        s6 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 15, 18, 00)),
            event=e1,
            booked_by="Blah blah",
            confirmed=True,
            hide_in_programme=True,
        )
        s6.save(force=True)

        # Rota items:
        RotaEntry(showing=self.e2s1, role=r2, rank=1).save()
        RotaEntry(showing=self.e2s1, role=r3, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=2).save()
        RotaEntry(showing=s2, role=r1, rank=3).save()
        RotaEntry(showing=s2, role=r1, rank=4).save()
        RotaEntry(showing=s2, role=r1, rank=5).save()
        RotaEntry(showing=s2, role=r1, rank=6).save()
        RotaEntry(showing=self.e4s3, role=r2, rank=1).save()

        # Ideas:
        i = DiaryIdea(
            ideas="April 2013 ideas",
            month=date(year=2013, month=4, day=1)
        )
        i.save()
        i = DiaryIdea(
            ideas="May 2013 ideas",
            month=date(year=2013, month=5, day=1)
        )
        i.save()

        # Templates:
        # One role, one tag, pricing
        self.tmpl1 = EventTemplate(name="Template 1")
        self.tmpl1.save()
        self.tmpl1.roles.set([r1])
        self.tmpl1.tags.set([t1])
        self.tmpl1.pricing = u"Entry: \u00a35 / \u20ac10"
        self.tmpl1.save()

        # Two roles, two tags
        self.tmpl2 = EventTemplate(name="Template 2")
        self.tmpl2.save()
        self.tmpl2.roles.set([r1, r2])
        self.tmpl2.tags.set([t1, t3])
        self.tmpl2.save()

        # No roles, no tags, no pricing
        self.tmpl3 = EventTemplate(name="Template 3")
        self.tmpl3.save()

        # Members:
        m1 = Member(name="Member One", email="*****@*****.**", number="1",
                    postcode="BS1 1AA")
        m1.save()
        m2 = Member(name="Two Member", email="*****@*****.**", number="2",
                    postcode="")
        m2.save()
        m3 = Member(name="Volunteer One", email="*****@*****.**", number="3",
                    phone="0800 000 000", address="1 Road", posttown="Town",
                    postcode="BS6 123", country="UK",
                    website="http://foo.test/")
        m3.save()
        m4 = Member(name="Volunteer Two", email="", number="4",
                    phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="http://foo.test/")
        m4.save()
        m5 = Member(name="Volunteer Three", email="*****@*****.**",
                    number="4", phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="")
        m5.save()

        # Volunteers:
        v1 = Volunteer(member=m3)
        v1.save()
        v1.roles.set([r1, r3])
        v1.save()

        v2 = Volunteer(member=m4)
        v2.save()

        v3 = Volunteer(member=m5)
        v3.save()
        v3.roles.set([r3])
        v3.save()
Exemplo n.º 28
0
class MailoutTestSendViewTests(TestCase, fixtures.TestWithFixtures):
    def setUp(self):
        self.useFixture(ToolkitUsersFixture())

        self.url = reverse("mailout-test-send")

        self.member = Member(name="Member One", email="*****@*****.**",
                             number="1", postcode="BS1 1AA")
        self.member.save()
        # Log in:
        self.client.login(username="******", password="******")

        self.send_patch = patch("toolkit.members.tasks.send_mailout_to")
        self.send_mock = self.send_patch.start()

    def tearDown(self):
        self.send_patch.stop()

    def test_no_get(self):
        response = self.client.get(self.url)
        # 405 Method Not Allowed
        self.assertEqual(response.status_code, 405)

    @override_settings(HTML_MAILOUT_ENABLED=False)
    @patch("toolkit.diary.mailout_views.Member")
    def test_success_html_disabled(self, member_mock):
        self.send_mock.return_value = (False, 1, None)
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'address': u"*****@*****.**",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': None,
        })
        self.send_mock.assert_called_once_with(
            u"Yet another member's mailout",
            u"Let the bodies hit the floor\netc.",
            None,
            member_mock.objects.filter.return_value.__getitem__.return_value
        )

    @override_settings(HTML_MAILOUT_ENABLED=True)
    @patch("toolkit.diary.mailout_views.Member")
    def test_success_html_enabled(self, member_mock):
        self.send_mock.return_value = (False, 1, None)
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'body_html': u"<h1>My HTML email</h1>",
            'send_html': u"true",
            'address': u"*****@*****.**",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': None,
        })
        self.send_mock.assert_called_once_with(
            u"Yet another member's mailout",
            u"Let the bodies hit the floor\netc.",
            u"<h1>My HTML email</h1>",
            member_mock.objects.filter.return_value.__getitem__.return_value
        )

    @override_settings(HTML_MAILOUT_ENABLED=True)
    @patch("toolkit.diary.mailout_views.Member")
    def test_success_html_enabled_do_not_send_html(self, member_mock):
        self.send_mock.return_value = (False, 1, None)
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'body_html': u"<h1>My HTML email</h1>",
            'send_html': u"false",
            'address': u"*****@*****.**",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': None,
        })
        self.send_mock.assert_called_once_with(
            u"Yet another member's mailout",
            u"Let the bodies hit the floor\netc.",
            None,
            member_mock.objects.filter.return_value.__getitem__.return_value
        )

    @override_settings(HTML_MAILOUT_ENABLED=True)
    def test_missing_html(self):
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'address': u"*****@*****.**",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            u'errors':
                u'body_html: '
                u'<ul class="errorlist"><li>This field is required.</li></ul>',
            u'status': u'error'
        })
        self.send_mock.assert_not_called()

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_success_with_message(self):
        self.send_mock.return_value = (False, 1, "Message of success")
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'address': u"*****@*****.**",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'ok',
            'errors': "Message of success",
        })

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_failed_send(self):
        self.send_mock.return_value = (True, None, u"Failed for some reason")
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'address': u"*****@*****.**",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'error',
            'errors': 'Failed for some reason',
        })

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_no_member(self):
        self.send_mock.return_value = (False, None, None)
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'address': u"*****@*****.**",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'error',
            'errors': 'No member found with given email address',
        })

    @override_settings(HTML_MAILOUT_ENABLED=False)
    def test_bad_email(self):
        self.send_mock.return_value = (False, None, None)
        response = self.client.post(self.url, data={
            'subject': u"Yet another member's mailout",
            'body_text': u"Let the bodies hit the floor\netc.",
            'address': u"dodgy",
        })
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            'status': 'error',
            'errors':  u'address: <ul class="errorlist"><li>'
                       u'Enter a valid email address.</li></ul>'
        })