Skip to content

Commit

Permalink
#150: Combine config test username and password
Browse files Browse the repository at this point in the history
- This will make it more convenient to use through the tests in the repo
  • Loading branch information
MRichards99 committed Nov 10, 2020
1 parent 7455c48 commit 572e89c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
3 changes: 1 addition & 2 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"generate_swagger": false,
"host": "127.0.0.1",
"port": "5000",
"test_username": "root",
"test_password": "pw",
"test_user_credentials": {"username": "root", "password": "pw"},
"test_mechanism": "simple"
}
12 changes: 3 additions & 9 deletions datagateway_api/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,11 @@ def get_port(self):
except KeyError:
sys.exit("Missing config value, port")

def get_test_username(self):
def get_test_user_credentials(self):
try:
return self.config["test_username"]
return self.config["test_user_credentials"]
except KeyError:
sys.exit("Missing config value, test_username")

def get_test_password(self):
try:
return self.config["test_password"]
except KeyError:
sys.exit("Missing config value, test_password")
sys.exit("Missing config value, test_user_credentials")

def get_test_mechanism(self):
try:
Expand Down
22 changes: 6 additions & 16 deletions test/icat/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,14 @@ def test_invalid_port(self, invalid_config):
invalid_config.get_icat_url()


class TestGetTestUsername:
def test_valid_test_username(self, valid_config):
test_username = valid_config.get_test_username()
assert test_username == "root"
class TestGetTestUserCredentials:
def test_valid_test_user_credentials(self, valid_config):
test_user_credentials = valid_config.get_test_user_credentials()
assert test_user_credentials == {"username": "root", "password": "pw"}

def test_invalid_test_username(self, invalid_config):
def test_invalid_test_user_credentials(self, invalid_config):
with pytest.raises(SystemExit):
invalid_config.get_test_username()


class TestGetTestPassword:
def test_valid_test_password(self, valid_config):
test_password = valid_config.get_test_password()
assert test_password == "pw"

def test_invalid_test_password(self, invalid_config):
with pytest.raises(SystemExit):
invalid_config.get_test_password()
invalid_config.get_test_user_credentials()


class TestGetTestMechanism:
Expand Down

0 comments on commit 572e89c

Please sign in to comment.