-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuji db.py
More file actions
32 lines (25 loc) · 801 Bytes
/
uji db.py
File metadata and controls
32 lines (25 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import unittest
def koneksi_ke_db():
print('[terhubung ke db]')
def putus_koneksi_db(db):
print('[tidak terhibing ke db {}]'.format(db))
class User:
username = ''
aktif = False
def __init__(self, db, username): # using db sample
self.username = username
def set_aktif(self):
self.aktif = True
class TestUser(unittest.TestCase):
def setUp(self):
self.db = koneksi_ke_db()
self.dicoding = User(self.db, 'dicoding')
def tearDown(self):
putus_koneksi_db(self.db)
def test_user_default_not_active(self):
self.assertFalse(self.dicoding.aktif)
def test_user_is_active(self):
self.dicoding.set_aktif()
self.assertTrue(self.dicoding.aktif)
if __name__ == '__main__':
unittest.main()