stash
Some checks failed
Test / test (push) Failing after 1m11s

This commit is contained in:
j3d1 2024-12-05 01:31:06 +01:00
parent f7fda52fd0
commit 3400faa1d2
6 changed files with 56 additions and 4 deletions

View file

@ -1,3 +1,4 @@
name: Test
on:
pull_request:
push:
@ -16,6 +17,12 @@ jobs:
- name: Install dependencies
working-directory: core
run: pip3 install -r requirements.dev.txt
- name: Run django tests
- name: Run django tests with coverage
working-directory: core
run: python3 manage.py test
run: coverage run manage.py test
- name: Run integration tests with coverage
working-directory: core
run: python3 integration_tests/main.py
- name: Evaluate coverage
working-directory: core
run: coverage report

View file

@ -8,6 +8,7 @@ skip_covered = True
omit =
*/tests/*
*/migrations/*
integration_tests/*
core/asgi.py
core/wsgi.py
core/settings.py

View file

@ -54,9 +54,9 @@ def registerUser(request):
errors['password'] = 'Password is required'
if not email:
errors['email'] = 'Email is required'
if ExtendedUser.objects.filter(email=email).exists():
if email and ExtendedUser.objects.filter(email=email).exists():
errors['email'] = 'Email already exists'
if ExtendedUser.objects.filter(username=username).exists():
if username and ExtendedUser.objects.filter(username=username).exists():
errors['username'] = 'Username already exists'
if errors:
return Response({'errors': errors}, status=400)

View file

@ -72,6 +72,17 @@ class UserApiTest(TestCase):
self.assertEqual(ExtendedUser.objects.get(username='testuser2').email, 'test2')
self.assertTrue(ExtendedUser.objects.get(username='testuser2').check_password('test'))
def test_register_user_fail(self):
anonymous = Client()
response = anonymous.post('/api/2/register/', {'username': 'testuser2', 'password': 'test', 'email': 'test2'},
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertEqual(response.json()['username'], 'testuser2')
self.assertEqual(response.json()['email'], 'test2')
self.assertEqual(len(ExtendedUser.objects.all()), 3)
self.assertEqual(ExtendedUser.objects.get(username='testuser2').email, 'test2')
self.assertTrue(ExtendedUser.objects.get(username='testuser2').check_password('test'))
def test_register_user_duplicate(self):
anonymous = Client()
response = anonymous.post('/api/2/register/', {'username': 'testuser', 'password': 'test', 'email': 'test2'},

View file

View file

@ -0,0 +1,33 @@
import time
import os
import signal
import sys
from os import path
sys.path.append( path.dirname( path.dirname( path.abspath(__file__) ) ) )
def run():
while True:
newpid = os.fork()
if newpid == 0:
import coverage
cov = coverage.Coverage()
cov.load()
cov.start()
signal.signal(signal.SIGINT, signal.default_int_handler)
try:
from server import main
main()
except KeyboardInterrupt:
pass
cov.stop()
cov.save()
os._exit(0)
else:
return newpid
if __name__ == '__main__':
pid = run()
time.sleep(5)
os.kill(pid, signal.SIGINT)