-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from shanejansen/refactor/compose-mocks
Refactor/compose mocks
- Loading branch information
Showing
101 changed files
with
1,567 additions
and
874 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
Contribute a New Mock | ||
====== | ||
1. Create a new directory in [touchstone/lib/mocks](../touchstone/lib/mocks) | ||
1. Create a new class extending [Mock](../touchstone/lib/mocks/mock.py) | ||
1. Create a new [Runnable](../touchstone/lib/mocks/runnables) or [Networked Runnable](../touchstone/lib/mocks/networked_runnables) | ||
1. Add a new property to the [Mocks](../touchstone/lib/mocks/mocks.py) class, so your new mock is accessible in user test cases | ||
1. Build a concrete instance of your new mock in the [Bootstrap](../touchstone/bootstrap.py) `__build_mocks` method with its required dependencies | ||
1. Build a concrete instance of your new mock in the [Mock Factory](../touchstone/lib/mocks/mock_factory.py) with its required dependencies | ||
1. Write [unit](../tests) and [Touchstone tests](../touchstone-tests) for your new mock |
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,44 @@ | ||
Filesystem | ||
====== | ||
Used to mock a filesystem for verifying file creation and contents. | ||
|
||
Note: All paths used in the "setup" and "verify" APIs use the "defaults" directory as a base path. | ||
|
||
|
||
## Specs | ||
* Name: filesystem | ||
|
||
|
||
## Configuration | ||
N/A | ||
|
||
|
||
## Defaults Example | ||
```yaml | ||
--- | ||
directories: | ||
- path: ./filesystem/some-dir | ||
files: | ||
- ./filesystem/foo.csv | ||
- ./filesystem/bar.png | ||
- path: ./filesystem/some-dir/sub-dir | ||
files: | ||
- ./filesystem/foo.csv | ||
``` | ||
## Usage Example | ||
```python | ||
# Verify a file exists in a directory | ||
result: bool = self.mocks.filesystem.verify().file_exists('./filesystem/some-dir/foo.csv') | ||
|
||
# Verify a file's content matches as expected | ||
result: bool = self.mocks.filesystem.verify().file_matches('./filesystem/some-dir/foo.csv', given) | ||
``` | ||
If you are performing filesystem operations in your test code, you must join with `get_base_path` when referring to file paths. This returns the path to the "defaults" folder. For example: | ||
```python | ||
path = os.path.join(self.mocks.filesystem.get_base_path(), './filesystem/foo.csv') | ||
with open(path, 'rb') as data: | ||
return bytes(data.read()) | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ def given(self) -> object: | |
'lastName': 'Brown', | ||
'email': '[email protected]' | ||
} | ||
self.mocks.mysql.setup.insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, given) | ||
self.mocks.mysql.setup().insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, given) | ||
return given | ||
|
||
def when(self, given) -> object: | ||
|
@@ -48,7 +48,7 @@ def given(self) -> object: | |
'lastName': 'Brown', | ||
'email': '[email protected]' | ||
} | ||
self.mocks.http.setup.get('/jane-brown/email', given['email']) | ||
self.mocks.http.setup().get('/jane-brown/email', given['email']) | ||
return given | ||
|
||
def when(self, given) -> object: | ||
|
@@ -66,7 +66,7 @@ def then(self, given, result) -> bool: | |
expected_response = given.copy() | ||
expected_response['id'] = validation.ANY | ||
expected_row = given.copy() | ||
return validation.matches(expected_response, result) and self.mocks.mysql.verify.row_exists( | ||
return validation.matches(expected_response, result) and self.mocks.mysql.verify().row_exists( | ||
creds.MYSQL_DATABASE, | ||
creds.MYSQL_TABLE, | ||
expected_row) | ||
|
@@ -93,7 +93,7 @@ def given(self) -> object: | |
'lastName': 'Brown', | ||
'email': '[email protected]' | ||
} | ||
self.mocks.mysql.setup.insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, existing_user) | ||
self.mocks.mysql.setup().insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, existing_user) | ||
return new_info | ||
|
||
def when(self, given) -> object: | ||
|
@@ -104,7 +104,7 @@ def when(self, given) -> object: | |
return None | ||
|
||
def then(self, given, result) -> bool: | ||
return self.mocks.mysql.verify.row_exists(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, given) | ||
return self.mocks.mysql.verify().row_exists(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, given) | ||
|
||
|
||
class DeleteUser(TouchstoneTest): | ||
|
@@ -128,7 +128,7 @@ def given(self) -> object: | |
'lastName': 'Brown', | ||
'email': '[email protected]' | ||
} | ||
self.mocks.mysql.setup.insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, user) | ||
self.mocks.mysql.setup().insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, user) | ||
return user_id | ||
|
||
def when(self, given) -> object: | ||
|
@@ -140,6 +140,6 @@ def then(self, given, result) -> bool: | |
where = { | ||
'id': given | ||
} | ||
return self.mocks.rabbitmq.verify.payload_published('user.exchange', str(given), | ||
routing_key='user-deleted') and \ | ||
self.mocks.mysql.verify.row_does_not_exist(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, where) | ||
return self.mocks.rabbitmq.verify().payload_published('user.exchange', str(given), | ||
routing_key='user-deleted') and \ | ||
self.mocks.mysql.verify().row_does_not_exist(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, where) |
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,4 +1,5 @@ | ||
--- | ||
touchstone-version: 1.0.0 | ||
services: | ||
- name: my-app | ||
availability_endpoint: "/actuator/health" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
directories: | ||
- path: ./filesystem/some-dir | ||
files: | ||
- ./filesystem/foo.csv | ||
- ./filesystem/bar.png | ||
- path: ./filesystem/some-dir/sub-dir | ||
files: | ||
- ./filesystem/foo.csv |
File renamed without changes
File renamed without changes.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,3 @@ | ||
first name,last name | ||
John ,Smith | ||
Jane ,Brown |
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,27 @@ | ||
import os | ||
|
||
from touchstone.lib.touchstone_test import TouchstoneTest | ||
|
||
|
||
class FileExists(TouchstoneTest): | ||
def given(self) -> object: | ||
return './filesystem/some-dir/foo.csv' | ||
|
||
def when(self, given) -> object: | ||
return None | ||
|
||
def then(self, given, result) -> bool: | ||
return self.mocks.filesystem.verify().file_exists(given) | ||
|
||
|
||
class FileMatches(TouchstoneTest): | ||
def given(self) -> object: | ||
path = os.path.join(self.mocks.filesystem.get_base_path(), './filesystem/some-dir/sub-dir/foo.csv') | ||
with open(path, 'rb') as data: | ||
return bytes(data.read()) | ||
|
||
def when(self, given) -> object: | ||
return None | ||
|
||
def then(self, given, result) -> bool: | ||
return self.mocks.filesystem.verify().file_matches('./filesystem/some-dir/sub-dir/foo.csv', given) |
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
Oops, something went wrong.