File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 11import unittest
22import 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+
48headers = {
59'Host' : 'localhost:5000' ,
610'Accept' : 'application/json, text/plain, */*' ,
1721incorrect_string = "user_name=" + incorrect_username + "&password=" + incorrect_password
1822payload = {'' }
1923class 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' })
Original file line number Diff line number Diff line change 33from UserManager import *
44import 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
711def username ():
812 return 'admin'
@@ -21,6 +25,16 @@ def passwordr():
2125
2226
2327class 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 ()))
Original file line number Diff line number Diff line change 88import unittest
99import 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
1515class User :
@@ -34,15 +34,15 @@ def auth(self):
3434
3535class 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' ))
You can’t perform that action at this time.
0 commit comments