-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switching to logger rather than print
- Loading branch information
Showing
8 changed files
with
77 additions
and
37 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
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
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
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
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
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
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
43 changes: 26 additions & 17 deletions
43
src/lambda_codebase/account_processing/tests/test_account_file_processing.py
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 |
---|---|---|
@@ -1,24 +1,33 @@ | ||
""" | ||
Tests the account file processing lambda | ||
""" | ||
import unittest | ||
from ..process_account_files import process_account, process_account_list, get_details_from_event | ||
|
||
from ..process_account_files import process_account, process_account_list | ||
class SuccessTestCase(unittest.TestCase): | ||
# pylint: disable=W0106 | ||
def test_process_account_when_account_exists(self): | ||
test_account = {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname"} | ||
account_lookup = {"mytestaccountname":1234567890} | ||
self.assertDictEqual(process_account(account_lookup, test_account), {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname", "Id": 1234567890, "needs_created": False}) | ||
|
||
# pylint: disable=W0106 | ||
def test_process_account_when_account_exists(): | ||
test_account = {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname"} | ||
account_lookup = {"mytestaccountname":1234567890} | ||
assert process_account(account_lookup, test_account) == {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname", "Id": 1234567890, "needs_created": False} | ||
def test_process_account_when_account_doesnt_exist(self): | ||
test_account = {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname"} | ||
account_lookup = {"mydifferentaccount":1234567890} | ||
self.assertDictEqual(process_account(account_lookup, test_account), {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname", "needs_created": True}) | ||
|
||
def test_process_account_when_account_doesnt_exist(): | ||
test_account = {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname"} | ||
account_lookup = {"mydifferentaccount":1234567890} | ||
assert process_account(account_lookup, test_account) == {"alias": "MyCoolAlias", "account_full_name":"mytestaccountname", "needs_created": True} | ||
def test_process_account_list(self): | ||
all_accounts = [{"Name":"mytestaccountname", "Id":1234567890}] | ||
accounts_in_file = [{"account_full_name": "mytestaccountname"}, {"account_full_name": "mynewaccountname"}] | ||
self.assertListEqual(process_account_list(all_accounts, accounts_in_file), [ | ||
{"account_full_name":"mytestaccountname", "needs_created": False, "Id": 1234567890}, | ||
{"account_full_name":"mynewaccountname", "needs_created": True} | ||
]) | ||
|
||
def test_process_account_list(): | ||
all_accounts = [{"Name":"mytestaccountname", "Id":1234567890}] | ||
accounts_in_file = [{"account_full_name": "mytestaccountname"}, {"account_full_name": "mynewaccountname"}] | ||
assert process_account_list(all_accounts, accounts_in_file) == [ | ||
{"account_full_name":"mytestaccountname", "needs_created": False, "Id": 1234567890}, | ||
{"account_full_name":"mynewaccountname", "needs_created": True} | ||
] | ||
class FailureTestCase(unittest.TestCase): | ||
# pylint: disable=W0106 | ||
def test_event_parsing(self): | ||
sample_event = {} | ||
with self.assertRaises(ValueError) as _error: | ||
get_details_from_event(sample_event) | ||
self.assertEqual(str(_error.exception), "No S3 Event details present in event trigger") |