diff --git a/core/tests/test_accounts.py b/core/tests/test_accounts.py index 6f74af3d037e32237d66be9f2d15a5c0940aa9fc..2e893235886cde7ab4959cf194eed79c2d2bd00e 100644 --- a/core/tests/test_accounts.py +++ b/core/tests/test_accounts.py @@ -89,12 +89,6 @@ class LoginTests(APITestCase): response = self.client.post(url, {'username': 'lalala', 'password': 'lalalala', 'login-type' : 'lalala'}, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - def test_return_age(self): - birth_day = (date.today() -timedelta(days = 700)) - self.assertEqual(1, get_current_age(birth_day)) - - - class RegisterTests(APITestCase): def test_create_and_recreate(self): diff --git a/core/tests/test_profile_accounts.py b/core/tests/test_profile_accounts.py new file mode 100644 index 0000000000000000000000000000000000000000..93f4214c29d41fb9f1f3048412c682f993707033 --- /dev/null +++ b/core/tests/test_profile_accounts.py @@ -0,0 +1,44 @@ +import requests_mock +from datetime import date, timedelta +from rest_framework import status +from rest_framework.test import APIClient, APITestCase +from django.contrib.auth.models import User +from django.core.exceptions import ValidationError +from StringIO import StringIO +from core.models.accounts import get_current_age,get_display_name + +class ProfileAccountsTests(APITestCase): + + def create_first_last_name(self): + user = User.objects.create_user('dummy.student2', 'dummy.student@student.com', 'lalala123') + user.first_name = 'Riansyah' + user.last_name = 'Tohamba' + return user + + def test_display_full_name(self): + self.assertEqual('Riansyah Tohamba', + get_display_name(self.create_first_last_name(),full_name=True) + ) + + def test_display_last_name_shortened(self): + self.assertEqual('Riansyah T.', + get_display_name(self.create_first_last_name(),full_name=False) + ) + + def test_display_first_name(self): + user = User.objects.create_user('dummy.student2', 'dummy.student@student.com', 'lalala123') + user.first_name = 'Riansyah' + self.assertEqual('Riansyah', get_display_name(user)) + + def test_display_last_name(self): + user = User.objects.create_user('dummy.student2', 'dummy.student@student.com', 'lalala123') + user.last_name = 'Tohamba' + self.assertEqual('Tohamba', get_display_name(user)) + + def test_display_username(self): + user = User.objects.create_user('dummy.student2', 'dummy.student@student.com', 'lalala123') + self.assertEqual('dummy.student2', get_display_name(user)) + + def test_return_age(self): + birth_day = (date.today() -timedelta(days = 700)) + self.assertEqual(1, get_current_age(birth_day))