fail build if coverage below 90% (#509)

* fail build if coverage below 95

* add a few test and relax to 90% coverage

* add additional tests for user commands
This commit is contained in:
Bernhard Posselt 2017-08-06 19:50:49 +02:00 коммит произвёл GitHub
Родитель 78e6aea763
Коммит 78dd83ef52
8 изменённых файлов: 94 добавлений и 2 удалений

Просмотреть файл

@ -22,6 +22,7 @@ lint:
test: lint
$(yarn) test
$(coverage) run --source=nextcloudappstore $(manage-script) test --settings nextcloudappstore.settings.development
$(coverage) report --fail-under 90
.PHONY: resetup
resetup:

Просмотреть файл

@ -3,13 +3,14 @@ from django.contrib.auth import get_user_model
from rest_framework.authtoken.models import Token
def create_user(username, password, email):
def create_user(username: str, password: str, email: str, verify: bool = True):
user = get_user_model().objects.create_user(
username=username,
password=password,
email=email,
)
verify_email(username, email)
if verify:
verify_email(username, email)
return user

Просмотреть файл

Просмотреть файл

@ -0,0 +1,13 @@
from django.contrib.auth import get_user_model
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
class CreateUserCommandTest(TestCase):
def test_create_user(self):
call_command('createtestuser', '--username=cmdtest',
'--password=cmdtest', '--email=test@test.com',
stdout=StringIO())
user = get_user_model().objects.get(username='cmdtest')
self.assertEqual('test@test.com', user.email)

Просмотреть файл

@ -0,0 +1,18 @@
from django.contrib.auth import get_user_model
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
class SetDefaultAdminPasswordCommandTest(TestCase):
fixtures = [
'admin.json',
]
def test_set_password(self):
user = get_user_model().objects.get(username='admin')
user.set_password('different')
user.save()
call_command('setdefaultadminpassword', stdout=StringIO())
user.refresh_from_db()
self.assertTrue(user.check_password('admin'))

Просмотреть файл

@ -0,0 +1,21 @@
from allauth.socialaccount.models import SocialApp
from django.contrib.sites.models import Site
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
class SetupSocialCommandTest(TestCase):
def test_setup(self):
call_command('setupsocial', '--github-secret=tres',
'--github-client-id=sec', '--domain=local.com',
stdout=StringIO())
site = Site.objects.all()[0]
app = SocialApp.objects.get(provider='github')
self.assertEqual('local.com', site.domain)
self.assertEqual('Nextcloud App Store', site.name)
self.assertEqual('GitHub', app.name)
self.assertEqual('tres', app.secret)
self.assertEqual('sec', app.client_id)

Просмотреть файл

@ -0,0 +1,15 @@
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
from rest_framework.authtoken.models import Token
from nextcloudappstore.user.facades import create_user
class UpdateTokenCommandTest(TestCase):
def test_update_token(self):
user = create_user('cmdtest', 'cmdtest', 'cmdtest@test.com')
call_command('updatetoken', '--username=cmdtest', '--token=token',
stdout=StringIO())
token = Token.objects.get(user=user)
self.assertEqual('token', token.key)

Просмотреть файл

@ -0,0 +1,23 @@
from allauth.account.models import EmailAddress
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
from nextcloudappstore.user.facades import create_user
class VerifyEmailCommandTest(TestCase):
def test_verify(self):
mail = 'cmdtest@test.com'
username = 'cmdtest'
user = create_user(username, username, mail, False)
with self.assertRaises(EmailAddress.DoesNotExist):
EmailAddress.objects.get(user=user, email=mail)
call_command('verifyemail', '--username=cmdtest',
'--email=cmdtest@test.com',
stdout=StringIO())
email = EmailAddress.objects.get(user=user, email=mail)
self.assertTrue(email.verified)