Exemplo n.º 1
0
 def test_post_enable(self):
     """Posting enable should turn on link sharing."""
     data = {'action': 'enable'}
     http_post_response(self.url, self.view, data, self.foi.user,
                        **self.kwargs)
     self.foi.refresh_from_db()
     ok_(self.foi.sharing_code)
Exemplo n.º 2
0
 def test_add_tags(self):
     """Posting a collection of tags to a request should update its tags."""
     data = {'action': 'tags', 'tags': 'foo, bar'}
     http_post_response(self.url, self.view, data, self.foia.user, **self.kwargs)
     self.foia.refresh_from_db()
     ok_('foo' in [tag.name for tag in self.foia.tags.all()])
     ok_('bar' in [tag.name for tag in self.foia.tags.all()])
Exemplo n.º 3
0
 def test_post_status(self):
     """A user updating the status of their request should update the status,
     open a status change task, and close any open response tasks"""
     nose.tools.assert_not_equal(self.foia.status, 'done')
     eq_(
         len(
             StatusChangeTask.objects.filter(
                 foia=self.foia,
                 user=self.foia.user,
                 resolved=False,
             )), 0)
     communication = FOIACommunicationFactory(foia=self.foia)
     response_task = ResponseTaskFactory(
         communication=communication,
         resolved=False,
     )
     data = {'action': 'status', 'status': 'done'}
     http_post_response(self.url, self.view, data, self.foia.user,
                        **self.kwargs)
     self.foia.refresh_from_db()
     eq_(self.foia.status, 'done')
     eq_(
         len(
             StatusChangeTask.objects.filter(
                 foia=self.foia,
                 user=self.foia.user,
                 resolved=False,
             )), 1)
     response_task.refresh_from_db()
     ok_(response_task.resolved)
Exemplo n.º 4
0
 def test_settings_view(self):
     """Test the account settings view"""
     profile = self.user.profile
     profile_data = {
         'action': 'profile',
         'first_name': 'Allan',
         'last_name': 'Lasser',
         'twitter': 'allanlasser'
     }
     email_data = {
         'action': 'email',
         'email': '*****@*****.**',
         'email_pref': 'hourly'
     }
     settings_url = reverse('acct-settings')
     http_post_response(settings_url, views.profile_settings, profile_data,
                        self.user)
     http_post_response(settings_url, views.profile_settings, email_data,
                        self.user)
     self.user.refresh_from_db()
     profile.refresh_from_db()
     all_data = {}
     all_data.update(profile_data)
     all_data.update(email_data)
     all_data.pop('action')
     for key, val in all_data.iteritems():
         if key in ['first_name', 'last_name', 'email']:
             eq_(val, getattr(self.user, key))
         else:
             eq_(val, getattr(profile, key))
Exemplo n.º 5
0
 def test_mark_all_read(self):
     """Users should be able to mark all their notifications as read."""
     data = {'action': 'mark_all_read'}
     ok_(self.unread_notification.read is not True)
     http_post_response(self.url, self.view, data, self.user)
     self.unread_notification.refresh_from_db()
     ok_(self.unread_notification.read is True,
         'The unread notification should be marked as read.')
Exemplo n.º 6
0
 def test_post_disable(self):
     """Posting disable should turn off link sharing."""
     self.foi.generate_sharing_code()
     ok_(self.foi.sharing_code)
     data = {'action': 'disable'}
     http_post_response(self.url, self.view, data, self.foi.user,
                        **self.kwargs)
     self.foi.refresh_from_db()
     ok_(not self.foi.sharing_code)
Exemplo n.º 7
0
 def test_add_projects(self):
     """Posting a collection of projects to a request should add it to those projects."""
     project = ProjectFactory()
     form = ProjectManagerForm({'projects': [project.pk]})
     ok_(form.is_valid())
     data = {'action': 'projects'}
     data.update(form.data)
     http_post_response(self.url, self.view, data, self.foia.user, **self.kwargs)
     project.refresh_from_db()
     ok_(self.foia in project.requests.all())
Exemplo n.º 8
0
 def test_appeal_example(self):
     """If an example appeal is used to base the appeal off of,
     then the examples should be recorded to the appeal object as well."""
     example_appeal = ExampleAppealFactory()
     data = {'action': 'appeal', 'text': 'Lorem ipsum', 'base_language': example_appeal.pk}
     http_post_response(self.url, self.view, data, self.foia.user, **self.kwargs)
     self.foia.refresh_from_db()
     appeal = Appeal.objects.last()
     ok_(appeal.base_language, 'The appeal should record its base language.')
     ok_(appeal.base_language.count(), 1)
Exemplo n.º 9
0
 def test_post_resolve_task(self):
     data = {'resolve': 'truthy', 'task': self.task.pk}
     http_post_response(self.url, self.view, data, self.user)
     self.task.refresh_from_db()
     eq_(
         self.task.resolved, True,
         'Tasks should be resolved by posting the task ID with a "resolve" request.'
     )
     eq_(self.task.resolved_by, self.user,
         'Task should record the logged in user who resolved it.')
Exemplo n.º 10
0
 def test_missing_appeal(self):
     """An appeal that is missing its language should not do anything."""
     comm_count = self.foia.communications.count()
     previous_status = self.foia.status
     data = {'action': 'appeal', 'text': ''}
     http_post_response(self.url, self.view, data, self.foia.user, **self.kwargs)
     self.foia.refresh_from_db()
     eq_(self.foia.status, previous_status,
         'The status of the request should not be changed.')
     eq_(self.foia.communications.count(), comm_count,
         'No communication should be added to the request.')
Exemplo n.º 11
0
 def test_post_set_price(self):
     """Setting the price should update the price on the response's request."""
     price = 1
     foia = self.task.communication.foia
     logging.info(foia.agency)
     data = {'status': 'done', 'price': price, 'task': self.task.pk}
     http_post_response(self.url, self.view, data, self.user)
     self.task.refresh_from_db()
     foia.refresh_from_db()
     eq_(foia.price, float(price), 'The price on the FOIA should be set.')
     ok_(self.task.resolved, 'Setting the price should resolve the task.')
Exemplo n.º 12
0
 def test_buy_multiple_bundles(self):
     """Users should be able to buy multiple bundles of four requests."""
     profile = self.user.profile
     bundles_to_buy = 2
     existing_request_count = profile.num_requests
     self.data['bundles'] = bundles_to_buy
     http_post_response(self.url, self.view, self.data, self.user,
                        **self.kwargs)
     profile.refresh_from_db()
     requests_to_add = bundles_to_buy * self.user.profile.bundled_requests()
     eq_(profile.num_requests, existing_request_count + requests_to_add)
Exemplo n.º 13
0
 def test_unauthorized_appeal(self):
     """Appealing a request without permission should not do anything."""
     unauth_user = UserFactory()
     comm_count = self.foia.communications.count()
     previous_status = self.foia.status
     data = {'action': 'appeal', 'text': 'Lorem ipsum'}
     http_post_response(self.url, self.view, data, unauth_user, **self.kwargs)
     self.foia.refresh_from_db()
     eq_(self.foia.status, previous_status,
         'The status of the request should not be changed.')
     eq_(self.foia.communications.count(), comm_count,
         'No communication should be added to the request.')
Exemplo n.º 14
0
 def test_batch_resolve_tasks(self):
     data = {
         'resolve': 'truthy',
         'tasks': [_task.id for _task in self.tasks]
     }
     http_post_response(self.url, self.view, data, self.user)
     for _task in self.tasks:
         _task.refresh_from_db()
         eq_(
             _task.resolved, True,
             'Task %d should be resolved when doing a batched resolve' %
             _task.pk)
Exemplo n.º 15
0
 def test_unappealable_request(self):
     """An appeal on a request that cannot be appealed should not do anything."""
     self.foia.status = 'submitted'
     self.foia.save()
     nose.tools.assert_false(self.foia.has_perm(self.foia.user, 'appeal'))
     comm_count = self.foia.communications.count()
     previous_status = self.foia.status
     data = {'action': 'appeal', 'text': 'Lorem ipsum'}
     http_post_response(self.url, self.view, data, self.foia.user, **self.kwargs)
     self.foia.refresh_from_db()
     eq_(self.foia.status, previous_status,
         'The status of the request should not be changed.')
     eq_(self.foia.communications.count(), comm_count,
         'No communication should be added to the request.')
