Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test coverage #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ def test_apply_update_pull_request_exists(self):
bot.apply_updates(initial=True, scheduled=False)

self.assertEqual(the_requirement.pull_request, the_pull)

def test_continue_on_empty_updates(self):
the_requirement = Mock()
the_pull = pullrequest_factory("The PR")

bot = bot_factory(prs=[the_pull])
bot.req_bundle.get_updates = Mock()
update = RequirementUpdate(
requirement_file="foo", requirement=the_requirement, commit_message="foo"
)
bot.req_bundle.get_updates.return_value = update
bot.iter_updates = Mock(return_value=[[None,None,None,None]])
bot.apply_updates(initial=False, scheduled=False)
# with no updates the update.requirement.pull_request is not populated with
# pull_request.
self.assertNotEqual(the_requirement.pull_request, the_pull)

def test_updates_empty(self):
bot = bot_factory()
Expand Down Expand Up @@ -375,6 +391,37 @@ def test_multiple_updates_in_file(self):
# we're looking for the sha here. Make sure that the sha got updated with the new content
self.assertEqual(create_commit_calls[0][1]["sha"], "abcd")
self.assertEqual(create_commit_calls[1][1]["sha"], "xyz")

def test_repo_name_is_user_repo_full_name(self):
bot = bot_factory()
delattr(bot.user_repo, "path_with_namespace")
bot.user_repo.full_name = "fooname"
bot.provider.create_branch = Mock()
bot.provider.create_commit.side_effect = [
"sha1", "sha2", "sha3"
]
bot.create_pull_request = Mock()
requirement = Mock()
requirement.update_content.return_value = "same content"
updates = [
RequirementUpdate(
requirement_file=RequirementFile(
path="foo.txt",
content='same content',
sha='abcd'
),
requirement=requirement,
commit_message="foo"
)
]

with patch('pyup.bot.logger.error') as mock_logger_err:
bot.commit_and_pull(True, "new branch", "repo", "", updates)

assert mock_logger_err.called
mock_logger_err.assert_called_once_with(
"Empty commit at fooname, unable to update repo."
)

def test_create_branch_fails(self):
bot = bot_factory()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_get_pull_request_committer(self):
committers = self.provider.get_pull_request_committer(self.repo, mr)
actual = [a.login for a in committers]
expected = [a['username'] for a in p]
self.assertEquals(actual, expected)
self.assertEqual(actual, expected)

def test_close_pull_request(self):
mr = MagicMock()
Expand Down
28 changes: 21 additions & 7 deletions tests/test_pullrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
from __future__ import absolute_import, print_function, unicode_literals
from unittest import TestCase
from pyup.pullrequest import PullRequest
from datetime import datetime, timedelta
from datetime import datetime


def pullrequest_factory(title, state="open", url="http://foo.bar",
created_at=datetime.now(), number=1):
def pullrequest_factory(
title, state="open", url="http://foo.bar", created_at=datetime.now(), number=1
):
return PullRequest(
title=title,
state=state,
url=url,
created_at=created_at,
number=number
number=number,
)


Expand Down Expand Up @@ -40,7 +41,6 @@ def test_initial(self):
def test_unknown(self):
pr = pullrequest_factory(title="Foo")
self.assertEqual(pr.type, "unknown")
#self.assertTrue(pr.is_scheduled)

def test_compile(self):
pr = pullrequest_factory(title="Compile foo.txt")
Expand Down Expand Up @@ -68,6 +68,18 @@ def test_is_valid(self):
pr = pullrequest_factory(title="Update this and that")
self.assertTrue(pr.is_valid)

def test_config_error_type(self):
pr = pullrequest_factory(title="Invalid .pyup.yml")
self.assertEqual(pr.type, PullRequest.CONFIG_ERROR_TYPE)
self.assertFalse(pr.is_scheduled)

def test_is_config_error(self):
pr = pullrequest_factory(title="Invalid .pyup.yml")
self.assertTrue(pr.is_config_error)
pr = pullrequest_factory(title="Foo")
self.assertFalse(pr.is_config_error)


class PullRequestEQTest(TestCase):
def test_is_eq(self):
pr1 = pullrequest_factory("yay", number=1)
Expand Down Expand Up @@ -110,9 +122,11 @@ def test_some_bogus(self):

def test_with_prefix(self):
pr = pullrequest_factory(title="Some Prefix | Update django")
self.assertEqual(pr.get_requirement("Some Prefix |"), 'django')
self.assertEqual(pr.get_requirement("Some Prefix |"), "django")

flask = pullrequest_factory(title="Pin flask")
flask_prefix = pullrequest_factory(title="Some Prefix | Pin flask")
self.assertIsNotNone(flask.get_requirement())
self.assertEqual(flask.get_requirement(), flask_prefix.get_requirement("Some Prefix |"))
self.assertEqual(
flask.get_requirement(), flask_prefix.get_requirement("Some Prefix |")
)