Beispiel #1
0
    def setUp(self):
        self.old_tempdir, tempfile.tempdir = tempfile.tempdir, mkdtemp(prefix='chime-TestViewFunctions-')

        repo_path = dirname(abspath(__file__)) + '/../test-app.git'
        temp_repo_dir = mkdtemp(prefix='chime-root')
        temp_repo_path = temp_repo_dir + '/test-app.git'
        copytree(repo_path, temp_repo_path)
        self.origin = ChimeRepo(temp_repo_path)
        repo_functions.ignore_task_metadata_on_merge(self.origin)
        self.clone = self.origin.clone(mkdtemp(prefix='chime-'))
        repo_functions.ignore_task_metadata_on_merge(self.clone)

        self.session = dict(email=str(uuid4()))

        environ['GIT_AUTHOR_NAME'] = ' '
        environ['GIT_COMMITTER_NAME'] = ' '
        environ['GIT_AUTHOR_EMAIL'] = self.session['email']
        environ['GIT_COMMITTER_EMAIL'] = self.session['email']
Beispiel #2
0
    def setUp(self):
        self.old_tempdir, tempfile.tempdir = tempfile.tempdir, mkdtemp(prefix="chime-TestViewFunctions-")

        repo_path = dirname(abspath(__file__)) + "/../test-app.git"
        temp_repo_dir = mkdtemp(prefix="chime-root")
        temp_repo_path = temp_repo_dir + "/test-app.git"
        copytree(repo_path, temp_repo_path)
        self.origin = ChimeRepo(temp_repo_path)
        repo_functions.ignore_task_metadata_on_merge(self.origin)
        self.clone = self.origin.clone(mkdtemp(prefix="chime-"))
        repo_functions.ignore_task_metadata_on_merge(self.clone)

        self.session = dict(email=str(uuid4()))

        environ["GIT_AUTHOR_NAME"] = " "
        environ["GIT_COMMITTER_NAME"] = " "
        environ["GIT_AUTHOR_EMAIL"] = self.session["email"]
        environ["GIT_COMMITTER_EMAIL"] = self.session["email"]
