Пример #1
0
    def test_set_id_nonexistent(self):
        """Tests whether the set_id method creates id.txt file
        after it has been removed."""

        expected = True

        os.remove(strings.get_id_path())
        self.test.set_id()

        actual = os.path.isfile(strings.get_id_path())

        self.assertEqual(expected, actual)
Пример #2
0
    def get_id(self):
        """Returns the UUID found in id.txt file."""

        if self.validate_id() is False:
            self.set_id()

        with open(strings.get_id_path(), "r") as file:
            return file.read()
Пример #3
0
    def test_validate_id_nonexistent(self):
        """Tests whether the validate_id method from identifier.py
        returns the correct result when the file doesn't exist."""

        expected = False

        os.remove(strings.get_id_path())

        actual = self.test.validate_id()

        self.assertEqual(expected, actual)
Пример #4
0
    def test_validate_id_altered(self):
        """Tests whether the validate_id method from identifier.py
        returns the correct result when the file is altered."""

        expected = False

        with open(strings.get_id_path(), "w") as file:
            file.write("this is definitely not a valid file.")

        actual = self.test.validate_id()

        self.assertEqual(expected, actual)
Пример #5
0
    def test_init_false(self, set_id):
        """Tests if init calls the set_id function if validate_id
        is False"""

        self.mock.attach_mock(set_id, 'set_id')

        with open(strings.get_id_path(), "w") as file:
            file.write("the dark side should have won.")

        self.test.__init__()

        expected = mock.call.set_id()
        actual = self.mock.mock_calls[0]

        self.assertEqual(expected, actual)
Пример #6
0
    def validate_id(self):
        """Checks if id.txt exists and if the id found
         in id.txt is the correct id."""

        try:
            file = open(strings.get_id_path(), "r")
        except IOError:
            return False

        correct_id = self.get_uuid()
        read_id = file.read()

        file.close()

        return correct_id == read_id
Пример #7
0
    def set_id(self):
        """Creates the id.txt file which contains the
        UUID of the machine."""

        with open(strings.get_id_path(), "w+") as file:
            file.write(self.get_uuid())