Fakultas Ilmu Komputer UI

Commit 8f9dfd50 authored by Bimo Iman Smartadi's avatar Bimo Iman Smartadi
Browse files

[REFACTOR] Changed error message to a variable

parent 6968ab82
from django.test import TestCase from django.test import TestCase
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, RUNNING_TEXT from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, RUNNING_TEXT
# from registrasi.models import User from registrasi.models import BisaGoUser
from django.contrib.auth.models import User from django.contrib.auth.models import User
import tempfile import tempfile
# Create your tests here. # Create your tests here.
class Informasi_Fasilitas_Test(TestCase): class InformasiFasilitasTest(TestCase):
not_null_constraint_failed = 'NOT NULL constraint failed'
def test_models_lokasi_not_created(self): def test_models_lokasi_not_created(self):
with self.assertRaises(IntegrityError) as cm: with self.assertRaises(IntegrityError) as cm:
obj = Lokasi(name=None) obj = Lokasi(name=None)
obj.save(); obj.save();
self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed')) self.assertTrue(str(cm.exception).startswith(not_null_constraint_failed))
def test_models_create_new_lokasi(self): def test_models_create_new_lokasi(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name image = tempfile.NamedTemporaryFile(suffix=".jpg").name
...@@ -31,7 +32,7 @@ class Informasi_Fasilitas_Test(TestCase): ...@@ -31,7 +32,7 @@ class Informasi_Fasilitas_Test(TestCase):
with self.assertRaises(IntegrityError) as cm: with self.assertRaises(IntegrityError) as cm:
obj = Fasilitas(lokasi=None) obj = Fasilitas(lokasi=None)
obj.save(); obj.save();
self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed')) self.assertTrue(str(cm.exception).startswith(not_null_constraint_failed))
def test_models_create_new_fasilitas(self): def test_models_create_new_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name image = tempfile.NamedTemporaryFile(suffix=".jpg").name
...@@ -68,7 +69,7 @@ class Informasi_Fasilitas_Test(TestCase): ...@@ -68,7 +69,7 @@ class Informasi_Fasilitas_Test(TestCase):
with self.assertRaises(IntegrityError) as cm: with self.assertRaises(IntegrityError) as cm:
obj = Komentar(fasilitas=None) obj = Komentar(fasilitas=None)
obj.save(); obj.save();
self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed')) self.assertTrue(str(cm.exception).startswith(not_null_constraint_failed))
def test_models_create_new_komentar(self): def test_models_create_new_komentar(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name image = tempfile.NamedTemporaryFile(suffix=".jpg").name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment