コード例 #1
0
ファイル: ajax.py プロジェクト: 9h37/pompadour-wiki
def add_wiki(request, dform=None):
    dajax = Dajax()

    if not dform:
        return dajax.json()

    wiki = Wiki()
    wiki.name = dform['add-wiki-name'].encode('utf-8')
    wiki.slug = slugify(wiki.name)
    wiki.description = dform['add-wiki-desc'].encode('utf-8')
    wiki.gitdir = os.path.join(settings.WIKI_GIT_DIR, wiki.slug)

    try:
        w = Wiki.objects.get(slug=wiki.slug)

        dajax.assign('#error', 'innerHTML',
                    render_to_string('error.html',
                                     {'error': ugettext(u'Can\'t add wiki, another wiki with the same name ({0}) already exists.').format(wiki.name)},
                                     context_instance=RequestContext(request)
                    )
        )

    except Wiki.DoesNotExist:
        wiki.create_repo(request.user)
        wiki.save()

        dajax.redirect(reverse('view-page', args=[wiki.slug, '']))

    return dajax.json()
コード例 #2
0
ファイル: tests.py プロジェクト: 9h37/pompadour-wiki
class FileManagerTest(TestCase):
    """
    Test Wiki views
    """

    def setUp(self):
        # Create User
        self.user = UserTest.get_or_create('*****@*****.**', 'gerard', u'Gérard', u'Test', '*****@*****.**')

        # Authenticate user
        self.client = Client()
        self.client.login(username=self.user.username, password='******')

        # Create Wiki
        self.wiki = Wiki()
        self.wiki.name = u'Wiki Test Héhé'
        self.wiki.slug = slugify(self.wiki.name)
        self.wiki.description = u'Wiki de test héhé'
        self.wiki.gitdir = '/tmp/test-wiki/'

        self.wiki.create_repo()

        self.wiki.save()

    def tearDown(self):
        import subprocess
        subprocess.call(['rm', '-rf', self.wiki.gitdir])

    def test_01_index(self):
        response = self.client.get('/files/wiki-test-hehe/tree/')

        self.assertEqual(response.status_code, 200)

    def test_02_upload(self):
        # Upload that script
        import inspect

        with open(inspect.getfile(inspect.currentframe())) as fp:
            response = self.client.post('/files/wiki-test-hehe/upload', {
                'format': 'json',
                'path': '/',
                'doc': fp
            })

        # Make sure the file was uploaded
        self.assertEqual(response.status_code, 200)

        # Make sure that it returns the correct URL
        data = json.loads(response.content)
        self.assertEqual(data['url'], 'tests.py')

        # And make sure the file is accessible
        response = self.client.get('/files/wiki-test-hehe/view/tests.py')
        self.assertEqual(response.status_code, 200)
コード例 #3
0
ファイル: ajax.py プロジェクト: linkdd/pompadour-wiki
def add_wiki(request, dform=None):
    dajax = Dajax()

    if not dform:
        return dajax.json()

    wiki = Wiki()
    wiki.name = dform['add-wiki-name'].encode('utf-8')
    wiki.slug = slugify(wiki.name)
    wiki.description = dform['add-wiki-desc'].encode('utf-8')
    wiki.gitdir = os.path.join(settings.WIKI_GIT_DIR, wiki.slug)

    try:
        w = Wiki.objects.get(slug=wiki.slug)

        dajax.assign('#error', 'innerHTML',
                    render_to_string('error.html',
                                     {'error': ugettext(u'Can\'t add wiki, another wiki with the same name ({0}) already exists.').format(wiki.name)},
                                     context_instance=RequestContext(request)
                    )
        )

    except Wiki.DoesNotExist:
        os.environ['GIT_AUTHOR_NAME'] = u'{0} {1}'.format(request.user.first_name, request.user.last_name).encode('utf-8')
        os.environ['GIT_AUTHOR_EMAIL'] = request.user.email
        os.environ['USERNAME'] = str(request.user.username)

        wiki.create_repo()

        del(os.environ['GIT_AUTHOR_NAME'])
        del(os.environ['GIT_AUTHOR_EMAIL'])
        del(os.environ['USERNAME'])

        wiki.save()

        dajax.redirect(reverse('view-page', args=[wiki.slug, '']))

    return dajax.json()