Exemplo n.º 16
0
 def test_post_move(self):
     """Moving the response should save it to a new request."""
     other_foia = factories.FOIARequestFactory()
     starting_date = self.task.communication.date
     data = {'move': other_foia.id, 'status': 'done', 'task': self.task.pk}
     http_post_response(self.url, self.view, data, self.user)
     self.task.refresh_from_db()
     self.task.communication.refresh_from_db()
     ending_date = self.task.communication.date
     eq_(self.task.communication.foia, other_foia,
         'The response should be moved to a different FOIA.')
     ok_(self.task.resolved, 'Moving the status should resolve the task')
     eq_(starting_date, ending_date,
         'Moving the communication should not change its date.')
Exemplo n.º 17
0
 def test_appeal(self):
     """Appealing a request should send a new communication,
     record the details of the appeal, and update the status of the request."""
     comm_count = self.foia.communications.count()
     data = {'action': 'appeal', 'text': 'Lorem ipsum'}
     http_post_response(self.url, self.view, data, self.foia.user, **self.kwargs)
     self.foia.refresh_from_db()
     eq_(self.foia.status, 'appealing')
     eq_(self.foia.communications.count(), comm_count + 1)
     eq_(self.foia.last_comm().communication, data['text'],
         'The appeal should use the language provided by the user.')
     appeal = Appeal.objects.last()
     ok_(appeal, 'An Appeal object should be created.')
     eq_(self.foia.last_comm(), appeal.communication,
         'The appeal should reference the communication that was created.')
Exemplo n.º 18
0
 def test_add_contributors(self, mock_notify):
     """When adding contributors, each new contributor should get an email notification."""
     new_contributor = factories.UserFactory()
     data = {
         'title': self.project.title,
         'contributors': [self.contributor.pk, new_contributor.pk]
     }
     form = forms.ProjectUpdateForm(data, instance=self.project)
     ok_(form.is_valid(), 'The form should validate. %s' % form.errors)
     http_post_response(self.url, self.view, data, self.contributor,
                        **self.kwargs)
     self.project.refresh_from_db()
     ok_(self.project.has_contributor(new_contributor))
     ok_(self.project.has_contributor(self.contributor))
     mock_notify.assert_called_once_with(new_contributor, self.project,
                                         self.contributor)
Exemplo n.º 19
0
 def test_add_note(self):
     """User with edit permission should be able to create a note."""
     response = http_post_response(self.url, self.view, self.data,
                                   self.editor, **self.kwargs)
     self.foia.refresh_from_db()
     eq_(response.status_code, 302)
     eq_(self.foia.notes.count() > 0, True)
Exemplo n.º 20
0
 def test_add_sans_permission(self):
     """Normies and viewers cannot add notes."""
     response = http_post_response(self.url, self.view, self.data,
                                   self.viewer, **self.kwargs)
     self.foia.refresh_from_db()
     eq_(response.status_code, 302)
     eq_(self.foia.notes.count(), 0)
Exemplo n.º 21
0
 def test_downgrade(self, mock_unsubscribe):
     """Logged in pro users should be able to downgrade to a Basic account."""
     data = {'action': 'downgrade'}
     pro_user = UserFactory(profile__acct_type='pro')
     response = http_post_response(self.url, self.view, data, pro_user)
     eq_(response.status_code, 200)
     ok_(mock_unsubscribe.called)
Exemplo n.º 22
0
 def test_post_ok(self):
     """Logging in should redirect to the profile page."""
     data = {
         'username': self.user.username,
         'password': self.password,
     }
     response = http_post_response(self.url, self.view, data)
     eq_(response.status_code, 200)
