Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding mocks and unit tests for socket code #63

Conversation

nsarras
Copy link
Contributor

@nsarras nsarras commented Jul 29, 2023

No description provided.

@nsarras nsarras requested a review from a team as a code owner July 29, 2023 02:38
@nsarras
Copy link
Contributor Author

nsarras commented Jul 31, 2023

Pycode style issues need to be resolved

dss_datamover/socket_communication.py:404:1: W391 blank line at end of file
dss_datamover/tests/conftest.py:112:33: E225 missing whitespace around operator
dss_datamover/tests/conftest.py:126:28: E261 at least two spaces before inline comment
dss_datamover/tests/conftest.py:127:30: E261 at least two spaces before inline comment
dss_datamover/tests/conftest.py:149:44: E203 whitespace before ':'
dss_datamover/tests/conftest.py:160:48: E203 whitespace before ':'
dss_datamover/tests/conftest.py:160:50: E202 whitespace before ']'
dss_datamover/tests/conftest.py:163:48: E203 whitespace before ':'
dss_datamover/tests/conftest.py:196:1: W293 blank line contains whitespace
dss_datamover/tests/conftest.py:205:1: W293 blank line contains whitespace
dss_datamover/tests/conftest.py:209:1: E302 expected 2 blank lines, found 1
dss_datamover/tests/conftest.py:217:29: E231 missing whitespace after ':'
dss_datamover/tests/conftest.py:221:1: W293 blank line contains whitespace
dss_datamover/tests/conftest.py:224:1: W293 blank line contains whitespace
dss_datamover/tests/conftest.py:227:1: W293 blank line contains whitespace
dss_datamover/tests/conftest.py:246:1: E302 expected 2 blank lines, found 1
dss_datamover/tests/conftest.py:308:1: E302 expected 2 blank lines, found 1
dss_datamover/tests/conftest.py:311:1: W293 blank line contains whitespace
dss_datamover/tests/conftest.py:321:1: W293 blank line contains whitespace
dss_datamover/tests/conftest.py:326:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:44:1: E302 expected 2 blank lines, found 1
dss_datamover/tests/test_socket.py:46:32: E226 missing whitespace around arithmetic operator
dss_datamover/tests/test_socket.py:52:1: E302 expected 2 blank lines, found 1
dss_datamover/tests/test_socket.py:58:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:65:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:75:20: E712 comparison to True should be 'if cond is True:' or 'if cond:'
dss_datamover/tests/test_socket.py:78:20: E712 comparison to True should be 'if cond is True:' or 'if cond:'
dss_datamover/tests/test_socket.py:84:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:86:20: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
dss_datamover/tests/test_socket.py:87:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:95:48: E231 missing whitespace after ':'
dss_datamover/tests/test_socket.py:96:24: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
dss_datamover/tests/test_socket.py:97:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:104:20: E712 comparison to True should be 'if cond is True:' or 'if cond:'
dss_datamover/tests/test_socket.py:117:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:121:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:139:60: E226 missing whitespace around arithmetic operator
dss_datamover/tests/test_socket.py:225:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:229:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:235:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:238:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:244:20: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
dss_datamover/tests/test_socket.py:249:20: E712 comparison to True should be 'if cond is True:' or 'if cond:'
dss_datamover/tests/test_socket.py:251:20: E712 comparison to True should be 'if cond is True:' or 'if cond:'
dss_datamover/tests/test_socket.py:258:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:260:20: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
dss_datamover/tests/test_socket.py:261:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:269:44: E231 missing whitespace after ':'
dss_datamover/tests/test_socket.py:270:20: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
dss_datamover/tests/test_socket.py:272:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:280:20: E712 comparison to True should be 'if cond is True:' or 'if cond:'
dss_datamover/tests/test_socket.py:297:1: W293 blank line contains whitespace
dss_datamover/tests/test_socket.py:317:60: E226 missing whitespace around arithmetic operator

return True

def recv(self):
# TODO: finish building out MockSocket class
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

def __init__(self):
self.host = "xxx.xxxx.xxxx.xxxx"
self.port = "xxxx"
STATUS_NORMAL = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these DEFAULTS should be near the top of the file

if not self.data:
return ret
if self.data_index >= len(self.data):
raise Exception
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we raise a specific exception here?

return list(self.data.items())
else:
ret = []
for k in self.data.keys():
Copy link
Contributor Author

@nsarras nsarras Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the specific key should only show up once. You can check to see if it is a nested dict, if so, just the items() method will pack the dict into a list of tuples

return self.data[k].items() if isinstance(self.data[k], dict) else [(k, self.data[k])]


@pytest.mark.usefixtures("get_mock_clientsocket")
@pytest.mark.usefixtures("get_pytest_configs", "get_config_dict", "get_mock_logger", "get_header_length")
class TestSocketCommunication():
Copy link
Contributor Author

@nsarras nsarras Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on the tests, only recommendation I have is to consolidate them more, meaning that if there are tests that test the positive & negative & corner cases of the same functionality, such as socket connect. Then all of those variations should be within that same test case

@@ -55,7 +55,7 @@ def __init__(self, config, logger=None):
self.logger = logger
self.config = config
self.socket = None
self.last_exception_log_time = datetime.now()
self.last_exception_log_time = datetime.min
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change is not necessary please remove

@@ -232,7 +232,7 @@ def __init__(self, config, logger=None):
self.logger = logger
self.config = config
self.client_socket = None
self.last_exception_log_time = datetime.now()
self.last_exception_log_time = datetime.min
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change is not necessary please remove

@nsarras
Copy link
Contributor Author

nsarras commented Aug 7, 2023

Pycode style issue needs to be resolved ; dss_datamover/socket_communication.py:404:1: W391 blank line at end of file

@nsarras
Copy link
Contributor Author

nsarras commented Aug 7, 2023

Sonar Cloud security hotspot dss_datamover/tests/conftest.py line 209. Make sure ip address is safe

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.17) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@nsarras
Copy link
Contributor Author

nsarras commented Aug 22, 2023

Eric, please recreate PR under your own user and pull in master branch

@nsarras
Copy link
Contributor Author

nsarras commented Sep 7, 2023

closing, as Eric has included changes in another PR

@nsarras nsarras closed this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Datamover Unittest] Build smoke tests and mocks for client/server socket modules
2 participants