Beispiel #1
0
 def test_inbox_invalid_get(self):
     ''' shouldn't try to handle if the user is not found '''
     request = self.factory.get('https://www.example.com/')
     self.assertIsInstance(incoming.inbox(request, 'anything'),
                           HttpResponseNotAllowed)
     self.assertIsInstance(incoming.shared_inbox(request),
                           HttpResponseNotAllowed)
Beispiel #2
0
 def test_inbox_invalid_bad_signature_delete(self):
     ''' invalid signature for Delete is okay though '''
     request = self.factory.post(self.local_user.shared_inbox,
                                 '{"type": "Delete", "object": "exists"}',
                                 content_type='application/json')
     with patch('bookwyrm.incoming.has_valid_signature') as mock_has_valid:
         mock_has_valid.return_value = False
         self.assertEqual(incoming.shared_inbox(request).status_code, 200)
Beispiel #3
0
 def test_inbox_unknown_type(self):
     ''' never heard of that activity type, don't have a handler for it '''
     request = self.factory.post(self.local_user.shared_inbox,
                                 '{"type": "Fish", "object": "exists"}',
                                 content_type='application/json')
     with patch('bookwyrm.incoming.has_valid_signature') as mock_has_valid:
         mock_has_valid.return_value = True
         self.assertIsInstance(incoming.shared_inbox(request),
                               HttpResponseNotFound)
Beispiel #4
0
    def test_inbox_success(self):
        ''' a known type, for which we start a task '''
        request = self.factory.post(self.local_user.shared_inbox,
                                    '{"type": "Accept", "object": "exists"}',
                                    content_type='application/json')
        with patch('bookwyrm.incoming.has_valid_signature') as mock_has_valid:
            mock_has_valid.return_value = True

            with patch('bookwyrm.incoming.handle_follow_accept.delay'):
                self.assertEqual(
                    incoming.shared_inbox(request).status_code, 200)
Beispiel #5
0
 def test_inbox_invalid_no_object(self):
     ''' json is missing "object" field '''
     request = self.factory.post(self.local_user.shared_inbox, data={})
     self.assertIsInstance(incoming.shared_inbox(request),
                           HttpResponseBadRequest)