-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import unittest | ||
| import os | ||
|
|
||
| # Function to check if the .env file is created correctly | ||
| def check_env_file_creation(): | ||
| env_filepath = os.path.join(os.path.dirname(__file__), "../../.env") | ||
|
|
||
| # Check if the .env file exists | ||
| if not os.path.exists(env_filepath): | ||
| return False, f".env file does not exist at {env_filepath}" | ||
|
|
||
| # Check if the file contains the expected keys | ||
| with open(env_filepath, 'r') as env_file: | ||
| file_content = env_file.read() | ||
|
|
||
| if 'API_EMAIL' not in file_content or 'API_KEY' not in file_content: | ||
| return False, "The .env file is missing 'API_EMAIL' or 'API_KEY'." | ||
|
|
||
| return True, ".env file is correctly created with API credentials." | ||
|
|
||
| # Function to check if the API_EMAIL and API_KEY values are formatted correctly | ||
| def check_api_credentials(): | ||
| env_filepath = os.path.join(os.path.dirname(__file__), "../../.env") | ||
|
|
||
| with open(env_filepath, 'r') as env_file: | ||
| lines = env_file.readlines() | ||
|
|
||
| api_email = None | ||
| api_key = None | ||
|
|
||
| for line in lines: | ||
| if 'API_EMAIL' in line: | ||
| api_email = line.strip().split('=')[1].strip().replace('"', '') | ||
| elif 'API_KEY' in line: | ||
| api_key = line.strip().split('=')[1].strip().replace('"', '') | ||
|
|
||
| if not api_email or not api_key: | ||
| return False, "API_EMAIL or API_KEY is missing or formatted incorrectly." | ||
|
|
||
| # Validate the email format (basic validation for '@' symbol) | ||
| if '@' not in api_email: | ||
| return False, "API_EMAIL format is incorrect." | ||
|
|
||
| # Validate API_KEY length (assuming it's a standard length for OpenWeatherMap keys) | ||
| if len(api_key) < 32: # OpenWeatherMap keys are typically longer | ||
| return False, "API_KEY format is incorrect." | ||
|
|
||
| return True, "API credentials are valid and properly formatted." | ||
|
|
||
| class TestDataFormatConsistency(unittest.TestCase): | ||
|
|
||
| # Test if the .env file is created correctly | ||
| def test_env_file_creation(self): | ||
| valid, message = check_env_file_creation() | ||
| self.assertTrue(valid, message) | ||
|
|
||
| # Test if the API credentials are correct | ||
| def test_api_credentials(self): | ||
| valid, message = check_api_credentials() | ||
| self.assertTrue(valid, message) | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |