Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
3
Indexable
Never
import unittest
from unittest.mock import patch
from ne import get_project_list


class TestGetProjectList(unittest.TestCase):
    @patch('ne.get_user_projects')
    def test_get_project_list(self, mock_get_user_projects):
        mock_get_user_projects.return_value = [
            {"id": 1, "name": "personal_project", "forked_from_project": None, "owner": {"id": "123"}},
            {"id": 2, "name": "forked_project", "forked_from_project": {"path_with_namespace": "original/namespace"}, "owner": {"id": "456"}},
            {"id": 3, "name": "another_personal_project", "forked_from_project": None, "owner": {"id": "123"}},
        ]
        expected_output = "Personal project: personal_project\nForked project: forked_project\nPersonal project: another_personal_project\n"
        self.assertEqual(get_project_list("123"), expected_output)

    @patch('ne.get_user_projects')
    def test_get_project_list_error(self, mock_get_user_projects):
        mock_get_user_projects.return_value = None
        expected_output = "Error: Unable to get list of projects for user 123\n"
        self.assertEqual(get_project_list("123"), expected_output)


if __name__ == '__main__':
    unittest.main()