示例#1
0
    def test_it_raises_with_info_about_rate_limit_when_exceeded(
            assert_github_issue_no_cache: AssertGitHubIssue,
            requests_mock: MagicMock):
        set_limit_exceeded(requests_mock)

        with pytest.raises(HTTPError, match=".*Current quota:.*"):
            assert_github_issue_no_cache.is_open(ISSUE_NUMBER)
 def test_it_checks_if_release_number_is_properly_configured(
         assert_github_issue_no_cache: AssertGitHubIssue,
         requests_mock: MagicMock):
     set_number_of_releases_to(requests_mock,
                               CURRENT_NUMBER_OF_RELEASES - 1)
     with pytest.raises(AssertionError, match=".*improperly configured.*"):
         assert_github_issue_no_cache.current_release(
             CURRENT_NUMBER_OF_RELEASES)
 def test_it_fails_when_new_releases_available(
         assert_github_issue_no_cache: AssertGitHubIssue,
         requests_mock: MagicMock):
     set_number_of_releases_to(requests_mock,
                               CURRENT_NUMBER_OF_RELEASES + 1)
     with pytest.raises(AssertionError, match="New release of .*"):
         assert_github_issue_no_cache.current_release(
             CURRENT_NUMBER_OF_RELEASES)
示例#4
0
 def test_it_does_not_fail_on_matching_state(
     assert_github_issue_no_cache: AssertGitHubIssue,
     requests_mock: MagicMock,
     expected_state: GitHubIssueState,
     returned_state: str,
 ):
     set_issue_state(requests_mock, returned_state)
     assert_github_issue_no_cache.is_state(ISSUE_NUMBER, expected_state)
示例#5
0
    def test_version_check_fails_when_available(
        assert_github_issue_no_cache: AssertGitHubIssue, ):
        with pytest.raises(AssertionError,
                           match="Release '2\\.0\\.0' of") as ex:
            assert_github_issue_no_cache.fixed_in(
                "2.0.0", pattern="releases/(?P<version>.*)")

        print(ex)  # for quick grab of string for documentation
示例#6
0
    def test_it_raises_when_status_not_200_in_state_check(
            self, assert_github_issue_no_cache: AssertGitHubIssue,
            requests_mock: MagicMock):
        set_issue_state(requests_mock, "open", 500)

        with pytest.raises(HTTPError,
                           match=self._GENERIC_ERROR_MESSAGE_PATTERN):
            assert_github_issue_no_cache.is_open(ISSUE_NUMBER)
示例#7
0
 def test_open_issue_check_fails_when_closed(
     assert_github_issue_no_cache: AssertGitHubIssue, ):
     with pytest.raises(AssertionError):
         try:
             assert_github_issue_no_cache.is_open(CLOSED_ISSUE_NUMBER,
                                                  "Custom message.")
         except AssertionError as ex:
             print(ex)
             raise ex
 def test_it_shows_current_release_number_if_none_given(
         assert_github_issue_no_cache: AssertGitHubIssue,
         requests_mock: MagicMock):
     set_number_of_releases_to(requests_mock, 1)
     with pytest.raises(
             AssertionError,
             match=".*test does not have any number of releases set.*"
             "number of releases is '[0-9]+'"):
         assert_github_issue_no_cache.current_release()
示例#9
0
    def test_it_fails_on_non_matching_state(
        assert_github_issue_no_cache: AssertGitHubIssue,
        requests_mock: MagicMock,
        expected_state: GitHubIssueState,
        returned_state: str,
    ):
        set_issue_state(requests_mock, returned_state)

        with pytest.raises(AssertionError):
            assert_github_issue_no_cache.is_state(ISSUE_NUMBER, expected_state)
示例#10
0
    def test_it_raises_when_status_not_200_in_releases_check(
            self, assert_github_issue_no_cache: AssertGitHubIssue,
            requests_mock: MagicMock):
        set_number_of_releases_to(requests_mock, CURRENT_NUMBER_OF_RELEASES,
                                  500)

        with pytest.raises(HTTPError,
                           match=self._GENERIC_ERROR_MESSAGE_PATTERN):
            assert_github_issue_no_cache.current_release(
                CURRENT_NUMBER_OF_RELEASES)
 def _init_with_user_name_token_and_assert(
     requests_mock: MagicMock, username: str, token: str, assertion: Callable[[AssertGitHubIssue], None] = noop
 ):
     with patch.dict(
         "os.environ",
         {"GITHUB_USER_NAME": username, "GITHUB_PERSONAL_ACCESS_TOKEN": token, "CACHE_INVALIDATION_IN_SECONDS": "0"},
     ):
         set_issue_state(requests_mock, "open")
         assert_github_issue = AssertGitHubIssue(REPOSITORY_ID)
         assert_github_issue.is_open(ISSUE_NUMBER)
         assertion(assert_github_issue)
    def test_safety_cannot_be_enable_on_windows():
        """
        See details of the issue:
        https://github.com/pyupio/safety/issues/119#issuecomment-511828226

        To re-test, remove the OS related conditions around safety in test.sh
        and re-run on windows. Search for 'if [[ ${use_safety} == true ]]; then'
        """
        AssertGitHubIssue("pyupio/safety").is_open(
            119, "Check if safety can be enabled on Windows.")