コード例 #4
0
ファイル: tests.py プロジェクト: 9h37/pompadour-wiki
    def setUp(self):
        # Create User
        self.user = UserTest.get_or_create('*****@*****.**', 'gerard', u'Gérard', u'Test', '*****@*****.**')

        # Authenticate user
        self.client = Client()
        self.client.login(username=self.user.username, password='******')

        # Create Wiki
        self.wiki = Wiki()
        self.wiki.name = u'Wiki Test Héhé'
        self.wiki.slug = slugify(self.wiki.name)
        self.wiki.description = u'Wiki de test héhé'
        self.wiki.gitdir = '/tmp/test-wiki/'

        self.wiki.create_repo()

        self.wiki.save()
コード例 #5
0
ファイル: tests.py プロジェクト: 9h37/pompadour-wiki
class WikiTest(TestCase):
    """
    Test Wiki views
    """

    def setUp(self):
        # Create User
        self.user = UserTest.get_or_create('*****@*****.**', 'gerard', u'Gérard', u'Test', '*****@*****.**')

        # Authenticate user
        self.client = Client()
        self.client.login(username=self.user.username, password='******')

        # Create Wiki
        self.wiki = Wiki()
        self.wiki.name = u'Wiki Test Héhé'
        self.wiki.slug = slugify(self.wiki.name)
        self.wiki.description = u'Wiki de test héhé'
        self.wiki.gitdir = '/tmp/test-wiki/'

        self.wiki.create_repo()

        self.wiki.save()

    def tearDown(self):
        import subprocess
        subprocess.call(['rm', '-rf', self.wiki.gitdir])

    def test_01_home(self):
        response = self.client.get('/')

        self.assertEqual(response.status_code, 200)

    def test_02_create_wiki(self):
        self.assertEqual(Wiki.objects.count(), 1)

    def test_03_view_page(self):
        response = self.client.get('/wiki/wiki-test-hehe/Home')

        self.assertEqual(response.status_code, 200)

    def test_04_edit_page(self):
        # Verify the page doesn't exist
        response = self.client.get(u'/wiki/wiki-test-hehe/Pagé')

        self.assertEqual(response.status_code, 302) # if the page is not found, the wiki redirect the user to an edit page

        # Check GET on edit page
        response = self.client.get(u'/wiki/wiki-test-hehe/Pagé/edit')

        self.assertEqual(response.status_code, 200)

        # Now send data
        response = self.client.post(u'/wiki/wiki-test-hehe/Pagé/edit', {
            'path': u'Pagé',
            'content': u'Test héhé',
            'comment': u'Commentaire de test héhé',
        })

        self.assertEqual(response.status_code, 302) # after an edit, the wiki redirect the user to the page

        # And now, check that the new page exists
        response = self.client.get(u'/wiki/wiki-test-hehe/Pagé')

        self.assertEqual(response.status_code, 200)

    def test_05_remove_page(self):
        self.test_04_edit_page()

        # Remove page

        response = self.client.get(u'/wiki/wiki-test-hehe/Pagé/remove')

        self.assertEqual(response.status_code, 302) # On delete, the user is redirected to wiki's home

        # Verify the page doesn't exist anymore
        
        response = self.client.get(u'/wiki/wiki-test-hehe/Pagé')

        self.assertEqual(response.status_code, 302) # if the page is not found, the wiki redirect the user to an edit page

    def test_06_last_edits(self):
        self.test_04_edit_page()

        le = LastEdits(Wiki.objects.all())

        self.assertTrue({'filename': u'Pagé.md', 'wiki': self.wiki} in le)
        self.assertTrue({'filename': u'Home.md', 'wiki': self.wiki} in le)

    def test_07_index(self):
        response = self.client.get('/')

        self.assertEqual(response.status_code, 200)

    def test_08_search(self):
        response = self.client.post('/search', {
            'search-query': u'test héhé',
        })

        self.assertEqual(response.status_code, 200)

    def test_09_tag(self):
        self.test_04_edit_page()

        tag = Tag()
        tag.page = u'wiki-test-hehe/Pagé'
        tag.tag = 'test'
        tag.save()

        response = self.client.get('/tag/test')

        self.assertEqual(response.status_code, 200)