예제 #1
0
    def test_shows_detail_for_paste_without_filename_or_description(self):
        paste = Paste.create_with_files(id=1234, files=[('', 'foo bar baz')])

        url = reverse('paste_detail', args=[paste.key.id()])
        response = self.client.get(url)

        self.assertContains(response, 'foo bar baz', status_code=200)
예제 #2
0
    def test_highlight_content_with_custom_lexer_config(self):
        config = LexerConfig.get()
        config.lexers = [{'extension': 'sass', 'language': 'CSS'}]
        config.put()

        # Same content, but different filenames.
        files = [
            ('example.sass', 'body { font-family: serif; }'),
            ('example.txt', 'body { font-family: serif; }'),
        ]
        paste = Paste.create_with_files(files=files)

        css_expected = (
            u'<div class="highlight highlight__autumn"><pre><span></span>'
            u'<span class="nt">body</span> <span class="p">{</span>'
            u' <span class="nb">font-family</span><span class="o">:</span>'
            u' <span class="nb">serif</span><span class="p">;</span>'
            u' <span class="p">}</span>\n</pre></div>\n')
        txt_expected = (
            u'<div class="highlight highlight__autumn"><pre><span></span>'
            u'body { font-family: serif; }\n</pre></div>\n')

        self.assertEqual(paste.preview, css_expected)
        # The sass file was highlighted as CSS.
        self.assertEqual(paste.files[0].content_highlight(), css_expected)
        self.assertEqual(paste.files[1].content_highlight(), txt_expected)
예제 #3
0
    def test_returns_404_for_bogus_filename(self):
        paste = Paste.create_with_files(files=[('image.jpg', 'example')])

        url = reverse('paste_raw', args=[paste.key.id(), '1/bogus.jpg'])
        response = self.client.get(url)

        self.assertEqual(response.status_code, 404)
예제 #4
0
    def test_serves_raw_file(self):
        paste = Paste.create_with_files(files=[('image.jpg', 'example')])

        url = reverse('paste_raw', args=[paste.key.id(), '1/image.jpg'])
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-type'], 'image/jpeg')
예제 #5
0
    def test_download_paste_files_as_zip(self):
        paste = Paste.create_with_files(id=1234,
                                        files=[('example.txt', 'foo')])

        url = reverse('paste_download', args=[paste.key.id()])
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Disposition'],
                         'attachment; filename="example.txt.zip"')
        self.assertEqual(response['Content-type'], 'application/zip')
예제 #6
0
    def test_shows_detail_for_paste(self):
        paste = Paste.create_with_files(id=1234,
                                        files=[('example.txt', 'foo')])

        url = reverse('paste_detail', args=[paste.key.id()])
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response.context_data,
            {
                'page_title': 'example.txt',
                'paste': paste,
                'starred': None,
            },
        )
예제 #7
0
    def test_shows_list_of_pastes(self):
        for n in range(11):
            fname = 'example-%s.txt' % n
            fcontent = 'foo %s' % n
            paste = Paste.create_with_files(files=[(fname, fcontent)])
            index.add_paste(paste)

        url = reverse('paste_list')
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.template_name, 'pasty/paste_list.html')
        self.assertEqual(
            sorted(response.context_data),
            ['page_title', 'pastes', 'section', 'terms'],
        )
        self.assertEqual(response.context_data['pastes'].count, 11)
예제 #8
0
    def test_get_paste_with_one_content_file(self):
        xmas = datetime.datetime(2016, 12, 25)

        with freeze_time('2016-12-25'):
            files = [('example.txt', 'foo')]
            paste = Paste.create_with_files(id=1234, created=xmas, files=files)

        url = reverse('api_paste_detail', args=(paste.key.id(), ))

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-type'], 'application/json')
        self.assertEqual(
            response.json(), {
                u'author':
                None,
                u'created':
                u'2016-12-25T00:00:00',
                u'description':
                None,
                u'filename':
                u'example.txt',
                u'files': [{
                    u'content_type': u'text/plain',
                    u'created': u'2016-12-25T00:00:00',
                    u'filename': u'example.txt',
                    u'num_lines': 1,
                    u'path': u'pasty/2016/12/25/1234/1/example.txt',
                    u'relative_path': u'1/example.txt',
                }],
                u'fork':
                None,
                u'id':
                1234,
                u'num_files':
                1,
                u'num_lines':
                1,
                u'preview':
                u'<div class="highlight highlight__autumn"><pre><span></span>foo\n</pre></div>\n',
                u'url':
                u'/1234/',
            })
예제 #9
0
    def test_forking_from_paste_pre_fills_form(self):
        files = [('example.txt', 'foo bar baz')]
        paste = Paste.create_with_files(id=1234,
                                        description='Foo',
                                        files=files)

        url = reverse('paste_create')
        response = self.client.get(url, {'fork': paste.key.id()})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            sorted(response.context_data),
            ['form', 'page_title', 'section'],
        )
        self.assertEqual(response.context_data['page_title'], u'New paste')
        self.assertEqual(response.context_data['section'], 'paste_create')
        self.assertEqual(
            response.context_data['form'].initial,
            {
                'content': 'foo bar baz',
                'description': 'Foo',
                'filename': 'example.txt',
            },
        )