示例#13
0
def assert_github_issue_caching():
    assert_github_issue = AssertGitHubIssue(REPOSITORY_ID)

    # first call can be cache miss
    assert_github_issue.is_closed(CLOSED_ISSUE_NUMBER)
    try:
        assert_github_issue.current_release(0)
    except AssertionError:
        pass

    assert_github_issue.fixed_in("1234567890.0.0", "releases/(?P<version>.*)")

    return assert_github_issue
示例#14
0
 def test_open_issue_check_does_not_fail_when_open(
     assert_github_issue_no_cache: AssertGitHubIssue, ):
     assert_github_issue_no_cache.is_open(OPEN_ISSUE_NUMBER)
示例#15
0
 def test_release_check_fails_when_new_releases_available(assert_github_issue_caching: AssertGitHubIssue):
     with _timer():
         with pytest.raises(AssertionError, match=".*New release of .*"):
             assert_github_issue_caching.current_release(0)
 def test_it_raises_error_when_repository_id(constructor_arguments: List):
     with pytest.raises(ValueError):
         AssertGitHubIssue(*constructor_arguments)
示例#17
0
 def test_closed_issue_check_fails_when_open(
     assert_github_issue_no_cache: AssertGitHubIssue, ):
     with pytest.raises(AssertionError):
         assert_github_issue_no_cache.is_closed(OPEN_ISSUE_NUMBER)
示例#18
0
def assert_github_issue_no_cache():
    with patch.dict("os.environ", {"CACHE_INVALIDATION_IN_SECONDS": "0"}):
        assert_github_issue = AssertGitHubIssue(REPOSITORY_ID)

    return assert_github_issue
 def test_it_raises(python_version_mock, expectation):  # pylint: disable=unused-argument
     with expectation:
         AssertGitHubIssue(REPOSITORY_ID)
示例#20
0
 def test_closed_issue_check_does_not_fail_when_closed(
     assert_github_issue_no_cache: AssertGitHubIssue, ):
     assert_github_issue_no_cache.is_closed(CLOSED_ISSUE_NUMBER)
示例#21
0
def _fail_open_state_check(assert_github_issue: AssertGitHubIssue,
                           req_mock: MagicMock,
                           msg: str = ""):
    set_issue_state(req_mock, GitHubIssueState.closed.value)
    assert_github_issue.is_open(ISSUE_NUMBER, msg)
示例#22
0
    def test_release_number_check_fails_when_new_releases_available(
        assert_github_issue_no_cache: AssertGitHubIssue, ):
        with pytest.raises(AssertionError, match=".*New release of .*") as ex:
            assert_github_issue_no_cache.current_release(0)

        print(ex)  # for quick grab of string for documentation
        def _assertion(assert_github_issue: AssertGitHubIssue):
            set_limit_exceeded(requests_mock)

            with pytest.raises(HTTPError, match=".*Consider setting.*"):
                assert_github_issue.is_open(ISSUE_NUMBER)
 def test_it_does_not_fail_when_expected_releases_available(
         assert_github_issue_no_cache: AssertGitHubIssue,
         requests_mock: MagicMock):
     set_number_of_releases_to(requests_mock, CURRENT_NUMBER_OF_RELEASES)
     assert_github_issue_no_cache.current_release(
         CURRENT_NUMBER_OF_RELEASES)
示例#25
0
 def test_version_check_fails_when_available(assert_github_issue_caching: AssertGitHubIssue):
     with _timer():
         with pytest.raises(AssertionError):
             assert_github_issue_caching.fixed_in("1.0.0", pattern="releases/(?P<version>.*)")
示例#26
0
 def test_closed_issue_check_does_not_fail_when_closed(assert_github_issue_caching: AssertGitHubIssue):
     with _timer():
         assert_github_issue_caching.is_closed(CLOSED_ISSUE_NUMBER)