Commit b918d3c5 authored by Jens Langhammer's avatar Jens Langhammer

p2: Add More Unittests

parent bfbccb96
"""p2 public access compoennt tests"""
from django.test import TestCase
from guardian.shortcuts import get_anonymous_user
from p2.components.public_access.controller import PublicAccessController
from p2.core.models import Blob, Component, Volume
from p2.core.tests.utils import get_test_storage
from p2.lib.reflection import class_to_path
class TestPublicAccess(TestCase):
"""p2 public access compoennt tests"""
def setUp(self):
self.storage = get_test_storage()
self.volume = Volume.objects.create(
name='p2-unittest-public-access',
storage=self.storage)
self.component = Component.objects.create(
volume=self.volume,
controller_path=class_to_path(PublicAccessController))
def test_add_permissions(self):
"""Create blob and check that anonymous user gets view permission assigned"""
_blob = Blob.objects.create(
path='/test',
volume=self.volume)
# Reload from DB so we get the latest data
blob = Blob.objects.get(pk=_blob.pk)
self.assertTrue(get_anonymous_user().has_perm('p2_core.view_blob', blob))
"""p2 ui API-Key tests"""
from django.contrib.auth.models import User
from django.shortcuts import reverse
from django.test import TestCase
# from guardian.shortcuts import assign_perm
# from p2.api.forms import APIKeyForm
# from p2.api.models import APIKey, get_access_key, get_secret_key
class APIViewTests(TestCase):
"""Test API-Key related views"""
def setUp(self):
self.user, _ = User.objects.get_or_create(
username='p2-unittest')
self.client.force_login(self.user)
def test_api_key_list(self):
"""Check api-key listing"""
response = self.client.get(reverse('p2_ui:api-key-list'))
self.assertEqual(response.status_code, 200)
# def test_api_key_create(self):
# assign_perm('p2_api.add_apikey', self.user)
# form = APIKeyForm(data={
# 'name': 'test',
# 'user': str(self.user.pk),
# 'access_key': get_access_key(),
# 'secret_key': get_secret_key(),
# })
# self.assertTrue(form.is_valid())
# response = self.client.post(reverse('p2_ui:api-key-create'), data=form.cleaned_data)
# self.assertEqual(response.status_code, 200)
# print(response.content)
# print(APIKey.objects.all())
# self.assertTrue(APIKey.objects.filter(name=form.cleaned_data['name']).exists())
"""p2 ui General View tests"""
from django.contrib.auth.models import User
from django.shortcuts import reverse
from django.test import TestCase
class GeneralViewTests(TestCase):
"""Test general views"""
def setUp(self):
self.user, _ = User.objects.get_or_create(
username='p2-unittest')
self.client.force_login(self.user)
def test_general_index_view(self):
"""Test index view (authenticated)"""
response = self.client.get(reverse('p2_ui:index'))
self.assertEqual(response.status_code, 200)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment