Skip to content

Commit 9ee3ca0

Browse files
author
Pipeline
committed
F - implemented new FileUtilities methods
d - improved README.md
1 parent 8540add commit 9ee3ca0

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

Infrastructure/FileUtilities.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import imp
22
import os
33
import sys
4+
from os.path import exists
45

56

67
class FileUtilities(object):
@@ -14,4 +15,17 @@ def main_is_frozen():
1415
def get_root_path():
1516
if FileUtilities.main_is_frozen():
1617
return os.path.dirname(sys.executable)
17-
return os.path.dirname(os.path.realpath(__file__))
18+
return os.path.dirname(os.path.realpath(__file__))
19+
20+
def file_exists(self, path):
21+
return exists(path)
22+
23+
def create_file(self, filePath):
24+
f = open(filePath, "w")
25+
# f.write("Woops! I have deleted the content!")
26+
f.close()
27+
28+
# def __init__(self, file_utility):
29+
#
30+
# if not file_utility.file_exists():
31+
# file_utility.create_file("path to file")

Infrastructure/SettingsManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_dojo_mob_station_name(self):
104104
return self.code_dojo.get("mob station name", "NewName")
105105

106106
def get_dojo_session_id(self):
107-
return self.code_dojo.get("session id","1337")
107+
return self.code_dojo.get("session id", "1337")
108108

109109
def get_dojo_topic_root(self):
110110
return self.code_dojo.get("topic root", "MobTimer")

MobTimer.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ broker = localhost
3939
port = 1883
4040
mob station name = NewName
4141
session id = 1337
42-
topic root = MobTimer
42+
topic root = MobTimer
43+
44+
[EVENT LOGGING]
45+
enabled = True
46+
log file name = MobTimer.log

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Run BuildMobTimer.py
3131

3232
# Kanban
3333
* Make it easy to track time actually working
34-
* enable/disable time tracking via a config file
35-
* define time types in the conf file
34+
* enable/disable time tracking via the config file
35+
* define time types in the config file
3636
* log when mobber added and removed
3737
* replace continue button with tracking type
3838
* Create plugin infrastructure (to interface with Clockify, etc.)

tests/Infrastructure/EventLoggingManager/__init__.py

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import unittest
2+
from unittest.mock import MagicMock
3+
from approvaltests.approvals import verify
4+
5+
from Infrastructure.FileUtilities import FileUtilities
6+
from Infrastructure.SettingsManager import SettingsManager
7+
8+
9+
class EventLoggingManager:
10+
11+
def __init__(self, file_utility):
12+
file_path = FileUtilities.get_root_path() + "\\filename.txt"
13+
if not file_utility.file_exists(file_path):
14+
# file_utility.
15+
file_utility.create_file(file_path)
16+
17+
18+
class TestsEventLoggingManager(unittest.TestCase):
19+
20+
def test_log_file_should_be_created_if_doesnt_exist(self):
21+
# Options: Mocks, Fake Files
22+
23+
# Arrange: Make sure the file does not exist
24+
file_utility = FileUtilities()
25+
file_utility.file_exists = MagicMock(return_value=False)
26+
file_utility.create_file = MagicMock(return_value=True)
27+
# Act: Instantiate EventLoggingManager
28+
event_logging_manager = EventLoggingManager(file_utility)
29+
30+
# Assert: Verify the file exists
31+
file_utility.create_file.assert_called_with(FileUtilities.get_root_path() + "\\filename.txt")
32+
33+
34+
if __name__ == '__main__':
35+
unittest.main()

0 commit comments

Comments
 (0)