Esempio n. 1
0
 def test_setting_permissions_in_challenges_works(self):
     tree = {
         "name":
         "~",
         "children": [{
             "name":
             "my-house",
             "type":
             "directory",
             "challenges": [{
                 "challenge": 1,
                 "step": 1,
                 "permissions": 0500
             }, {
                 "challenge": 2,
                 "step": 1,
                 "permissions": 0300
             }]
         }]
     }
     FileTree(tree, self.__end_path).parse_complete(1, 9)
     house = os.path.join(self.__end_path, "~/my-house")
     self.assertTrue(os.path.exists(house))
     self.assertEquals(get_oct_permissions(house), "0500")
     self.tearDown()
     FileTree(tree, self.__end_path).parse_complete(2, 1)
     self.assertTrue(os.path.exists(house))
     self.assertEquals(get_oct_permissions(house), "0300")
 def test_create_a_new_standalone_item(self):
     file_tree = FileTree(None, self.__end_path)
     contents_path = "/tmp/test"
     contents = "hello"
     open(contents_path, "w+").write(contents)
     file_tree.create_item("file", "~/my-house", 0644, contents_path)
     house = os.path.join(self.__end_path, "~/my-house")
     self.assertTrue(os.path.exists(house))
     test_contents = open(house).readline()
     self.assertEquals(contents, test_contents)
Esempio n. 3
0
 def test_containing_folder_outside_challenge_scope_then_child_file_is(
         self):
     tree = {
         "name":
         "~",
         "children": [{
             "name":
             "my-house",
             "challenges": [{
                 "challenge": 1,
                 "step": 1,
                 "exists": False
             }, {
                 "challenge": 2,
                 "step": 1
             }],
             "children": [{
                 "name": "Dad",
                 "contents": get_story_file("Dad"),
                 "challenges": [{
                     "challenge": 2,
                     "step": 1
                 }]
             }]
         }]
     }
     FileTree(tree, self.__end_path).parse_complete(1, 9)
     house = os.path.join(self.__end_path, "~/my-house")
     dad = os.path.join(house, "Dad")
     self.assertFalse(os.path.exists(house))
     self.assertFalse(os.path.exists(dad))
Esempio n. 4
0
 def test_create_a_new_standalone_item(self):
     file_tree = FileTree(None, self.__end_path)
     contents_path = "/tmp/test"
     contents = "hello"
     open(contents_path, "w+").write(contents)
     file_tree.create_item("file", "~/my-house", 0644, contents_path)
     house = os.path.join(self.__end_path, "~/my-house")
     self.assertTrue(os.path.exists(house))
     test_contents = open(house).readline()
     self.assertEquals(contents, test_contents)
Esempio n. 5
0
    def test_basic_dir(self):
        tree = {
            "name": "~",
            "children": [{
                "name": "my-house",
                "type": FileTree.TYPE_DIR
            }]
        }

        FileTree(tree, self.__end_path).parse_complete(1, 1)
        my_house = os.path.join(self.__end_path, "~/my-house")
        self.assertTrue(os.path.exists(my_house))
        self.assertTrue(os.path.isdir(my_house))
    def run(self, challenge=1, step=1):
        FileTree(tree, tq_file_system).parse_complete(challenge, step)
        StepClass = get_step_class(challenge, step)
        step_instance = StepClass(self.__message_client)
        self.__send_start_challenge_data(step_instance, step_instance.TerminalClass.terminal_commands, challenge)
        step_instance.run()
        (new_challenge, new_step) = step_instance.next()

        while not step_instance.is_finished_game():
            StepClass = get_step_class(new_challenge, new_step)
            step_instance = StepClass(self.__message_client)
            self.__send_start_challenge_data(step_instance, step_instance.TerminalClass.terminal_commands, new_challenge)
            self.__save_challenge(new_challenge, challenge)
            challenge = new_challenge
            step_instance.run()
            (new_challenge, new_step) = step_instance.next()
Esempio n. 7
0
    def test_basic_file(self):
        tree = {
            "name":
            "~",
            "children": [{
                "name": "Dad",
                "contents": get_story_file("Dad"),
                "permissions": 0755
            }]
        }

        FileTree(tree, self.__end_path).parse_complete(1, 1)
        dad = os.path.join(self.__end_path, "~/Dad")
        self.assertTrue(os.path.exists(dad))
        self.assertTrue(os.path.isfile(dad))
        self.assertTrue(is_executable(dad))
        self.assertTrue(filecmp.cmp(dad, get_story_file("Dad"), shallow=False))
Esempio n. 8
0
def launch_project(challenge=1, step=1):
    """
    Start the game off form the specified challenge and step

    Args:
        challenge (int)
        step (int)

    Returns:
        None
    """

    from linux_story.ChallengeController import ChallengeController
    from linux_story.MessageClient import MessageClient

    FileTree(tree, tq_file_system).parse_complete(challenge, step)
    client = MessageClient()
    controller = ChallengeController(client)
    controller.run(challenge, step)
Esempio n. 9
0
    def test_file_does_not_exist_challenge_2(self):
        tree = {
            "name":
            "~",
            "children": [{
                "name":
                "Dad",
                "contents":
                get_story_file("Dad"),
                "challenges": [{
                    "challenge": 1,
                    "step": 1
                }, {
                    "challenge": 2,
                    "step": 1,
                    "exists": False
                }],
            }]
        }

        FileTree(tree, self.__end_path).parse_complete(2, 2)
        dad = os.path.join(self.__end_path, "~/Dad")
        self.assertFalse(os.path.exists(dad))
Esempio n. 10
0
 def __containing_folder_with_permission_removed(self, permissions,
                                                 string_permissions):
     tree = {
         "name":
         "~",
         "children": [{
             "name":
             "my-house",
             "type":
             FileTree.TYPE_DIR,
             "permissions":
             permissions,
             "children": [{
                 "name": "Dad",
                 "contents": get_story_file("Dad")
             }]
         }]
     }
     FileTree(tree, self.__end_path).parse_complete(1, 1)
     house = os.path.join(self.__end_path, "~/my-house")
     dad = os.path.join(house, "Dad")
     self.assertEquals(get_oct_permissions(house), string_permissions)
     os.chmod(house, 0755)
     self.assertTrue(os.path.exists(dad))