tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_get_upstream_remotes.py (1672B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 from unittest import mock
      6 
      7 import mozunit
      8 import pytest
      9 
     10 from mozversioncontrol import get_repository_object
     11 
     12 STEPS = {
     13    "hg": [],
     14    "git": [
     15        "git remote add blah https://example.com/blah",
     16        """
     17        git remote add unified hg::https://hg.mozilla.org/mozilla-unified
     18        git remote add central hg::https://hg.mozilla.org/central
     19        git remote add try hg::https://hg.mozilla.org/try
     20        git remote add firefox https://github.com/mozilla-firefox/firefox
     21        """,
     22    ],
     23    "jj": [],
     24 }
     25 
     26 
     27 @pytest.mark.parametrize(
     28    "is_cinnabar,expected_remotes",
     29    (
     30        (
     31            True,
     32            [
     33                "central",
     34                "firefox",
     35                "unified",
     36            ],
     37        ),
     38        (False, ["firefox"]),
     39    ),
     40 )
     41 def test_get_upstream_remotes(is_cinnabar, expected_remotes, repo):
     42    # Test is only relevant for Git.
     43    if not repo.vcs == "git":
     44        return
     45 
     46    repo.execute_next_step()
     47 
     48    vcs = get_repository_object(repo.dir)
     49    vcs.is_cinnabar_repo = mock.MagicMock(name="is_cinnabar_repo")
     50    vcs.is_cinnabar_repo.return_value = is_cinnabar
     51 
     52    remotes = vcs.get_mozilla_upstream_remotes()
     53 
     54    assert list(remotes) == [], "No official remotes should be found."
     55 
     56    repo.execute_next_step()
     57 
     58    remotes = sorted(list(vcs.get_mozilla_upstream_remotes()))
     59 
     60    assert remotes == expected_remotes, "Multiple non-try remotes should be found."
     61 
     62 
     63 if __name__ == "__main__":
     64    mozunit.main()