Example #1
0
    def test_multiple_updates_in_file(self):
        bot = bot_factory()
        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 = "new content"
        updates = [
            RequirementUpdate(requirement_file=RequirementFile(path="foo.txt",
                                                               content='',
                                                               sha='abcd'),
                              requirement=requirement,
                              commit_message="foo"),
            RequirementUpdate(requirement_file=RequirementFile(path="foo.txt",
                                                               content='',
                                                               sha='abcd'),
                              requirement=requirement,
                              commit_message="foo"),
            RequirementUpdate(requirement_file=RequirementFile(path="baz.txt",
                                                               content='',
                                                               sha='xyz'),
                              requirement=requirement,
                              commit_message="foo")
        ]

        bot.commit_and_pull(True, "new branch", "repo", "", updates)

        self.assertEqual(bot.provider.create_commit.called, True)
        self.assertEqual(bot.provider.create_commit.call_count, 2)
        create_commit_calls = bot.provider.create_commit.call_args_list
        # 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")
Example #2
0
    def test_ignore_requirement(self, package):
        package.return_value = True

        content = """foo
bar # pyup: ignore
baz"""
        r = RequirementFile("r.txt", content=content)
        self.assertEqual(len(r.requirements), 2)
        self.assertEqual(
            r.requirements, [
                Requirement.parse("foo", 0),
                Requirement.parse("baz", 2)
            ]
        )

        content = """foo
        bar # pyup:ignore
        baz"""
        r = RequirementFile("r.txt", content=content)
        self.assertEqual(len(r.requirements), 2)
        self.assertEqual(
            r.requirements, [
                Requirement.parse("foo", 0),
                Requirement.parse("baz", 2)
            ]
        )
Example #3
0
    def test_str(self):
        r = RequirementFile("r.txt", "content", "asdfe")
        self.assertEqual(
            r.__str__(),
            "RequirementFile(path='r.txt', sha='asdfe', content='content')")

        content = "more content than 30 characters here"
        r = RequirementFile("r.txt", content, "asdfe")
        self.assertEqual(
            r.__str__(), "RequirementFile(path='r.txt', sha='asdfe', "
            "content='more content than 30 character[truncated]')")
Example #4
0
    def test_get_updates(self):
        with patch('pyup.requirements.Requirement.package', return_value=Mock()):
            reqs = RequirementsBundle()
            reqs.append(RequirementFile(path="r.txt", content='Bla'))
            updates = [u for u in reqs.get_updates(True, False, Mock())]
            self.assertEqual(len(updates), 1)
            #self.assertEqual(updates[0].__class__, reqs.get_initial_update_class().__class__)

            reqs = RequirementsBundle()
            reqs.append(RequirementFile(path="r.txt", content='Bla'))
            updates = [u for u in reqs.get_updates(False, False, Mock())]
            self.assertEqual(len(updates), 1)
Example #5
0
    def test_update_with_hashes_and_comment_and_env_markers(
            self, get_hashes_mock):

        get_hashes_mock.return_value = {
            "hashes": [{
                "hash": "123"
            }, {
                "hash": "456"
            }]
        }
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9; sys_platform != 'win32' \\\n" \
                      "        --hash=sha256:abcde # yay"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9; sys_platform != 'win32'",
                                  1), req)

            new_content = req.update_content(content)
            self.assertEqual(
                new_content, "alembic==1.4.2; sys_platform != 'win32' \\\n"
                "    --hash=sha256:123 \\\n"
                "    --hash=sha256:456 # yay")
Example #6
0
    def test_parse_requirement(self, package):
        package.return_value = True
        content = """
-e common/lib/calc
South==1.0.1
pycrypto>=2.6
git+https://github.com/pmitros/pyfs.git@96e1922348bfe6d99201b9512a9ed946c87b7e0b
distribute>=0.6.28, <0.7
# bogus comment
-e .
pdfminer==20140328
-r production/requirements.txt
--requirement test.txt
        """
        r = RequirementFile("r.txt", content=content)

        self.assertEqual(
            r.other_files, [
                "production/requirements.txt",
                "test.txt"
            ]
        )

        self.assertEqual(
            r.requirements, [
                Requirement.parse("South==1.0.1", 3),
                Requirement.parse("pycrypto>=2.6", 4),
                Requirement.parse("distribute>=0.6.28, <0.7", 6),
                Requirement.parse("pdfminer==20140328", 3),
            ]
        )
Example #7
0
    def test_parse_comment_line(self):
        content = """
# the comment is here
        """
        r = RequirementFile("r.txt", content=content)
        self.assertEqual(r.requirements, [])
        self.assertEqual(r._other_files, [])
