Пример #1
0
    def setUp(self):
        self.agencies = AgencyFactory.create_batch(6)
        self.composer = FOIAComposerFactory(
            status="submitted",
            agencies=self.agencies,
            num_monthly_requests=2,
            num_reg_requests=3,
        )
        self.task = MultiRequestTask.objects.create(composer=self.composer)

        self.mocker = requests_mock.Mocker()
        mock_squarelet(self.mocker)
        self.mocker.start()
        self.addCleanup(self.mocker.stop)
Пример #2
0
 def test_registered_ajax(self, mock_requests):
     """
     A contribution made via AJAX while logged out, but registering, should report that:
     - the user is authenticated
     - the user was registered
     """
     mock_squarelet(mock_requests)
     # when registering, the full name should be present
     self.data['full_name'] = 'John Doe'
     self.data['show'] = True
     response = self.post(self.data, ajax=True)
     data = json.loads(response.content)
     print data
     eq_(data['authenticated'], True)
     eq_(data['registered'], True)
Пример #3
0
    def test_expected_case(self, mock_requests):
        """
        Giving the miniregister method a full name, email, and password should
        create a user, create a profile, and log them in.
        The method should return the authenticated user.
        """

        mock_squarelet(mock_requests)

        request = RequestFactory()
        mixin = MiniregMixin()
        form = Mock()
        mixin.request = mock_middleware(request.get(reverse('foia-create')))
        user = mixin.miniregister(form, self.full_name, self.email)
        ok_(isinstance(user, User), 'A user should be created and returned.')
        ok_(user.profile, 'A profile should be created for the user.')
        ok_(user.is_authenticated(), 'The user should be logged in.')
        eq_(user.profile.full_name, 'Lou Reed')
        eq_(user.username, 'LouReed',
            'The username should remove the spaces from the full name.')
Пример #4
0
 def setUp(self):
     self.mocker = requests_mock.Mocker()
     mock_squarelet(self.mocker)
     self.mocker.start()
     self.addCleanup(self.mocker.stop)
Пример #5
0
    def test_request_lifecycle_no_email(self, mock_request):
        """Test a request going through the full cycle as if we had to
        physically mail it
        """
        # pylint: disable=too-many-statements
        # pylint: disable=protected-access

        mock_squarelet(mock_request)
        mail.outbox = []
        user = UserFactory(membership__organization__number_requests=1)
        agency = AgencyFactory(email=None, fax=None)
        cal = agency.jurisdiction.get_calendar()

        with freeze_time("2010-02-01"):
            nose.tools.eq_(len(mail.outbox), 0)

            ## create and submit request
            composer = FOIAComposerFactory(
                user=user,
                organization=user.profile.organization,
                title="Test with no email",
                agencies=[agency],
            )
            composer.submit()
            foia = FOIARequest.objects.get(composer=composer)
            comm = foia.communications.last()
            self.run_commit_hooks()

            # check that a snail mail task was created
            nose.tools.ok_(
                SnailMailTask.objects.filter(communication=comm,
                                             category="n").exists())

        ## two days pass, then the admin mails in the request
        with freeze_time("2010-02-03"):
            foia.status = "processed"
            foia.update_dates()
            foia.save()

            # make sure dates were set correctly
            nose.tools.eq_(foia.composer.datetime_submitted,
                           datetime(2010, 2, 1, tzinfo=pytz.utc))
            nose.tools.eq_(
                foia.date_due,
                cal.business_days_from(date(2010, 2, 1),
                                       agency.jurisdiction.days),
            )
            nose.tools.eq_(
                foia.date_followup,
                max(
                    foia.date_due,
                    foia.communications.last().datetime.date() +
                    timedelta(foia._followup_days()),
                ),
            )
            nose.tools.ok_(foia.days_until_due is None)
            # no more mail should have been sent
            nose.tools.eq_(len(mail.outbox), 0)

            old_date_due = foia.date_due

        ## after 5 days agency replies with a fix needed
        with freeze_time("2010-02-08"):
            comm = FOIACommunication.objects.create(
                foia=foia,
                from_user=agency.get_user(),
                to_user=user,
                datetime=timezone.now(),
                response=True,
                communication="Test communication",
            )
            foia.status = "fix"
            foia.save()
            foia.update(comm.anchor())

            # make sure dates were set correctly
            nose.tools.eq_(foia.composer.datetime_submitted,
                           datetime(2010, 2, 1, tzinfo=pytz.utc))
            nose.tools.ok_(foia.date_due is None)
            nose.tools.ok_(foia.date_followup is None)
            nose.tools.eq_(
                foia.days_until_due,
                cal.business_days_between(date(2010, 2, 8), old_date_due),
            )

            old_days_until_due = foia.days_until_due

        ## after 10 days the user submits the fix and the admin submits it right away
        with freeze_time("2010-02-18"):
            comm = FOIACommunication.objects.create(
                foia=foia,
                from_user=user,
                to_user=agency.get_user(),
                datetime=timezone.now(),
                response=False,
                communication="Test communication",
            )
            foia.status = "submitted"
            foia.save()
            foia.submit()
            self.run_commit_hooks()

            # check that another snail mail task is created
            nose.tools.ok_(
                SnailMailTask.objects.filter(communication=comm,
                                             category="u").exists())

            foia.status = "processed"

            foia.update_dates()
            foia.save()

            # make sure dates were set correctly
            nose.tools.eq_(foia.composer.datetime_submitted,
                           datetime(2010, 2, 1, tzinfo=pytz.utc))
            nose.tools.eq_(
                foia.date_due,
                cal.business_days_from(date.today(), old_days_until_due))
            nose.tools.eq_(
                foia.date_followup,
                max(
                    foia.date_due,
                    foia.communications.last().datetime.date() +
                    timedelta(foia._followup_days()),
                ),
            )
            nose.tools.ok_(foia.days_until_due is None)

            old_date_due = foia.date_due

        ## after 4 days agency replies with the documents
        with freeze_time("2010-02-22"):
            comm = FOIACommunication.objects.create(
                foia=foia,
                from_user=agency.get_user(),
                to_user=user,
                datetime=timezone.now(),
                response=True,
                communication="Test communication",
            )
            foia.status = "done"
            foia.save()
            foia.update(comm.anchor())

            # make sure dates were set correctly
            nose.tools.eq_(foia.composer.datetime_submitted,
                           datetime(2010, 2, 1, tzinfo=pytz.utc))
            nose.tools.eq_(foia.date_due, old_date_due)
            nose.tools.ok_(foia.date_followup is None)
            nose.tools.ok_(foia.days_until_due is None)