Skip to content

Commit 38843f8

Browse files
committed
add testing.mysqld to existing tests and change name of file to user_test.py
1 parent 613ee6c commit 38843f8

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

components/core/tests/Bassa_endpoint_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import unittest
22
import requests
33

4+
import testing.mysqld
5+
# Generate MYSQLD class which shares the generated database
6+
MYSQLD = testing.mysqld.MysqldFactory(cache_initialized_db=True)
7+
48
headers = {
59
'Host': 'localhost:5000',
610
'Accept': 'application/json, text/plain, */*',
@@ -17,6 +21,17 @@
1721
incorrect_string="user_name="+incorrect_username+"&password="+incorrect_password
1822
payload = {''}
1923
class TestFlaskAPIUsingRequests(unittest.TestCase):
24+
def setUp(self):
25+
# Use the generated MYSQLD class instead of testing.mysqld
26+
self.mysqld = MYSQLD()
27+
28+
def tearDown(self):
29+
self.mysqld.stop()
30+
31+
def tearDownModule(self):
32+
# clear cached database at end of tests
33+
MYSQLD.clear_cache()
34+
2035
def test_api_login_returns_auth_level(self):
2136
resp = requests.post('http://localhost:5000/api/login',correct_string,headers=headers)
2237
self.assertEqual(resp.json(),{u'auth': u'0'})

components/core/tests/login_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from UserManager import *
44
import unittest
55

6+
import testing.mysqld
7+
# Generate MYSQLD class which shares the generated database
8+
MYSQLD = testing.mysqld.MysqldFactory(cache_initialized_db=True)
9+
610

711
def username():
812
return 'admin'
@@ -21,6 +25,16 @@ def passwordr():
2125

2226

2327
class Test(unittest.TestCase):
28+
def setUp(self):
29+
# Use the generated MYSQLD class instead of testing.mysqld
30+
self.mysqld = MYSQLD()
31+
32+
def tearDown(self):
33+
self.mysqld.stop()
34+
35+
def tearDownModule(self):
36+
# clear cached database at end of tests
37+
MYSQLD.clear_cache()
2438

2539
def test_incorrect_login(self):
2640
self.assertEqual(False, user_login(username(), password()))

components/core/tests/User_tests.py renamed to components/core/tests/user_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import unittest
99
import testing.mysqld
1010

11-
# Generate Mysqld class which shares the generated database
12-
Mysqld = testing.mysqld.MysqldFactory(cache_initialized_db=True)
11+
# Generate MYSQLD class which shares the generated database
12+
MYSQLD = testing.mysqld.MysqldFactory(cache_initialized_db=True)
1313

1414

1515
class User:
@@ -34,15 +34,15 @@ def auth(self):
3434

3535
class Test(unittest.TestCase):
3636
def setUp(self):
37-
# Use the generated Mysqld class instead of testing.mysqld.Mysqld
38-
self.mysqld = Mysqld()
37+
# Use the generated MYSQLD class instead of testing.mysqld
38+
self.mysqld = MYSQLD()
3939

4040
def tearDown(self):
4141
self.mysqld.stop()
4242

4343
def tearDownModule(self):
4444
# clear cached database at end of tests
45-
Mysqld.clear_cache()
45+
MYSQLD.clear_cache()
4646

4747
def test_check_existing_username(self):
4848
self.assertEqual(True, check_user_name('rand'))

0 commit comments

Comments
 (0)