Exemplo n.º 23
0
 def test_logged_out_post(self, mock_subscribe):
     """Posting valid data while logged out should create a new professional account."""
     response = http_post_response(self.url, self.view, self.data)
     eq_(response.status_code, 302,
         'Should redirect to the new account upon creation.')
     user = User.objects.get(username=self.data['username'])
     ok_(user, 'The user should be created.')
     ok_(mock_subscribe.called_once)
Exemplo n.º 24
0
 def test_edit_description(self):
     """
     The description should be editable.
     When sending data, the 'edit' keyword should be set to 'description'.
     """
     desc = 'Lorem ipsum'
     data = {
         'title': self.project.title,
         'description': desc,
     }
     form = forms.ProjectUpdateForm(data, instance=self.project)
     ok_(form.is_valid(), 'The form should validate. %s' % form.errors)
     http_post_response(self.url, self.view, data, self.contributor,
                        **self.kwargs)
     self.project.refresh_from_db()
     eq_(self.project.description, desc,
         'The description should be updated.')
Exemplo n.º 25
0
 def test_logged_out_post(self):
     """Posting valid data while logged out should create a new basic account."""
     response = http_post_response(self.url, self.view, self.data)
     eq_(response.status_code, 302,
         'Should redirect to the new account upon creation.')
     user = User.objects.get(username=self.data['username'])
     ok_(user, 'The user should be created.')
     eq_(user.profile.acct_type, 'basic',
         'The user should be given a basic plan.')
Exemplo n.º 26
0
 def test_post_tracking_number(self):
     """Setting the tracking number should save it to the response's request."""
     new_tracking_id = 'ABC123OMGWTF'
     data = {
         'tracking_number': new_tracking_id,
         'status': 'done',
         'task': self.task.pk
     }
     http_post_response(self.url, self.view, data, self.user)
     self.task.refresh_from_db()
     self.task.communication.refresh_from_db()
     self.task.communication.foia.refresh_from_db()
     foia_tracking = self.task.communication.foia.tracking_id
     eq_(
         foia_tracking, new_tracking_id,
         'The new tracking number should be saved to the associated request.'
     )
     ok_(self.task.resolved,
         'Setting the tracking number should resolve the task')
Exemplo n.º 27
0
 def test_logged_out_post(self):
     """Posting valid data while logged out should create a new professional account."""
     response = http_post_response(self.url, self.view, self.data)
     eq_(response.status_code, 302,
         'Should redirect to the org activation page upon creation.')
     user = User.objects.get(username=self.data['username'])
     org = Organization.objects.get(name=self.data['organization_name'])
     ok_(user, 'The user should be created.')
     ok_(org, 'The org should be created.')
     eq_(org.owner, user, 'The user should be made an owner of the org.')
Exemplo n.º 28
0
 def test_terrible_data(self):
     """Posting awful data shouldn't cause everything to collapse."""
     data = {
         'move': 'omglol, howru',
         'status': 'notastatus',
         'tracking_number': ['wtf'],
         'task': self.task.pk
     }
     response = http_post_response(self.url, self.view, data, self.user)
     ok_(response)
Exemplo n.º 29
0
 def test_post_view(self, mock_subscribe):
     """Posting an email to the list should add that email to our MailChimp list."""
     form = NewsletterSignupForm({
         'email': '*****@*****.**',
         'list': settings.MAILCHIMP_LIST_DEFAULT
     })
     ok_(form.is_valid(), 'The form should validate.')
     response = http_post_response(self.url, self.view, form.data)
     mock_subscribe.assert_called_with(form.data['email'], form.data['list'])
     eq_(response.status_code, 302, 'Should redirect upon successful submission.')
Exemplo n.º 30
0
 def test_post(self, mock_publish):
     """Posting a valid ProjectPublishForm should publish the project."""
     notes = 'Testing project publishing'
     form = forms.ProjectPublishForm({'notes': notes})
     ok_(form.is_valid(), 'The form should validate.')
     response = http_post_response(self.url, self.view, form.data,
                                   self.contributor, **self.kwargs)
     eq_(response.status_code, 302, 'The user should be redirected.')
     eq_(response.url, self.project.get_absolute_url(),
         'The user should be redirected back to the project page.')
     mock_publish.assert_called_with(notes)