def test_get_inbox_list(self): master_inbox_path = os.path.join(self.TEST_DIR, "master_inbox") container_inboxes_path = os.path.join(self.TEST_DIR, "container_inboxes") testfile1 = os.path.join(self.TEST_DIR, "testFile1.json") testfile2 = os.path.join(self.TEST_DIR, "testFile2.json") testfile3 = os.path.join(self.TEST_DIR, "testFile3.json") # Initialize inboxer using a tmp directory for unit testing inboxer = Inboxer(master_inbox_path, container_inboxes_path) # Create our test files with open(testfile1, "a"): os.utime(testfile1, None) with open(testfile2, "a"): os.utime(testfile2, None) with open(testfile3, "a"): os.utime(testfile3, None) inboxer.add_file_by_path("MyTopic", testfile1) inboxer.add_file_by_path("MyTopic", testfile2) inboxer.add_file_by_path("MyTopic", testfile3) self.assertEqual(len(inboxer.get_inbox_list("MyTopic")), 3)
def test_on(self): def callback(data): self.assertEqual(data["topic"], "MyTopicEvent") master_inbox_path = os.path.join(self.TEST_DIR, "master_inbox") container_inboxes_path = os.path.join(self.TEST_DIR, "container_inboxes") testfile = os.path.join(self.TEST_DIR, "testFile.json") # Initialize inboxer using a tmp directory for unit testing inboxer = Inboxer(master_inbox_path, container_inboxes_path) inboxer.on("received", callback) # Create our test file with open(testfile, "a"): os.utime(testfile, None) counter = inboxer.add_file_by_path("MyTopicEvent", testfile)
def test_add_file_by_path(self): master_inbox_path = os.path.join(self.TEST_DIR, "master_inbox") container_inboxes_path = os.path.join(self.TEST_DIR, "container_inboxes") testfile = os.path.join(self.TEST_DIR, "testFile.json") # Initialize inboxer using a tmp directory for unit testing inboxer = Inboxer(master_inbox_path, container_inboxes_path) # Create our test file with open(testfile, "a"): os.utime(testfile, None) counter = inboxer.add_file_by_path("MyTopic", testfile) master_inbox_destination = os.path.join(master_inbox_path, "MyTopic", str(counter)) self.assertEqual(os.path.exists(testfile), False) self.assertEqual(os.path.exists(master_inbox_destination), True)