Example #8
0
 def test_tox_ini(self, _):
     with patch('pyup.requirements.Requirement.latest_version_within_specs',
                new_callable=PropertyMock,
                return_value="2.9.5"):
         content = "[testenv:bandit]\n" \
                   "commands =\n" \
                   "\tbandit --ini setup.cfg -ii -l --recursive project_directory\n" \
                   "deps =\n" \
                   "\tbandit==1.4.0\n" \
                   "\n" \
                   "[testenv:manifest]\n" \
                   "commands =\n" \
                   "\tcheck-manifest --verbose\n"
         req_file = RequirementFile("tox.ini", content)
         req = list(req_file.requirements)[0]
         self.assertEqual(
             Requirement.parse("bandit==1.4.0", 1),
             req
         )
         updated = req.update_content(content)
         new_content = "[testenv:bandit]\n" \
                   "commands =\n" \
                   "\tbandit --ini setup.cfg -ii -l --recursive project_directory\n" \
                   "deps =\n" \
                   "\tbandit==2.9.5\n" \
                   "\n" \
                   "[testenv:manifest]\n" \
                   "commands =\n" \
                   "\tcheck-manifest --verbose\n"
         self.assertEqual(updated, new_content)
Example #9
0
    def test_is_invalid(self):
        content = ''
        r = RequirementFile("r.txt", content=content)
        self.assertEqual(r._is_valid, None)

        # this triggers the _parse
        self.assertEqual(r.is_valid, False)
        self.assertEqual(r._is_valid, False)
Example #10
0
    def test_is_valid_other_file(self):
        content = '-r other_file.txt'
        r = RequirementFile("r.txt", content=content)
        self.assertEqual(r._is_valid, None)

        # this triggers the _parse
        self.assertEqual(r.is_valid, True)
        self.assertEqual(r._is_valid, True)
Example #11
0
    def test_requirements(self):
        with patch('pyup.requirements.Requirement.package',
                   return_value=Mock()):
            reqs = RequirementsBundle()
            reqs.append(RequirementFile(path="r.txt", content='Bla\nFoo'))

            self.assertEqual(
                [Requirement.parse("Bla", 1),
                 Requirement.parse("Foo", 2)], [r for r in reqs.requirements])
Example #12
0
    def test_is_valid_requirement(self):
        with patch('pyup.requirements.Requirement.package', return_value=True):
            content = 'some_package'
            r = RequirementFile("r.txt", content=content)
            self.assertEqual(r._is_valid, None)

            # this triggers the _parse
            self.assertEqual(r.is_valid, True)
            self.assertEqual(r._is_valid, True)
Example #13
0
    def test_ignore_file(self, package):
        package.return_value = True
        content = """# pyup: ignore file
foo
bar
baz"""
        r = RequirementFile("r.txt", content=content)
        self.assertEqual(r.requirements, [])
        self.assertEqual(r._other_files, [])
        self.assertEqual(r.is_valid, False)
Example #14
0
    def test_multispace(self):

        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="2.9.5"):
            content = "                   pass"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(Requirement.parse("pass", 1), req)
            updated = req.update_content(content)
            self.assertEqual(updated, "pass==2.9.5")
Example #15
0
 def test_parse_hashes(self):
     with open(
             os.path.dirname(os.path.realpath(__file__)) +
             "/data/hashed_reqs.txt") as f:
         content = f.read()
         r = RequirementFile("r.txt", content)
         self.assertEqual([
             Requirement.parse("alembic==0.8.9", 1),
             Requirement.parse("amqp==2.1.1", 3),
             Requirement.parse("argon2-cffi==16.3.0", 6),
             Requirement.parse("Babel==2.3.4", 8),
         ], list(r.requirements))
Example #16
0
    def test_file_found_with_reference(self):
        bot = bot_factory()
        bot.req_bundle.has_file_in_path = Mock()
        bot.req_bundle.append = Mock()
        req_file = RequirementFile("path", "-r foo.txt")
        bot.provider.get_requirement_file.side_effect = [req_file, None]

        bot.req_bundle.has_file_in_path.return_value = False

        bot.add_requirement_file("path")

        self.assertEqual(bot.provider.get_requirement_file.called, True)
        self.assertEqual(bot.req_bundle.append.called, True)
Example #17
0
    def test_update_contains_correct_sep_char(self):

        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="2.9.5"):
            content = "Jinja2==2.9.4         # via flask"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("Jinja2==2.9.4         # via flask", 1), req)

            self.assertEqual(req.update_content(content),
                             "Jinja2==2.9.5         # via flask")
Example #18
0
    def test_file_found_single(self):
        bot = bot_factory()
        bot.req_bundle.has_file_in_path = Mock()
        bot.req_bundle.append = Mock()
        req_file = RequirementFile("path", "")
        bot.provider.get_requirement_file.return_value = req_file

        bot.req_bundle.has_file_in_path.return_value = False

        bot.add_requirement_file("path", )

        self.assertEqual(bot.provider.get_requirement_file.called, True)
        self.assertEqual(bot.req_bundle.append.called, True)
Example #19
0
    def test_unsupported_line_start(self):
        content = """
-f foo
--find-links bla
-i bla
--index-url bla
--extra-index-url bla
--no-index bla
--allow-external
--allow-unverified
-Z
--always-unzip
        """
        r = RequirementFile("r.txt", content=content)
        self.assertEqual(r.requirements, [])
        self.assertEqual(r._other_files, [])
Example #20
0
 def test_line_endings(self):
     with patch('pyup.requirements.Requirement.latest_version', new_callable=PropertyMock,
                return_value="1.2.3"):
         with patch('pyup.requirements.Requirement.package', new_callable=PropertyMock,
                    return_value=package_factory("Foo", [])):
             content = """\r\n\r\nWerkzeug\r\ndjango-template-repl\nbpython\nsome-fooo    \n"""
             r = RequirementFile("foo.txt", content)
             self.assertEqual(r.requirements[0].name, "Werkzeug")
             self.assertEqual(r.requirements[1].name, "django-template-repl")
             self.assertEqual(r.requirements[2].name, "bpython")
             self.assertEqual(r.requirements[3].name, "some-fooo")
             self.assertTrue("Werkzeug==1.2.3\r\n" in r.requirements[0].update_content(content))
             self.assertTrue(
                 "django-template-repl==1.2.3\n" in r.requirements[1].update_content(content))
             self.assertTrue(
                 "bpython==1.2.3" in r.requirements[2].update_content(content))
             self.assertTrue(
                 "some-fooo==1.2.3    \n" in r.requirements[3].update_content(content))
Example #21
0
    def test_update_with_hashes(self, get_hashes_mock):
        get_hashes_mock.return_value = {
            "hashes": [{"hash": "123"}, {"hash": "456"}]
        }
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "alembic==0.8.9 \\\n" \
                      "        --hash=sha256:abcde"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("alembic==0.8.9", 1),
                req
            )

            self.assertEqual(req.update_content(content), "alembic==1.4.2 \\\n"
                                                          "    --hash=sha256:123 \\\n"
                                                          "    --hash=sha256:456")
Example #22
0
    def test_taskcluster_215(self, get_hashes_mock):
        get_hashes_mock.return_value = {
            "hashes": [{"hash": "123"}, {"hash": "456"}]
        }
        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="1.4.2"):
            content = "taskcluster==0.3.4 --hash sha256:d4fe5e2a44fe27e195b92830ece0a6eb9eb7ad9dc556a0cb16f6f2a6429f1b65"
            req_file = RequirementFile("req.txt", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("taskcluster==0.3.4", 1),
                req
            )

            new_content = req.update_content(content)
            self.assertEqual(new_content, "taskcluster==1.4.2 \\\n"
                                          "    --hash=sha256:123 \\\n"
                                          "    --hash=sha256:456")
Example #23
0
    def test_conda_file(self, _):

        with patch('pyup.requirements.Requirement.latest_version_within_specs',
                   new_callable=PropertyMock,
                   return_value="2.9.5"):
            content = "name: my_env\n" \
                      "dependencies:\n" \
                      "  - gevent=1.2.1\n" \
                      "  - pip:\n" \
                      "    - beautifulsoup4==1.2.3\n"
            req_file = RequirementFile("req.yml", content)
            req = list(req_file.requirements)[0]
            self.assertEqual(
                Requirement.parse("beautifulsoup4==1.2.3", 1),
                req
            )
            updated = req.update_content(content)
            new_content = "name: my_env\n" \
                      "dependencies:\n" \
                      "  - gevent=1.2.1\n" \
                      "  - pip:\n" \
                      "    - beautifulsoup4==2.9.5\n"
            self.assertEqual(updated, new_content)
Example #24
0
 def test_has_file(self):
     reqs = RequirementsBundle()
     self.assertEqual(reqs.has_file_in_path("foo.txt"), False)
     self.assertEqual(reqs.has_file_in_path(""), False)
     reqs.append(RequirementFile(path="foo.txt", content=''))
     self.assertEqual(reqs.has_file_in_path("foo.txt"), True)
Example #25
0
 def test_add(self):
     reqs = RequirementsBundle()
     self.assertEqual(reqs, [])
     reqs.append(RequirementFile(path="foo.txt", content=''))
     self.assertEqual(reqs[0].path, "foo.txt")
Example #26
0
 def test_parse_package_with_index_server(self, package):
     content = """-i https://some.foo/\ndjango"""
     r = RequirementFile("r.txt", content=content)
     self.assertEqual(r.requirements[0].index_server, "https://some.foo/")
Example #27
0
 def test_parse_empty_line(self):
     content = """
     """
     r = RequirementFile("r.txt", content=content)
     self.assertEqual(r.requirements, [])
     self.assertEqual(r._other_files, [])
Example #28
0
 def test_init_with_reqs(self):
     with patch("pyup.requirements.Requirement") as req:
         req.needs_update = True
         req_files = [RequirementFile("req.txt", "django")]
         update = Update(req_files, self.config)
         self.assertEqual(len(update.keys()), 1)
Example #29
0
 def test_parse_empty_line(self):
     r = RequirementFile("foo.txt", "\n\n\n\n\n")
     self.assertEqual(r.requirements, [])