Exemplo n.º 1
0
    def test_create_a_new_paste_without_filename_or_description(self):
        self.assertIsNone(Paste.get_by_id(1))

        data = {
            'filename': '',
            'description': '',
            'content': 'foo bar baz',
        }
        url = reverse('paste_create')

        with freeze_time('2016-12-25'):
            response = self.client.post(url, data)

        detail_url = reverse('paste_detail', args=[1])

        self.assertRedirects(response, detail_url)

        paste = Paste.get_by_id(1)

        self.assertEqual(
            paste.to_dict(),
            {
                'author':
                u'',
                'created':
                datetime.datetime(2016, 12, 25),
                'description':
                u'',
                'filename':
                u'untitled.txt',
                'files': [
                    {
                        'content_type': 'text/plain',
                        'created': datetime.datetime(2016, 12, 25),
                        'filename': 'untitled.txt',
                        'num_lines': 1,
                        'path': u'pasty/2016/12/25/1/1/untitled.txt',
                        'relative_path': '1/untitled.txt',
                    },
                ],
                'fork':
                None,
                'id':
                1,
                'num_files':
                1,
                'num_lines':
                1,
                'preview': ('<div class="highlight highlight__autumn">'
                            '<pre><span></span>foo bar baz\n</pre></div>\n'),
                'url':
                '/1/',
            },
        )
Exemplo n.º 2
0
    def test_create_a_new_paste_on_post(self):
        self.assertIsNone(Paste.get_by_id(1))

        data = {
            'description': 'Foo',
            'filename': 'example.txt',
            'content': 'foo bar baz',
        }

        url = reverse('paste_create')
        with freeze_time('2016-12-25'):
            response = self.client.post(url, data)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], '/1/')

        paste = Paste.get_by_id(1)

        self.assertEqual(
            paste.to_dict(),
            {
                'author':
                u'',
                'created':
                datetime.datetime(2016, 12, 25),
                'description':
                'Foo',
                'filename':
                'example.txt',
                'files': [
                    {
                        'content_type': 'text/plain',
                        'created': datetime.datetime(2016, 12, 25),
                        'filename': 'example.txt',
                        'num_lines': 1,
                        'path': 'pasty/2016/12/25/1/1/example.txt',
                        'relative_path': '1/example.txt',
                    },
                ],
                'fork':
                None,
                'id':
                1,
                'num_files':
                1,
                'num_lines':
                1,
                'preview': ('<div class="highlight highlight__autumn">'
                            '<pre><span></span>foo bar baz\n</pre></div>\n'),
                'url':
                '/1/',
            },
        )
Exemplo n.º 3
0
    def test_error_for_non_existent_paste(self):
        url = reverse('api_paste_detail', args=('1234', ))

        self.assertIsNone(Paste.get_by_id(1234))

        response = self.client.get(url)

        self.assertEqual(response.status_code, 404)
        self.assertEqual(response['Content-type'], 'application/json')
        self.assertEqual(
            response.json(),
            {u'error': u'Paste does not exist'},
        )
Exemplo n.º 4
0
    def test_unstar_non_existent_paste(self):
        url = reverse('api_star_delete')
        data = {'paste': '1234'}

        self.assertIsNone(Paste.get_by_id(1234))

        self.login('*****@*****.**')
        response = self.client.post(url, data)

        self.assertEqual(response.status_code, 400)
        self.assertEqual(response['Content-type'], 'application/json')
        self.assertEqual(
            response.json(),
            {'error': 'Does not exist'},
        )
Exemplo n.º 5
0
    def test_get_or_404_with_unknown_id(self):
        self.assertIsNone(Paste.get_by_id(1234))

        with self.assertRaises(Http404):
            Paste.get_or_404(1234)