Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Create profile test #90

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class SemesterWithProblemsSerializer(serializers.ModelSerializer):
class Meta:
model = models.Semester
fields = '__all__'
read_only_fields = ['semesterpublication_set',
'unspecifiedpublication_set']

def create(self, validated_data):
all_series_data = validated_data.pop('series_set')
Expand Down
1 change: 1 addition & 0 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from rest_framework import exceptions, status, viewsets, mixins
from rest_framework.decorators import action

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.response import Response
from webstrom import settings
Expand Down
2 changes: 2 additions & 0 deletions problem_database/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Create your views here.
from rest_framework import status, viewsets
from rest_framework.decorators import action, api_view
from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.response import Response
from rest_framework.filters import SearchFilter
from django_filters.rest_framework import DjangoFilterBackend
Expand Down
2 changes: 1 addition & 1 deletion user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class User(AbstractBaseUser, PermissionsMixin):
default=False,
help_text='Umožňuje prihlásiť sa do administrácie.',)
is_active = models.BooleanField(
verbose_name='aktnívny',
verbose_name='aktívny',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch 🚀

default=True,
help_text='Označuje, či je používateľ aktívny. '
'Používa sa namiesto mazania účtov.',)
Expand Down
95 changes: 95 additions & 0 deletions user/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from django.contrib.auth.models import User
from rest_framework.test import APITestCase
from user.models import User
from django.test import Client
from competition.forms import ProfileUpdateForm
from user.forms import UserChangeForm, NameUpdateForm
from personal.models import County, District, School, Profile
from personal.serializers import ProfileSerializer

class UpdateUserTest(APITestCase):
def test_user_change_form(self):
form = UserChangeForm(data = {
'email': '[email protected]',
'password': 'Aa123456'
})
self.assertTrue(form.is_valid())

def test_wrong_email(self):
form = UserChangeForm(data = {
'email': '123',
'password': 'Aa123456'
})
self.assertFalse(form.is_valid())

def test_name_change_form(self):
form = NameUpdateForm(data = {
'first_name': 'Jožko',
'last_name': 'Mrkvička'
})
self.assertTrue(form.is_valid())

def test_profile_update_form(self):
form = ProfileUpdateForm(data = {
'first_name':'Účastník',
'last_name':'Matikovský',
'user' : {
'email':'[email protected]', 'password':'1234abcd'
},
'nickname' : 'ucastnik',
'school' : {
'name' : 'Gymnázium',
'district' : {
'name' : 'Košice I',
'county': {'name' : 'Košický kraj'}
},
'street' : 'Poštová 9',
'city': 'Košice',
'zip_code' : '04001'
}, 'year_of_graduation': 2025,
'phone' : '+421901234567',
'parent_phone' : '+421987654321',
'gdpr' : True
})

self.assertTrue(form.is_valid())

def setUp(self):
self.client = Client()
user = User.objects.create(email="[email protected]", password="1234abcd")

county = County.objects.create(name="Košický kraj")
district = District.objects.create(name="Košice I", county=county)
school = School.objects.create(name='Gymnázium', district=district, street='Poštová 9', city='Košice', zip_code='04001')

self.profile = Profile.objects.create(
first_name='Účastník', last_name='Matikovský', user = user,
nickname = 'ucastnik', school = school, year_of_graduation = 2025,
phone = '+421901234567', parent_phone = '+421987654321', gdpr = True
)

#self.superuser = User.objects.create_superuser('veduci','1234abcd')
#self.veduci_log_in = {'username':'veduci', 'password':'1234abcd'}
#self.client.post('/user/login/',self.veduci_log_in)

self.profiledata = ProfileSerializer(self.profile)
self.userdata = {
'first_name': 'Účastník',
'last_name': 'Matikovský'
}

self.profiledata.update({'first_name': 'Meno', 'last_name': 'Priezvisko'})
self.userdata.update({'first_name': 'Meno', 'last_name': 'Priezvisko'})

self.data = {
'user' : self.userdata,
'profile' : self.profiledata
}

self.log_in = {'nickname':'ucastnik', 'password':'1234abcd'}

def test_can_update_profile(self):
response_log_in = self.client.post('/user/login/',self.log_in)
self.assertEqual(response_log_in.status_code,200)
response = self.client.post('/user/profile/update/', self.data)
self.assertEqual(response.status_code, 200)