From db997ed9db84656db0d4ebf459494485caad221b Mon Sep 17 00:00:00 2001
From: muhammad riansyah <mriansyah93@gmail.com>
Date: Wed, 30 Oct 2019 06:48:44 +0700
Subject: [PATCH 1/3] create new file test_profile_accounts and move
 test_return_age to that class

---
 core/tests/test_accounts.py         |  6 ------
 core/tests/test_profile_accounts.py | 13 +++++++++++++
 2 files changed, 13 insertions(+), 6 deletions(-)
 create mode 100644 core/tests/test_profile_accounts.py

diff --git a/core/tests/test_accounts.py b/core/tests/test_accounts.py
index 6f74af3d..2e893235 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 00000000..8777a276
--- /dev/null
+++ b/core/tests/test_profile_accounts.py
@@ -0,0 +1,13 @@
+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 Company, Supervisor, Student, get_current_age
+
+class ProfileAccountsTests(APITestCase):
+    def test_return_age(self):
+        birth_day = (date.today() -timedelta(days = 700))
+        self.assertEqual(1, get_current_age(birth_day))
-- 
GitLab


From f1c2efc7073046e048dc620593d2a281f7dcf889 Mon Sep 17 00:00:00 2001
From: muhammad riansyah <mriansyah93@gmail.com>
Date: Wed, 30 Oct 2019 07:03:29 +0700
Subject: [PATCH 2/3] init method test_display_name

---
 core/tests/test_profile_accounts.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/core/tests/test_profile_accounts.py b/core/tests/test_profile_accounts.py
index 8777a276..f4d51116 100644
--- a/core/tests/test_profile_accounts.py
+++ b/core/tests/test_profile_accounts.py
@@ -8,6 +8,9 @@ from StringIO import StringIO
 from core.models.accounts import Company, Supervisor, Student, get_current_age
 
 class ProfileAccountsTests(APITestCase):
+    def test_display_name(self):
+    	pass
+    	
     def test_return_age(self):
         birth_day = (date.today() -timedelta(days = 700))
         self.assertEqual(1, get_current_age(birth_day))
-- 
GitLab


From 5edc7fa8b1882080aa44d9328be43cec286c2cf4 Mon Sep 17 00:00:00 2001
From: muhammad riansyah <mriansyah93@gmail.com>
Date: Wed, 30 Oct 2019 09:09:52 +0700
Subject: [PATCH 3/3] coverage all imposible path for get_display_name

---
 core/tests/test_profile_accounts.py | 42 ++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/core/tests/test_profile_accounts.py b/core/tests/test_profile_accounts.py
index f4d51116..93f4214c 100644
--- a/core/tests/test_profile_accounts.py
+++ b/core/tests/test_profile_accounts.py
@@ -5,12 +5,40 @@ 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 Company, Supervisor, Student, get_current_age
+from core.models.accounts import get_current_age,get_display_name
 
 class ProfileAccountsTests(APITestCase):
-    def test_display_name(self):
-    	pass
-    	
-    def test_return_age(self):
-        birth_day = (date.today() -timedelta(days = 700))
-        self.assertEqual(1, get_current_age(birth_day))
+
+	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))
-- 
GitLab