Beispiel #3
0
class TestViewFunctions (TestCase):

    def setUp(self):
        self.old_tempdir, tempfile.tempdir = tempfile.tempdir, mkdtemp(prefix='chime-TestViewFunctions-')

        repo_path = dirname(abspath(__file__)) + '/../test-app.git'
        temp_repo_dir = mkdtemp(prefix='chime-root')
        temp_repo_path = temp_repo_dir + '/test-app.git'
        copytree(repo_path, temp_repo_path)
        self.origin = ChimeRepo(temp_repo_path)
        repo_functions.ignore_task_metadata_on_merge(self.origin)
        self.clone = self.origin.clone(mkdtemp(prefix='chime-'))
        repo_functions.ignore_task_metadata_on_merge(self.clone)

        self.session = dict(email=str(uuid4()))

        environ['GIT_AUTHOR_NAME'] = ' '
        environ['GIT_COMMITTER_NAME'] = ' '
        environ['GIT_AUTHOR_EMAIL'] = self.session['email']
        environ['GIT_COMMITTER_EMAIL'] = self.session['email']

    def tearDown(self):
        rmtree(tempfile.tempdir)
        tempfile.tempdir = self.old_tempdir

    # in TestViewFunctions
    def test_sorted_paths(self):
        ''' Ensure files/directories are sorted in alphabetical order, and that
            we get the expected values back from the sorted_paths method
        '''
        sorted_list = view_functions.sorted_paths(self.clone, 'master')

        expected_list = [
            {'modified_date': view_functions.get_relative_date(self.clone, 'img'), 'name': 'img', 'title': 'img', 'view_path': '/tree/master/view/img', 'is_editable': False, 'link_name': u'img/', 'display_type': view_functions.FOLDER_FILE_TYPE},
            {'modified_date': view_functions.get_relative_date(self.clone, 'index.md'), 'name': 'index.md', 'title': 'index.md', 'view_path': '/tree/master/view/index.md', 'is_editable': True, 'link_name': 'index.md', 'display_type': view_functions.FILE_FILE_TYPE},
            {'modified_date': view_functions.get_relative_date(self.clone, 'other'), 'name': 'other', 'title': 'other', 'view_path': '/tree/master/view/other', 'is_editable': False, 'link_name': u'other/', 'display_type': view_functions.FOLDER_FILE_TYPE},
            {'modified_date': view_functions.get_relative_date(self.clone, 'other.md'), 'name': 'other.md', 'title': 'other.md', 'view_path': '/tree/master/view/other.md', 'is_editable': True, 'link_name': 'other.md', 'display_type': view_functions.FILE_FILE_TYPE},
            {'modified_date': view_functions.get_relative_date(self.clone, 'sub'), 'name': 'sub', 'title': 'sub', 'view_path': '/tree/master/view/sub', 'is_editable': False, 'link_name': u'sub/', 'display_type': view_functions.FOLDER_FILE_TYPE}]

        self.assertEqual(sorted_list, expected_list)

    # in TestViewFunctions
    def test_breadcrumb_paths_with_no_relative_path(self):
        ''' Ensure that a list with pairs of a sub-directory and the absolute path
            to that directory is returned for all sub-directories in a path
        '''
        breadcrumb_paths = view_functions.make_breadcrumb_paths('my-branch')
        self.assertEqual(breadcrumb_paths, [('root', '/tree/my-branch/edit')])

    # in TestViewFunctions
    def test_breadcrumb_paths_with_relative_path(self):
        ''' Ensure that a list with pairs of a sub-directory and the absolute path
            to that directory is returned for all sub-directories in a path
        '''
        breadcrumb_paths = view_functions.make_breadcrumb_paths('my-branch', 'blah/foo/')
        self.assertEqual(breadcrumb_paths, [('root', '/tree/my-branch/edit'),
                                            ('blah', '/tree/my-branch/edit/blah/'),
                                            ('foo', '/tree/my-branch/edit/blah/foo/')])

    # in TestViewFunctions
    def test_auth_url(self):
        '''
        '''
        auth_url = 'data/authentication.csv'
        csv_url = view_functions.get_auth_csv_url(auth_url)
        self.assertEqual(csv_url, auth_url)

        auth_url = 'https://docs.google.com/spreadsheets/d/12jUfaRBd-CU1_6BGeLFG1_qoi7Fw_vRC_SXv36eDzM0/edit'
        csv_url = view_functions.get_auth_csv_url(auth_url)
        self.assertEqual(csv_url, 'https://docs.google.com/spreadsheets/d/12jUfaRBd-CU1_6BGeLFG1_qoi7Fw_vRC_SXv36eDzM0/export?format=csv')

    # in TestViewFunctions
    def test_is_allowed_email(self):
        '''
        '''
        def mock_remote_authentication_file(url, request):
            if 'good-file.csv' in url.geturl():
                return response(200, '''
Some junk below
Email domain,Organization,Email address,Organization,Name
codeforamerica.org,Code for America,[email protected],Code for America,Mike Migurski
*@codeforamerica.org,Code for America,,,
''')

            if 'org-file.csv' in url.geturl():
                return response(200, '''
Some junk below
Email domain,Organization
codeforamerica.org,Code for America
*@codeforamerica.org,Code for America
''')

            if 'addr-file.csv' in url.geturl():
                return response(200, '''
Some junk below
Email address,Organization,Name
[email protected],Code for America,Mike Migurski
''')

            return response(404, '')

        def good_file():
            return view_functions.get_auth_data_file('http://example.com/good-file.csv')

        def org_file():
            return view_functions.get_auth_data_file('http://example.com/org-file.csv')

        def addr_file():
            return view_functions.get_auth_data_file('http://example.com/addr-file.csv')

        def no_file():
            return view_functions.get_auth_data_file('http://example.com/no-file.csv')

        with HTTMock(mock_remote_authentication_file):
            self.assertTrue(view_functions.is_allowed_email(good_file(), '*****@*****.**'))
            self.assertTrue(view_functions.is_allowed_email(good_file(), '*****@*****.**'))
            self.assertTrue(view_functions.is_allowed_email(good_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(good_file(), '*****@*****.**'))

            self.assertTrue(view_functions.is_allowed_email(org_file(), '*****@*****.**'))
            self.assertTrue(view_functions.is_allowed_email(org_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(org_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(org_file(), '*****@*****.**'))

            self.assertFalse(view_functions.is_allowed_email(addr_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(addr_file(), '*****@*****.**'))
            self.assertTrue(view_functions.is_allowed_email(addr_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(addr_file(), '*****@*****.**'))

            self.assertFalse(view_functions.is_allowed_email(no_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(no_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(no_file(), '*****@*****.**'))
            self.assertFalse(view_functions.is_allowed_email(no_file(), '*****@*****.**'))
    
    def test_guess_branch_names_in_decorator(self):
        '''
        '''
        config = dict(default_branch='abcd')

        branch_name, master_name = \
            view_functions.guess_branch_names_in_decorator(dict(), config, dict())
        
        self.assertEqual((branch_name, master_name), (None, 'abcd'))

        kwargs = dict(branch_name='xxyz')
        branch_name, master_name = \
            view_functions.guess_branch_names_in_decorator(kwargs, config, dict())
        
        self.assertEqual((branch_name, master_name), ('xxyz', 'abcd'))

        form = dict(branch='lmnop')
        branch_name, master_name = \
            view_functions.guess_branch_names_in_decorator(dict(), config, form)
        
        self.assertEqual((branch_name, master_name), ('lmnop', 'abcd'))

        branch_name, master_name = \
            view_functions.guess_branch_names_in_decorator(kwargs, config, form)
        
        self.assertEqual((branch_name, master_name), ('xxyz', 'abcd'))
Beispiel #4
0
class TestViewFunctions(TestCase):
    def setUp(self):
        self.old_tempdir, tempfile.tempdir = tempfile.tempdir, mkdtemp(prefix="chime-TestViewFunctions-")

        repo_path = dirname(abspath(__file__)) + "/../test-app.git"
        temp_repo_dir = mkdtemp(prefix="chime-root")
        temp_repo_path = temp_repo_dir + "/test-app.git"
        copytree(repo_path, temp_repo_path)
        self.origin = ChimeRepo(temp_repo_path)
        repo_functions.ignore_task_metadata_on_merge(self.origin)
        self.clone = self.origin.clone(mkdtemp(prefix="chime-"))
        repo_functions.ignore_task_metadata_on_merge(self.clone)

        self.session = dict(email=str(uuid4()))

        environ["GIT_AUTHOR_NAME"] = " "
        environ["GIT_COMMITTER_NAME"] = " "
        environ["GIT_AUTHOR_EMAIL"] = self.session["email"]
        environ["GIT_COMMITTER_EMAIL"] = self.session["email"]

    def tearDown(self):
        rmtree(tempfile.tempdir)
        tempfile.tempdir = self.old_tempdir

    # in TestViewFunctions
    def test_sorted_paths(self):
        """ Ensure files/directories are sorted in alphabetical order, and that
            we get the expected values back from the sorted_paths method
        """
        sorted_list = view_functions.sorted_paths(self.clone, "master")

        expected_list = [
            {
                "modified_date": view_functions.get_relative_date(self.clone, "img"),
                "name": "img",
                "title": "img",
                "view_path": "/tree/master/view/img",
                "is_editable": False,
                "link_name": u"img/",
                "display_type": constants.FOLDER_FILE_TYPE,
            },
            {
                "modified_date": view_functions.get_relative_date(self.clone, "index.md"),
                "name": "index.md",
                "title": "index.md",
                "view_path": "/tree/master/view/index.md",
                "is_editable": True,
                "link_name": "index.md",
                "display_type": constants.FILE_FILE_TYPE,
            },
            {
                "modified_date": view_functions.get_relative_date(self.clone, "other"),
                "name": "other",
                "title": "other",
                "view_path": "/tree/master/view/other",
                "is_editable": False,
                "link_name": u"other/",
                "display_type": constants.FOLDER_FILE_TYPE,
            },
            {
                "modified_date": view_functions.get_relative_date(self.clone, "other.md"),
                "name": "other.md",
                "title": "other.md",
                "view_path": "/tree/master/view/other.md",
                "is_editable": True,
                "link_name": "other.md",
                "display_type": constants.FILE_FILE_TYPE,
            },
            {
                "modified_date": view_functions.get_relative_date(self.clone, "sub"),
                "name": "sub",
                "title": "sub",
                "view_path": "/tree/master/view/sub",
                "is_editable": False,
                "link_name": u"sub/",
                "display_type": constants.FOLDER_FILE_TYPE,
            },
        ]

        self.assertEqual(sorted_list, expected_list)

    # in TestViewFunctions
    def test_breadcrumb_paths_with_no_relative_path(self):
        """ Ensure that a list with pairs of a sub-directory and the absolute path
            to that directory is returned for all sub-directories in a path
        """
        breadcrumb_paths = view_functions.make_breadcrumb_paths("my-branch")
        self.assertEqual(breadcrumb_paths, [("root", "/tree/my-branch/edit")])

    # in TestViewFunctions
    def test_breadcrumb_paths_with_relative_path(self):
        """ Ensure that a list with pairs of a sub-directory and the absolute path
            to that directory is returned for all sub-directories in a path
        """
        breadcrumb_paths = view_functions.make_breadcrumb_paths("my-branch", "blah/foo/")
        self.assertEqual(
            breadcrumb_paths,
            [
                ("root", "/tree/my-branch/edit"),
                ("blah", "/tree/my-branch/edit/blah/"),
                ("foo", "/tree/my-branch/edit/blah/foo/"),
            ],
        )

    # in TestViewFunctions
    def test_auth_url(self):
        """
        """
        auth_url = "data/authentication.csv"
        csv_url = view_functions.get_auth_csv_url(auth_url)
        self.assertEqual(csv_url, auth_url)

        auth_url = "https://docs.google.com/spreadsheets/d/12jUfaRBd-CU1_6BGeLFG1_qoi7Fw_vRC_SXv36eDzM0/edit"
        csv_url = view_functions.get_auth_csv_url(auth_url)
        self.assertEqual(
            csv_url,
            "https://docs.google.com/spreadsheets/d/12jUfaRBd-CU1_6BGeLFG1_qoi7Fw_vRC_SXv36eDzM0/export?format=csv",
        )

    # in TestViewFunctions
    def test_is_allowed_email(self):
        """
        """

        def mock_remote_authentication_file(url, request):
            if "good-file.csv" in url.geturl():
                return response(
                    200,
                    """
Some junk below
Email domain,Organization,Email address,Organization,Name
codeforamerica.org,Code for America,[email protected],Code for America,Mike Migurski
*@codeforamerica.org,Code for America,,,
""",
                )

            if "org-file.csv" in url.geturl():
                return response(
                    200,
                    """
Some junk below
Email domain,Organization
codeforamerica.org,Code for America
*@codeforamerica.org,Code for America
""",
                )

            if "addr-file.csv" in url.geturl():
                return response(
                    200,
                    """
Some junk below
Email address,Organization,Name
[email protected],Code for America,Mike Migurski
""",
                )

            return response(404, "")

        def good_file():
            return view_functions.get_auth_data_file("http://example.com/good-file.csv")

        def org_file():
            return view_functions.get_auth_data_file("http://example.com/org-file.csv")

        def addr_file():
            return view_functions.get_auth_data_file("http://example.com/addr-file.csv")

        def no_file():
            return view_functions.get_auth_data_file("http://example.com/no-file.csv")

        with HTTMock(mock_remote_authentication_file):
            self.assertTrue(view_functions.is_allowed_email(good_file(), "*****@*****.**"))
            self.assertTrue(view_functions.is_allowed_email(good_file(), "*****@*****.**"))
            self.assertTrue(view_functions.is_allowed_email(good_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(good_file(), "*****@*****.**"))

            self.assertTrue(view_functions.is_allowed_email(org_file(), "*****@*****.**"))
            self.assertTrue(view_functions.is_allowed_email(org_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(org_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(org_file(), "*****@*****.**"))

            self.assertFalse(view_functions.is_allowed_email(addr_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(addr_file(), "*****@*****.**"))
            self.assertTrue(view_functions.is_allowed_email(addr_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(addr_file(), "*****@*****.**"))

            self.assertFalse(view_functions.is_allowed_email(no_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(no_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(no_file(), "*****@*****.**"))
            self.assertFalse(view_functions.is_allowed_email(no_file(), "*****@*****.**"))

    def test_guess_branch_names_in_decorator(self):
        """
        """
        config = dict(default_branch="abcd")

        branch_name, master_name = view_functions.guess_branch_names_in_decorator(dict(), config, dict())

        self.assertEqual((branch_name, master_name), (None, "abcd"))

        kwargs = dict(branch_name="xxyz")
        branch_name, master_name = view_functions.guess_branch_names_in_decorator(kwargs, config, dict())

        self.assertEqual((branch_name, master_name), ("xxyz", "abcd"))

        form = dict(branch="lmnop")
        branch_name, master_name = view_functions.guess_branch_names_in_decorator(dict(), config, form)

        self.assertEqual((branch_name, master_name), ("lmnop", "abcd"))

        branch_name, master_name = view_functions.guess_branch_names_in_decorator(kwargs, config, form)

        self.assertEqual((branch_name, master_name), ("xxyz", "abcd"))