File tree Expand file tree Collapse file tree 6 files changed +58
-5
lines changed
tests/Infrastructure/EventLoggingManager Expand file tree Collapse file tree 6 files changed +58
-5
lines changed Original file line number Diff line number Diff line change 11import imp
22import os
33import sys
4+ from os .path import exists
45
56
67class 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")
Original file line number Diff line number Diff 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" )
Original file line number Diff line number Diff line change @@ -39,4 +39,8 @@ broker = localhost
3939port = 1883
4040mob station name = NewName
4141session id = 1337
42- topic root = MobTimer
42+ topic root = MobTimer
43+
44+ [EVENT LOGGING]
45+ enabled = True
46+ log file name = MobTimer.log
Original file line number Diff line number Diff 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.)
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments