Ejemplo n.º 1
0
    def test_api_projects_names(self):
        """ Test the api_projects_names function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/projects/names')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {"projects": [], "total": 0}
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/projects/names/')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {"projects": ["geany", "R2spec", "subsurface"], "total": 3}
        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/names/?pattern=ge')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {"projects": ["geany"], "total": 1}
        self.assertEqual(data, exp)
Ejemplo n.º 2
0
    def test_create_project(self):
        """ Test the create_project function of Distro. """
        create_distro(self.session)
        self.assertEqual(2, model.Distro.all(self.session, count=True))

        anitya.lib.create_project(
            self.session,
            name='geany',
            homepage='http://www.geany.org/',
            version_url='http://www.geany.org/Download/Releases',
            regex='DEFAULT',
            user_mail='*****@*****.**',
        )

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 1)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org/')

        self.assertRaises(
            AnityaException,
            anitya.lib.create_project,
            self.session,
            name='geany',
            homepage='http://www.geany.org/',
            version_url='http://www.geany.org/Download/Releases',
            regex='DEFAULT',
            user_mail='*****@*****.**',
        )

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 1)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org/')
Ejemplo n.º 3
0
    def test_create_project(self):
        """ Test the create_project function of Distro. """
        create_distro(self.session)
        self.assertEqual(2, model.Distro.all(self.session, count=True))

        anitya.lib.create_project(
            self.session,
            name='geany',
            homepage='http://www.geany.org/',
            version_url='http://www.geany.org/Download/Releases',
            regex='DEFAULT',
            user_mail='*****@*****.**',
        )

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 1)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org/')

        self.assertRaises(
            AnityaException,
            anitya.lib.create_project,
            self.session,
            name='geany',
            homepage='http://www.geany.org/',
            version_url='http://www.geany.org/Download/Releases',
            regex='DEFAULT',
            user_mail='*****@*****.**',
        )

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 1)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org/')
Ejemplo n.º 4
0
    def test_projects(self):
        """ Test the projects function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/projects/')
        self.assertEqual(output.status_code, 200)

        expected = """
                <a href="http://www.geany.org/" target="_blank">
                  http://www.geany.org/
                </a>"""
        self.assertTrue(expected in output.data)

        expected = """
                <a href="https://fedorahosted.org/r2spec/" target="_blank">
                  https://fedorahosted.org/r2spec/
                </a>"""
        self.assertTrue(expected in output.data)

        expected = """
                <a href="http://subsurface.hohndel.org/" target="_blank">
                  http://subsurface.hohndel.org/
                </a>"""
        self.assertTrue(expected in output.data)

        self.assertEqual(output.data.count('<a href="/project/'), 3)

        output = self.app.get('/projects/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertEqual(output.data.count('<a href="/project/'), 3)
Ejemplo n.º 5
0
    def test_projects_search(self):
        """ Test the projects_search function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get("/projects/search/g")
        self.assertEqual(output.status_code, 200)
        self.assertEqual(output.data.count(b'<a href="/project/'), 1)

        output = self.app.get("/projects/search/g*")
        self.assertEqual(output.status_code, 200)
        expected = b"""
                  <a href="http://www.geany.org/" target="_blank">
                    http://www.geany.org/
                  </a>"""
        self.assertTrue(expected in output.data)

        self.assertEqual(output.data.count(b'<a href="/project/'), 1)

        output = self.app.get("/projects/search/?page=ab")
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
        self.assertEqual(output.data.count(b'<a href="/project/'), 3)

        output = self.app.get("/projects/search/geany*", follow_redirects=True)
        self.assertEqual(output.status_code, 200)

        expected = (
            b'<li class="list-group-item list-group-item-default">'
            b"Only one result matching with an "
            b"exact match, redirecting</li>"
        )
        self.assertTrue(expected in output.data)
Ejemplo n.º 6
0
    def test_projects_search(self):
        """ Test the projects_search function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/projects/search/g')
        self.assertEqual(output.status_code, 200)
        self.assertEqual(output.data.count('<a href="/project/'), 1)

        output = self.app.get('/projects/search/g*')
        self.assertEqual(output.status_code, 200)
        expected = """
                  <a href="http://www.geany.org/" target="_blank">
                    http://www.geany.org/
                  </a>"""
        self.assertTrue(expected in output.data)

        self.assertEqual(output.data.count('<a href="/project/'), 1)

        output = self.app.get('/projects/search/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
        self.assertEqual(output.data.count('<a href="/project/'), 3)

        output = self.app.get('/projects/search/geany*', follow_redirects=True)
        self.assertEqual(output.status_code, 200)

        expected = '<li class="list-group-item list-group-item-default">' \
            'Only one result matching with an ' \
            'exact match, redirecting</li>'
        self.assertTrue(expected in output.data)
Ejemplo n.º 7
0
    def test_projects(self):
        """ Test the projects function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/projects/')
        self.assertEqual(output.status_code, 200)

        expected = """
                <a href="http://www.geany.org/" target="_blank">
                  http://www.geany.org/
                </a>"""
        self.assertTrue(expected in output.data)

        expected = """
                <a href="https://fedorahosted.org/r2spec/" target="_blank">
                  https://fedorahosted.org/r2spec/
                </a>"""
        self.assertTrue(expected in output.data)

        expected = """
                <a href="http://subsurface.hohndel.org/" target="_blank">
                  http://subsurface.hohndel.org/
                </a>"""
        self.assertTrue(expected in output.data)

        self.assertEqual(output.data.count('<a href="/project/'), 3)

        output = self.app.get('/projects/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertEqual(output.data.count('<a href="/project/'), 3)
Ejemplo n.º 8
0
    def test_projects_search(self):
        """ Test the projects_search function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/projects/search/g')
        self.assertEqual(output.status_code, 200)

        expected = """
                  <a href="http://www.geany.org/" target="_blank">
                    http://www.geany.org/
                  </a>"""
        self.assertTrue(expected in output.data)

        self.assertEqual(output.data.count('<a href="/project/'), 1)

        output = self.app.get('/projects/search/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
        self.assertEqual(output.data.count('<a href="/project/'), 3)

        output = self.app.get(
            '/projects/search/geany*', follow_redirects=True)
        self.assertEqual(output.status_code, 200)

        expected = '<li class="message">Only one result matching with an '\
            'exact match, redirecting</li>'
        self.assertTrue(expected in output.data)
Ejemplo n.º 9
0
    def test_distro(self):
        """ Test the distro function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/distro/Fedora/')
        self.assertEqual(output.status_code, 200)

        expected = b"""
  <blockquote>
      Oups this is embarrassing, it seems that no projects are being
      monitored currently.
  </blockquote>"""
        self.assertTrue(expected in output.data)
        self.assertTrue(b'form action="/distro/Fedora/search/" role="form" '
                        b'class="form-inline">' in output.data)
        self.assertTrue(
            b'<h1>Projects of Fedora monitored</h1>' in output.data)

        output = self.app.get('/distro/Fedora/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
        self.assertTrue(b'form action="/distro/Fedora/search/" role="form" '
                        b'class="form-inline">' in output.data)
        self.assertTrue(
            b'<h1>Projects of Fedora monitored</h1>' in output.data)
Ejemplo n.º 10
0
    def test_distro(self):
        """ Test the distro function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/distro/Fedora/')
        self.assertEqual(output.status_code, 200)

        expected = """
  <blockquote>
      Oups this is embarrassing, it seems that no projects are being
      monitored currently.
  </blockquote>"""
        self.assertTrue(expected in output.data)
        self.assertTrue(
            'form action="/distro/Fedora/search/" role="form">'
            in output.data)
        self.assertTrue(
            '<h1>Projects of Fedora monitored</h1>' in output.data)

        output = self.app.get('/distro/Fedora/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
        self.assertTrue(
            'form action="/distro/Fedora/search/" role="form">'
            in output.data)
        self.assertTrue(
            '<h1>Projects of Fedora monitored</h1>' in output.data)
Ejemplo n.º 11
0
    def test_packages__repr__(self):
        """ Test the Packages.__repr__ function. """
        create_project(self.session)
        create_distro(self.session)
        create_package(self.session)

        pkg = model.Packages.by_id(self.session, 1)
        self.assertEqual(str(pkg), '<Packages(1, Fedora: geany)>')
Ejemplo n.º 12
0
    def test_init_distro(self):
        """ Test the __init__ function of Distro. """
        create_distro(self.session)
        self.assertEqual(2, model.Distro.all(self.session, count=True))

        distros = model.Distro.all(self.session)
        self.assertEqual(distros[0].name, 'Debian')
        self.assertEqual(distros[1].name, 'Fedora')
Ejemplo n.º 13
0
    def test_init_distro(self):
        """ Test the __init__ function of Distro. """
        create_distro(self.session)
        self.assertEqual(2, model.Distro.all(self.session, count=True))

        distros = model.Distro.all(self.session)
        self.assertEqual(distros[0].name, 'Debian')
        self.assertEqual(distros[1].name, 'Fedora')
Ejemplo n.º 14
0
    def test_packages__repr__(self):
        """ Test the Packages.__repr__ function. """
        create_project(self.session)
        create_distro(self.session)
        create_package(self.session)

        pkg = model.Packages.by_id(self.session, 1)
        self.assertEqual(str(pkg), '<Packages(1, Fedora: geany)>')
Ejemplo n.º 15
0
    def test_packages_by_id(self):
        """ Test the Packages.by_id function. """
        create_project(self.session)
        create_distro(self.session)
        create_package(self.session)

        pkg = model.Packages.by_id(self.session, 1)
        self.assertEqual(pkg.package_name, 'geany')
        self.assertEqual(pkg.distro, 'Fedora')
Ejemplo n.º 16
0
    def test_packages_by_id(self):
        """ Test the Packages.by_id function. """
        create_project(self.session)
        create_distro(self.session)
        create_package(self.session)

        pkg = model.Packages.by_id(self.session, 1)
        self.assertEqual(pkg.package_name, 'geany')
        self.assertEqual(pkg.distro, 'Fedora')
Ejemplo n.º 17
0
    def test_distro_all(self):
        """ Test the all function of Distro. """
        create_distro(self.session)

        distro = model.Distro.all(self.session, page=2)
        self.assertEqual(distro, [])

        distro = model.Distro.all(self.session, page='b')
        distro2 = model.Distro.all(self.session)
        self.assertEqual(distro, distro2)
Ejemplo n.º 18
0
    def test_distro_search(self):
        """ Test the search function of Distro. """
        create_distro(self.session)

        distro = model.Distro.search(self.session, 'fed')
        self.assertEqual(distro, [])

        distro = model.Distro.search(self.session, 'fed*')
        self.assertNotEqual(distro, [])
        self.assertEqual(distro[0].name, 'Fedora')
        self.assertEqual(len(distro), 1)
Ejemplo n.º 19
0
    def test_distro_get_or_create(self):
        """ Test the get_or_create function of Distro. """
        create_distro(self.session)

        distro = model.Distro.get_or_create(self.session, 'fedora')
        self.assertEqual(distro.name, 'Fedora')
        self.assertEqual(2, model.Distro.all(self.session, count=True))

        distro = model.Distro.get_or_create(self.session, 'CentOS')
        self.assertEqual(distro.name, 'CentOS')
        self.assertEqual(3, model.Distro.all(self.session, count=True))
Ejemplo n.º 20
0
    def test_api_get_project_distro(self):
        """ Test the api_get_project_distro function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/project/Fedora/geany')
        self.assertEqual(output.status_code, 404)
        data = json.loads(output.data)

        exp = {
            "error": "No package \"geany\" found in distro \"Fedora\"",
            "output": "notok"
        }
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/project/Fedora/gnome-terminal/')
        self.assertEqual(output.status_code, 404)
        data = json.loads(output.data)

        exp = {
            "error": "No package \"gnome-terminal\" found in distro "
                     "\"Fedora\"",
            "output": "notok"
        }
        self.assertEqual(data, exp)

        output = self.app.get('/api/project/Fedora/geany/')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        del(data['created_on'])
        del(data['updated_on'])

        exp = {
            "id": 1,
            "backend": "custom",
            "homepage": "http://www.geany.org/",
            "name": "geany",
            "regex": 'DEFAULT',
            "version": None,
            "version_url": 'http://www.geany.org/Download/Releases',
            "versions": [],
            "packages": [
                {
                  "distro": "Fedora",
                  "package_name": "geany"
                }
            ],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 21
0
    def test_distros(self):
        """ Test the distros function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/distros/')
        self.assertEqual(output.status_code, 200)

        expected = "Here is the list of all the distributions"
        self.assertTrue(expected in output.data)

        output = self.app.get('/distros/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
Ejemplo n.º 22
0
    def test_distros(self):
        """ Test the distros function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/distros/')
        self.assertEqual(output.status_code, 200)

        expected = "Here is the list of all the distributions"
        self.assertTrue(expected in output.data)

        output = self.app.get('/distros/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
Ejemplo n.º 23
0
    def test_api_get_project_distro(self):
        """ Test the api_get_project_distro function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/project/Fedora/geany')
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {
            "error": "No package \"geany\" found in distro \"Fedora\"",
            "output": "notok"
        }
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/project/Fedora/gnome-terminal/')
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {
            "error": "No package \"gnome-terminal\" found in distro "
            "\"Fedora\"",
            "output": "notok"
        }
        self.assertEqual(data, exp)

        output = self.app.get('/api/project/Fedora/geany/')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        del (data['created_on'])
        del (data['updated_on'])

        exp = {
            "id": 1,
            "backend": "custom",
            "homepage": "http://www.geany.org/",
            "name": "geany",
            "regex": 'DEFAULT',
            "version": None,
            "version_url": 'http://www.geany.org/Download/Releases',
            "versions": [],
            "packages": [{
                "distro": "Fedora",
                "package_name": "geany"
            }],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 24
0
    def test_distro_by_name(self):
        """ Test the by_name function of Distro. """
        create_distro(self.session)

        distro = model.Distro.by_name(self.session, 'fedora')
        self.assertEqual(distro.name, 'Fedora')

        distro = model.Distro.get(self.session, 'fedora')
        self.assertEqual(distro.name, 'Fedora')

        distro = model.Distro.by_name(self.session, 'DEBIAN')
        self.assertEqual(distro.name, 'Debian')

        distro = model.Distro.get(self.session, 'DEBIAN')
        self.assertEqual(distro.name, 'Debian')
Ejemplo n.º 25
0
    def test_project(self):
        """ Test the project function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/project/1/')
        self.assertEqual(output.status_code, 200)

        expected = """
            <p><a property="doap:homepage" href="http://www.geany.org/"
               target="_blank">http://www.geany.org/
             </a><p>"""

        self.assertTrue(expected in output.data)

        output = self.app.get('/project/10/')
        self.assertEqual(output.status_code, 404)
Ejemplo n.º 26
0
    def test_distro_projects_search(self):
        """ Test the distro_projects_search function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/distro/Fedora/search/gua')
        self.assertEqual(output.status_code, 200)

        expected = """
    <blockquote>
        Oups this is embarrassing, it seems that no projects are being
        monitored currently.
    </blockquote>"""
        self.assertTrue(expected in output.data)
        self.assertTrue(
            'form action="/distro/Fedora/search/" role="form">' in output.data)
        self.assertTrue('<h1>Search projects in Fedora</h1>' in output.data)
Ejemplo n.º 27
0
    def test_api_packages_wiki_list(self):
        """ Test the api_packages_wiki_list function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/packages/wiki/')
        self.assertEqual(output.status_code, 200)

        self.assertEqual(output.data, '')

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/packages/wiki/')
        self.assertEqual(output.status_code, 200)

        exp = "* geany DEFAULT http://www.geany.org/Download/Releases\n"\
            "* subsurface DEFAULT http://subsurface.hohndel.org/downloads/"
        self.assertEqual(output.data, exp)
Ejemplo n.º 28
0
    def test_api_packages_wiki_list(self):
        """ Test the api_packages_wiki_list function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/packages/wiki/')
        self.assertEqual(output.status_code, 200)

        self.assertEqual(output.data, b'')

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/packages/wiki/')
        self.assertEqual(output.status_code, 200)

        exp = b"* geany DEFAULT http://www.geany.org/Download/Releases\n"\
            b"* subsurface DEFAULT http://subsurface.hohndel.org/downloads/"
        self.assertEqual(output.data, exp)
Ejemplo n.º 29
0
    def test_distro_projects_search(self):
        """ Test the distro_projects_search function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get("/distro/Fedora/search/gua")
        self.assertEqual(output.status_code, 200)

        expected = b"""
    <blockquote>
        Oups this is embarrassing, it seems that no projects are being
        monitored currently.
        <p><a href="/project/new?name=gua">Click Here</a> to add this project instead. </p>
    </blockquote>"""
        self.assertTrue(expected in output.data)
        self.assertTrue(b'form action="/distro/Fedora/search/" role="form">' in output.data)
        self.assertTrue(b"<h1>Search projects in Fedora</h1>" in output.data)
Ejemplo n.º 30
0
    def test_project(self):
        """ Test the project function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/project/1/')
        self.assertEqual(output.status_code, 200)

        expected = """
            <p><a property="doap:homepage" href="http://www.geany.org/"
               target="_blank">http://www.geany.org/
             </a><p>"""

        self.assertTrue(expected in output.data)

        output = self.app.get('/project/10/')
        self.assertEqual(output.status_code, 404)
Ejemplo n.º 31
0
    def test_api_get_project_by_ecosystem(self):
        """ Test the api_get_project_ecosystem function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/by_ecosystem/pypi/pypi_and_npm')
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {
            "error": 'No project "pypi_and_npm" found in ecosystem "pypi"',
            "output": "notok"
        }
        self.assertEqual(data, exp)

        create_ecosystem_projects(self.session)

        output = self.app.get('/api/by_ecosystem/pypi/not-a-project')
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {
            "error": 'No project "not-a-project" found in ecosystem "pypi"',
            "output": "notok"
        }
        self.assertEqual(data, exp)

        output = self.app.get('/api/by_ecosystem/pypi/pypi_and_npm')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        del (data['created_on'])
        del (data['updated_on'])

        exp = {
            "id": 1,
            "backend": "PyPI",
            "homepage": "https://example.com/not-a-real-pypi-project",
            "name": "pypi_and_npm",
            "regex": None,
            "version": None,
            "version_url": None,
            "versions": [],
            "packages": [],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 32
0
    def test_api_get_project_by_ecosystem(self):
        """ Test the api_get_project_ecosystem function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/by_ecosystem/pypi/pypi_and_npm')
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {
            "error": 'No project "pypi_and_npm" found in ecosystem "pypi"',
            "output": "notok"
        }
        self.assertEqual(data, exp)

        create_ecosystem_projects(self.session)

        output = self.app.get('/api/by_ecosystem/pypi/not-a-project')
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {
            "error": 'No project "not-a-project" found in ecosystem "pypi"',
            "output": "notok"
        }
        self.assertEqual(data, exp)

        output = self.app.get('/api/by_ecosystem/pypi/pypi_and_npm')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        del(data['created_on'])
        del(data['updated_on'])

        exp = {
            "id": 1,
            "backend": "PyPI",
            "homepage": "https://example.com/not-a-real-pypi-project",
            "name": "pypi_and_npm",
            "regex": None,
            "version": None,
            "version_url": None,
            "versions": [],
            "packages": [],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 33
0
    def test_edit_project(self):
        """ Test the edit_project function of Distro. """
        create_distro(self.session)
        create_project(self.session)

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 3)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org/')
        self.assertEqual(project_objs[1].name, 'R2spec')
        self.assertEqual(project_objs[2].name, 'subsurface')

        anitya.lib.edit_project(
            self.session,
            project=project_objs[0],
            name=project_objs[0].name,
            homepage='http://www.geany.org',
            backend='PyPI',
            version_url=None,
            version_prefix=None,
            regex=None,
            insecure=False,
            user_id='*****@*****.**')

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 3)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org')
        self.assertEqual(project_objs[1].name, 'R2spec')
        self.assertEqual(project_objs[2].name, 'subsurface')

        self.assertRaises(
            AnityaException,
            anitya.lib.edit_project,
            self.session,
            project=project_objs[2],
            name='geany',
            homepage='http://www.geany.org',
            backend=project_objs[2].backend,
            version_url=project_objs[2].version_url,
            version_prefix=None,
            regex=project_objs[2].regex,
            insecure=False,
            user_id='*****@*****.**',
        )
Ejemplo n.º 34
0
    def test_distro_search(self):
        """ Test the Distro.search function. """
        create_distro(self.session)

        logs = model.Distro.search(self.session, '*', count=True)
        self.assertEqual(logs, 2)

        logs = model.Distro.search(self.session, 'Fed*')
        self.assertEqual(len(logs), 1)
        self.assertEqual(logs[0].name, 'Fedora')

        logs = model.Distro.search(self.session, 'Fed*', page=1)
        self.assertEqual(len(logs), 1)
        self.assertEqual(logs[0].name, 'Fedora')

        logs = model.Distro.search(self.session, 'Fed*', page='as')
        self.assertEqual(len(logs), 1)
        self.assertEqual(logs[0].name, 'Fedora')
Ejemplo n.º 35
0
    def test_distros(self):
        """ Test the distros function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/distros/')
        self.assertEqual(output.status_code, 200)

        expected = """
  <p>
    Here is the list of all the distribution having at least one project
    mapped as a package of this distribution and monitored by anitya.
  </p>"""
        self.assertTrue(expected in output.data)

        output = self.app.get('/distros/?page=ab')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(expected in output.data)
Ejemplo n.º 36
0
    def test_distro_search(self):
        """ Test the Distro.search function. """
        create_distro(self.session)

        logs = model.Distro.search(self.session, '*', count=True)
        self.assertEqual(logs, 2)

        logs = model.Distro.search(self.session, 'Fed*')
        self.assertEqual(len(logs), 1)
        self.assertEqual(logs[0].name, 'Fedora')

        logs = model.Distro.search(self.session, 'Fed*', page=1)
        self.assertEqual(len(logs), 1)
        self.assertEqual(logs[0].name, 'Fedora')

        logs = model.Distro.search(self.session, 'Fed*', page='as')
        self.assertEqual(len(logs), 1)
        self.assertEqual(logs[0].name, 'Fedora')
Ejemplo n.º 37
0
    def test_edit_project(self):
        """ Test the edit_project function of Distro. """
        create_distro(self.session)
        create_project(self.session)

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 3)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org/')
        self.assertEqual(project_objs[1].name, 'R2spec')
        self.assertEqual(project_objs[2].name, 'subsurface')

        anitya.lib.edit_project(self.session,
                                project=project_objs[0],
                                name=project_objs[0].name,
                                homepage='http://www.geany.org',
                                backend='PyPI',
                                version_url=None,
                                version_prefix=None,
                                regex=None,
                                insecure=False,
                                user_mail='*****@*****.**')

        project_objs = anitya.lib.model.Project.all(self.session)
        self.assertEqual(len(project_objs), 3)
        self.assertEqual(project_objs[0].name, 'geany')
        self.assertEqual(project_objs[0].homepage, 'http://www.geany.org')
        self.assertEqual(project_objs[1].name, 'R2spec')
        self.assertEqual(project_objs[2].name, 'subsurface')

        self.assertRaises(
            AnityaException,
            anitya.lib.edit_project,
            self.session,
            project=project_objs[2],
            name='geany',
            homepage='http://www.geany.org',
            backend=project_objs[2].backend,
            version_url=project_objs[2].version_url,
            version_prefix=None,
            regex=project_objs[2].regex,
            insecure=False,
            user_mail='*****@*****.**',
        )
Ejemplo n.º 38
0
    def test_api_get_project(self):
        """ Test the api_get_project function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/project/')
        self.assertEqual(output.status_code, 404)

        output = self.app.get('/api/project/10')
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {"error": "no such project", "output": "notok"}
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/project/10')
        self.assertEqual(output.status_code, 404)

        output = self.app.get('/api/project/1')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        del(data['created_on'])
        del(data['updated_on'])

        exp = {
            "id": 1,
            "backend": "custom",
            "homepage": "http://www.geany.org/",
            "name": "geany",
            "regex": 'DEFAULT',
            "version": None,
            "version_url": 'http://www.geany.org/Download/Releases',
            "versions": [],
            "packages": [
                {
                  "distro": "Fedora",
                  "package_name": "geany"
                }
            ],
        }

        self.assertEqual(exp, data)
Ejemplo n.º 39
0
    def test_api_get_project(self):
        """ Test the api_get_project function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/project/')
        self.assertEqual(output.status_code, 404)

        output = self.app.get('/api/project/10')
        self.assertEqual(output.status_code, 404)
        data = json.loads(output.data)

        exp = {"error": "no such project", "output": "notok"}
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/project/10')
        self.assertEqual(output.status_code, 404)

        output = self.app.get('/api/project/1')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        del (data['created_on'])
        del (data['updated_on'])

        exp = {
            "id": 1,
            "backend": "custom",
            "homepage": "http://www.geany.org/",
            "name": "geany",
            "regex": 'DEFAULT',
            "version": None,
            "version_url": 'http://www.geany.org/Download/Releases',
            "versions": [],
            "packages": [{
                "distro": "Fedora",
                "package_name": "geany"
            }],
        }

        self.assertEqual(exp, data)
Ejemplo n.º 40
0
    def test_api_projects_names(self):
        """ Test the api_projects_names function of the API. """
        create_distro(self.session)
        output = self.app.get('/api/projects/names')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        exp = {"projects": [], "total": 0}
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/api/projects/names/')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        exp = {
            "projects": [
                "geany",
                "R2spec",
                "subsurface"
            ],
            "total": 3
        }
        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/names/?pattern=ge')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        exp = {
            "projects": [
                "geany"
            ],
            "total": 1
        }
        self.assertEqual(data, exp)
Ejemplo n.º 41
0
    def test_delete_project_mapping(self):
        """ Test the delete_project_mapping function. """
        create_distro(self.session)
        create_project(self.session)
        create_package(self.session)

        output = self.app.get('/project/1/delete/Fedora/geany',
                              follow_redirects=True)
        self.assertEqual(output.status_code, 200)
        self.assertTrue(b'<ul id="flashes" class="list-group">'
                        b'<li class="list-group-item list-group-item-warning">'
                        b'Login required</li></ul>' in output.data)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'openid_url'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/100/delete/Fedora/geany',
                           follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/delete/CentOS/geany',
                           follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/delete/Fedora/geany2',
                           follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/delete/Fedora/geany',
                           follow_redirects=True)
            self.assertEqual(output.status_code, 401)

        output = c.get('/project/1/')
        self.assertEqual(output.status_code, 200)
        self.assertTrue(b'<h1>Project: geany</h1>' in output.data)
        self.assertTrue(b'<td>Fedora</td>' in output.data)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'http://pingou.id.fedoraproject.org/'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/1/delete/Fedora/geany',
                           follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                b'<h1>Project: geany - Delete package</h1>' in output.data)
            self.assertTrue(b'<button type="submit" name="confirm" value="Yes"'
                            in output.data)

            data = {
                'confirm': 'Yes',
            }

            output = c.post('/project/1/delete/Fedora/geany',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                b'<h1>Project: geany - Delete package</h1>' in output.data)
            self.assertTrue(b'<button type="submit" name="confirm" value="Yes"'
                            in output.data)

            csrf_token = output.data.split(
                b'name="csrf_token" type="hidden" value="')[1].split(b'">')[0]

            data['csrf_token'] = csrf_token
            del (data['confirm'])

            output = c.post('/project/1/delete/Fedora/geany',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(b'<h1>Project: geany</h1>' in output.data)
            self.assertTrue(b'<td>Fedora</td>' in output.data)

            data['confirm'] = True

            output = c.post('/project/1/delete/Fedora/geany',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                b'class="list-group-item list-group-item-default">'
                b'Mapping for geany has been removed</li>' in output.data)
            self.assertTrue(b'<h1>Project: geany</h1>' in output.data)
            self.assertFalse(b'<td>Fedora</td>' in output.data)
Ejemplo n.º 42
0
    def test_map_project(self):
        """ Test the map_project function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/project/1/map', follow_redirects=True)
        self.assertEqual(output.status_code, 200)
        self.assertTrue(
            '<li class="errors">Login required</li>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'geany')
        self.assertEqual(len(projects[0].packages), 0)
        self.assertEqual(projects[0].id, 1)
        self.assertEqual(projects[1].name, 'R2spec')
        self.assertEqual(projects[1].id, 3)
        self.assertEqual(len(projects[1].packages), 0)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)
        self.assertEqual(len(projects[2].packages), 0)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'openid_url'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/10/map', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/map', follow_redirects=True)
            self.assertEqual(output.status_code, 200)

            self.assertTrue('<h1>Project: geany</h1>' in output.data)
            self.assertTrue(
                '<td><label for="distro">Distribution</label></td>'
                in output.data)

            data = {
                'package_name': 'geany',
                'distro': 'CentOS',
            }

            output = c.post(
                '/project/1/map', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Project: geany</h1>' in output.data)
            self.assertTrue(
                '<td><label for="distro">Distribution</label></td>'
                in output.data)

            # This should works just fine
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data['csrf_token'] = csrf_token

            output = c.post(
                '/project/1/map', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">Mapping added</li>' in output.data)
            self.assertTrue(
                '<h1>Project: geany</h1>' in output.data)

            # This should fail, the mapping already exists
            data = {
                'package_name': 'geany',
                'distro': 'CentOS',
                'csrf_token': csrf_token,
            }

            output = c.post(
                '/project/1/map', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">Could not edit the mapping of geany on '
                'CentOS, there is already a package geany on CentOS.</li>'
                in output.data)
            self.assertTrue(
                '<h1>Project: geany</h1>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'geany')
        self.assertEqual(projects[0].id, 1)
        self.assertEqual(len(projects[0].packages), 1)
        self.assertEqual(projects[0].packages[0].package_name, 'geany')
        self.assertEqual(projects[1].name, 'R2spec')
        self.assertEqual(projects[1].id, 3)
        self.assertEqual(len(projects[1].packages), 0)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)
        self.assertEqual(len(projects[2].packages), 0)
Ejemplo n.º 43
0
    def test_edit_project(self):
        """ Test the edit_project function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/project/1/edit', follow_redirects=True)
        self.assertEqual(output.status_code, 200)
        self.assertTrue(
            '<li class="errors">Login required</li>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'geany')
        self.assertEqual(projects[0].id, 1)
        self.assertEqual(projects[1].name, 'R2spec')
        self.assertEqual(projects[1].id, 3)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'openid_url'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/10/edit', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/edit', follow_redirects=True)
            self.assertEqual(output.status_code, 200)

            self.assertTrue('<h1>Edit project</h1>' in output.data)
            self.assertTrue(
                '<td><label for="regex">Regex</label></td>' in output.data)

            data = {
                'name': 'repo_manager',
                'homepage': 'https://pypi.python.org/pypi/repo_manager',
                'backend': 'pypi',
            }

            output = c.post(
                '/project/1/edit', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Edit project</h1>' in output.data)
            self.assertTrue(
                '<td><label for="regex">Regex</label></td>' in output.data)

            # This should works just fine
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data['csrf_token'] = csrf_token

            output = c.post(
                '/project/1/edit', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">Project edited</li>' in output.data)
            self.assertTrue(
                '<h1>Project: repo_manager</h1>' in output.data)

            # This should fail, the R2spec project already exists
            data = {
                'name': 'R2spec',
                'homepage': 'https://fedorahosted.org/r2spec/',
                'backend': 'folder',
                'csrf_token': csrf_token,
            }

            output = c.post(
                '/project/1/edit', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">Could not edit this project. Is there '
                'already a project with these name and homepage?</li>'
                in output.data)
            self.assertTrue(
                '<h1>Project: repo_manager</h1>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'R2spec')
        self.assertEqual(projects[0].id, 3)
        self.assertEqual(projects[1].name, 'repo_manager')
        self.assertEqual(projects[1].id, 1)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)
Ejemplo n.º 44
0
    def test_api_projects(self):
        """ Test the api_projects function of the API. """
        create_distro(self.session)

        output = self.app.get('/api/projects')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        exp = {"projects": [], "total": 0}
        self.assertEqual(data, exp)

        create_project(self.session)

        output = self.app.get('/api/projects/')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        for key in range(len(data['projects'])):
            del(data['projects'][key]['created_on'])
            del(data['projects'][key]['updated_on'])

        exp = {
            "projects": [
                {
                    "id": 1,
                    "backend": "custom",
                    "homepage": "http://www.geany.org/",
                    "name": "geany",
                    "regex": "DEFAULT",
                    "version": None,
                    "version_url": "http://www.geany.org/Download/Releases",
                    "versions": []
                },
                {
                    "id": 3,
                    "backend": "custom",
                    "homepage": "https://fedorahosted.org/r2spec/",
                    "name": "R2spec",
                    "regex": None,
                    "version": None,
                    "version_url": None,
                    "versions": []
                },
                {
                    "id": 2,
                    "backend": "custom",
                    "homepage": "http://subsurface.hohndel.org/",
                    "name": "subsurface",
                    "regex": "DEFAULT",
                    "version": None,
                    "version_url": "http://subsurface.hohndel.org/downloads/",
                    "versions": []
                }
            ],
            "total": 3
        }

        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/?pattern=ge')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        for key in range(len(data['projects'])):
            del(data['projects'][key]['created_on'])
            del(data['projects'][key]['updated_on'])

        exp = {
            "projects": [
                {
                    "id": 1,
                    "backend": "custom",
                    "homepage": "http://www.geany.org/",
                    "name": "geany",
                    "regex": "DEFAULT",
                    "version": None,
                    "version_url": "http://www.geany.org/Download/Releases",
                    "versions": [],
                },
            ],
            "total": 1
        }

        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/?homepage=http://www.geany.org/')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)

        for key in range(len(data['projects'])):
            del(data['projects'][key]['created_on'])
            del(data['projects'][key]['updated_on'])

        exp = {
            "projects": [
                {
                    "id": 1,
                    "backend": "custom",
                    "homepage": "http://www.geany.org/",
                    "name": "geany",
                    "regex": "DEFAULT",
                    "version": None,
                    "version_url": "http://www.geany.org/Download/Releases",
                    "versions": [],
                },
            ],
            "total": 1
        }

        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/?pattern=foo&homepage=bar')
        self.assertEqual(output.status_code, 400)
Ejemplo n.º 45
0
    def test_api_projects(self):
        """ Test the api_projects function of the API. """
        create_distro(self.session)

        output = self.app.get('/api/projects')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {"projects": [], "total": 0}
        self.assertEqual(data, exp)

        create_project(self.session)

        output = self.app.get('/api/projects/')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        for key in range(len(data['projects'])):
            del (data['projects'][key]['created_on'])
            del (data['projects'][key]['updated_on'])

        exp = {
            "projects": [{
                "id": 1,
                "backend": "custom",
                "homepage": "http://www.geany.org/",
                "name": "geany",
                "regex": "DEFAULT",
                "version": None,
                "version_url": "http://www.geany.org/Download/Releases",
                "versions": []
            }, {
                "id": 3,
                "backend": "custom",
                "homepage": "https://fedorahosted.org/r2spec/",
                "name": "R2spec",
                "regex": None,
                "version": None,
                "version_url": None,
                "versions": []
            }, {
                "id": 2,
                "backend": "custom",
                "homepage": "http://subsurface.hohndel.org/",
                "name": "subsurface",
                "regex": "DEFAULT",
                "version": None,
                "version_url": "http://subsurface.hohndel.org/downloads/",
                "versions": []
            }],
            "total":
            3
        }

        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/?pattern=ge')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        for key in range(len(data['projects'])):
            del (data['projects'][key]['created_on'])
            del (data['projects'][key]['updated_on'])

        exp = {
            "projects": [
                {
                    "id": 1,
                    "backend": "custom",
                    "homepage": "http://www.geany.org/",
                    "name": "geany",
                    "regex": "DEFAULT",
                    "version": None,
                    "version_url": "http://www.geany.org/Download/Releases",
                    "versions": [],
                },
            ],
            "total":
            1
        }

        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/?homepage=http://www.geany.org/')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        for key in range(len(data['projects'])):
            del (data['projects'][key]['created_on'])
            del (data['projects'][key]['updated_on'])

        exp = {
            "projects": [
                {
                    "id": 1,
                    "backend": "custom",
                    "homepage": "http://www.geany.org/",
                    "name": "geany",
                    "regex": "DEFAULT",
                    "version": None,
                    "version_url": "http://www.geany.org/Download/Releases",
                    "versions": [],
                },
            ],
            "total":
            1
        }

        self.assertEqual(data, exp)

        output = self.app.get('/api/projects/?pattern=foo&homepage=bar')
        self.assertEqual(output.status_code, 400)
Ejemplo n.º 46
0
    def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(MavenBackendTest, self).setUp()

        create_distro(self.session)
Ejemplo n.º 47
0
    def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(RubygemsBackendtests, self).setUp()

        create_distro(self.session)
        self.create_project()
Ejemplo n.º 48
0
    def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(Drupal7Backendtests, self).setUp()

        create_distro(self.session)
        self.create_project()
Ejemplo n.º 49
0
    def test_delete_project_mapping(self):
        """ Test the delete_project_mapping function. """
        create_distro(self.session)
        create_project(self.session)
        create_package(self.session)

        output = self.app.get(
            '/project/1/delete/Fedora/geany', follow_redirects=True)
        self.assertEqual(output.status_code, 200)
        self.assertTrue(
            '<li class="errors">Login required</li>' in output.data)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'openid_url'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get(
                '/project/100/delete/Fedora/geany', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get(
                '/project/1/delete/CentOS/geany', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get(
                '/project/1/delete/Fedora/geany2', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get(
                '/project/1/delete/Fedora/geany', follow_redirects=True)
            self.assertEqual(output.status_code, 401)

        output = c.get('/project/1/')
        self.assertEqual(output.status_code, 200)
        self.assertTrue('<h1>Project: geany</h1>' in output.data)
        self.assertTrue('<td>Fedora</td>' in output.data)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'http://pingou.id.fedoraproject.org/'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/1/delete/Fedora/geany', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Project: geany - Delete package</h1>' in output.data)
            self.assertTrue(
                '<button type="submit" name="confirm" value="Yes"'
                in output.data)

            data = {
                'confirm': 'Yes',
            }

            output = c.post(
                '/project/1/delete/Fedora/geany', data=data,
                follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Project: geany - Delete package</h1>' in output.data)
            self.assertTrue(
                '<button type="submit" name="confirm" value="Yes"'
                in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data['csrf_token'] = csrf_token
            del(data['confirm'])

            output = c.post(
                '/project/1/delete/Fedora/geany', data=data,
                follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Project: geany</h1>' in output.data)
            self.assertTrue('<td>Fedora</td>' in output.data)

            data['confirm'] = True

            output = c.post(
                '/project/1/delete/Fedora/geany', data=data,
                follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                'class="message">Mapping for geany has been removed</li>'
                in output.data)
            self.assertTrue('<h1>Project: geany</h1>' in output.data)
            self.assertFalse('<td>Fedora</td>' in output.data)
Ejemplo n.º 50
0
    def test_map_project(self):
        """ Test the map_project function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/project/1/map', follow_redirects=True)
        self.assertEqual(output.status_code, 200)
        self.assertTrue('<ul id="flashes" class="list-group">'
                        '<li class="list-group-item list-group-item-warning">'
                        'Login required</li></ul>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'geany')
        self.assertEqual(len(projects[0].packages), 0)
        self.assertEqual(projects[0].id, 1)
        self.assertEqual(projects[1].name, 'R2spec')
        self.assertEqual(projects[1].id, 3)
        self.assertEqual(len(projects[1].packages), 0)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)
        self.assertEqual(len(projects[2].packages), 0)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'openid_url'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/10/map', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/map', follow_redirects=True)
            self.assertEqual(output.status_code, 200)

            self.assertTrue('<h1>Project: geany</h1>' in output.data)
            self.assertTrue('<td><label for="distro">Distribution</label></td>'
                            in output.data)

            data = {
                'package_name': 'geany',
                'distro': 'CentOS',
            }

            output = c.post('/project/1/map', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Project: geany</h1>' in output.data)
            self.assertTrue('<td><label for="distro">Distribution</label></td>'
                            in output.data)

            # This should works just fine
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data['csrf_token'] = csrf_token

            output = c.post('/project/1/map', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="list-group-item list-group-item-default">'
                'Mapping added</li>' in output.data)
            self.assertTrue('<h1>Project: geany</h1>' in output.data)

            # This should fail, the mapping already exists
            data = {
                'package_name': 'geany',
                'distro': 'CentOS',
                'csrf_token': csrf_token,
            }

            output = c.post('/project/1/map', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="list-group-item list-group-item-danger">'
                'Could not edit the mapping of geany on '
                'CentOS, there is already a package geany on CentOS '
                'as part of the project <a href="/project/1/">geany'
                '</a>.</li>' in output.data)
            self.assertTrue('<h1>Project: geany</h1>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'geany')
        self.assertEqual(projects[0].id, 1)
        self.assertEqual(len(projects[0].packages), 1)
        self.assertEqual(projects[0].packages[0].package_name, 'geany')
        self.assertEqual(projects[1].name, 'R2spec')
        self.assertEqual(projects[1].id, 3)
        self.assertEqual(len(projects[1].packages), 0)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)
        self.assertEqual(len(projects[2].packages), 0)
Ejemplo n.º 51
0
    def test_edit_project(self):
        """ Test the edit_project function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/project/1/edit', follow_redirects=True)
        self.assertEqual(output.status_code, 200)
        self.assertTrue('<ul id="flashes" class="list-group">'
                        '<li class="list-group-item list-group-item-warning">'
                        'Login required</li></ul>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'geany')
        self.assertEqual(projects[0].id, 1)
        self.assertEqual(projects[1].name, 'R2spec')
        self.assertEqual(projects[1].id, 3)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'openid_url'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/10/edit', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/edit', follow_redirects=True)
            self.assertEqual(output.status_code, 200)

            self.assertTrue('<h1>Edit project</h1>' in output.data)
            self.assertTrue(
                '<td><label for="regex">Regex</label></td>' in output.data)

            data = {
                'name': 'repo_manager',
                'homepage': 'https://pypi.python.org/pypi/repo_manager',
                'backend': 'PyPI',
            }

            output = c.post('/project/1/edit',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Edit project</h1>' in output.data)
            self.assertTrue(
                '<td><label for="regex">Regex</label></td>' in output.data)

            # This should works just fine
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data['csrf_token'] = csrf_token

            output = c.post('/project/1/edit',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="list-group-item list-group-item-default">'
                'Project edited</li>' in output.data)
            self.assertTrue('<h1>Project: repo_manager</h1>' in output.data)

            # This should fail, the R2spec project already exists
            data = {
                'name': 'R2spec',
                'homepage': 'https://fedorahosted.org/r2spec/',
                'backend': 'folder',
                'csrf_token': csrf_token,
            }

            output = c.post('/project/1/edit',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="list-group-item list-group-item-warning">'
                'Could not edit this project. Is there '
                'already a project with these name and homepage?</li>' in
                output.data)
            self.assertTrue('<h1>Project: repo_manager</h1>' in output.data)

        projects = model.Project.all(self.session)
        self.assertEqual(len(projects), 3)
        self.assertEqual(projects[0].name, 'R2spec')
        self.assertEqual(projects[0].id, 3)
        self.assertEqual(projects[1].name, 'repo_manager')
        self.assertEqual(projects[1].id, 1)
        self.assertEqual(projects[2].name, 'subsurface')
        self.assertEqual(projects[2].id, 2)
Ejemplo n.º 52
0
    def test_map_project(self):
        """ Test the map_project function of Distro. """
        create_distro(self.session)
        create_project(self.session)

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 0)

        # Map `geany` project to CentOS
        anitya.lib.map_project(
            self.session,
            project=project_obj,
            package_name='geany',
            distribution='CentOS',
            user_mail='*****@*****.**',
            old_package_name=None,
        )
        self.session.commit()

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 1)
        self.assertEqual(project_obj.packages[0].package_name, 'geany')
        self.assertEqual(project_obj.packages[0].distro, 'CentOS')

        # Map `geany` project to CentOS, exactly the same way
        anitya.lib.map_project(
            self.session,
            project=project_obj,
            package_name='geany2',
            distribution='CentOS',
            user_mail='*****@*****.**',
            old_package_name=None,
        )
        self.session.commit()

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 2)
        self.assertEqual(project_obj.packages[0].package_name, 'geany')
        self.assertEqual(project_obj.packages[0].distro, 'CentOS')
        self.assertEqual(project_obj.packages[1].package_name, 'geany2')
        self.assertEqual(project_obj.packages[1].distro, 'CentOS')

        # Edit the mapping of the `geany` project to Fedora
        anitya.lib.map_project(
            self.session,
            project=project_obj,
            package_name='geany3',
            distribution='Fedora',
            user_mail='*****@*****.**',
            old_package_name='geany',
            old_distro_name='CentOS',
        )
        self.session.commit()

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 2)
        pkgs = sorted(project_obj.packages, key=lambda x: x.package_name)
        self.assertEqual(pkgs[0].package_name, 'geany2')
        self.assertEqual(pkgs[0].distro, 'CentOS')
        self.assertEqual(pkgs[1].package_name, 'geany3')
        self.assertEqual(pkgs[1].distro, 'Fedora')

        # Edit the mapping of the `geany` project to Fedora
        project_obj = anitya.lib.model.Project.get(self.session, 2)
        self.assertEqual(project_obj.name, 'subsurface')
        self.assertEqual(len(project_obj.packages), 0)

        self.assertRaises(
            anitya.lib.exceptions.AnityaInvalidMappingException,
            anitya.lib.map_project,
            self.session,
            project=project_obj,
            package_name='geany2',
            distribution='CentOS',
            user_mail='*****@*****.**',
        )
Ejemplo n.º 53
0
    def test_delete_project(self):
        """ Test the delete_project function. """
        create_distro(self.session)
        create_project(self.session)

        output = self.app.get('/project/1/delete', follow_redirects=True)
        self.assertEqual(output.status_code, 200)
        self.assertTrue(
            '<li class="errors">Login required</li>' in output.data)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'openid_url'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/100/delete', follow_redirects=True)
            self.assertEqual(output.status_code, 404)

            output = c.get('/project/1/delete', follow_redirects=True)
            self.assertEqual(output.status_code, 401)

        output = c.get('/projects/')
        self.assertEqual(output.status_code, 200)
        self.assertTrue('<h1>Projects monitored</h1>' in output.data)
        self.assertEqual(output.data.count('<a href="/project/1'), 1)
        self.assertEqual(output.data.count('<a href="/project/2'), 1)
        self.assertEqual(output.data.count('<a href="/project/3'), 1)

        with anitya.app.APP.test_client() as c:
            with c.session_transaction() as sess:
                sess['openid'] = 'http://pingou.id.fedoraproject.org/'
                sess['fullname'] = 'Pierre-Yves C.'
                sess['nickname'] = 'pingou'
                sess['email'] = '*****@*****.**'

            output = c.get('/project/1/delete', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Delete project geany?</h1>' in output.data)
            self.assertTrue('<button type="submit" name="confirm" value="Yes"'
                            in output.data)

            data = {
                'confirm': 'Yes',
            }

            output = c.post('/project/1/delete',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Delete project geany?</h1>' in output.data)
            self.assertTrue('<button type="submit" name="confirm" value="Yes"'
                            in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data['csrf_token'] = csrf_token
            del (data['confirm'])

            output = c.post('/project/1/delete',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Project: geany</h1>' in output.data)

            data['confirm'] = True

            output = c.post('/project/1/delete',
                            data=data,
                            follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Projects monitored</h1>' in output.data)
            self.assertTrue(
                '<li class="message">Project geany has been removed</li>' in
                output.data)
            self.assertEqual(output.data.count('<a href="/project/1'), 0)
            self.assertEqual(output.data.count('<a href="/project/2'), 1)
            self.assertEqual(output.data.count('<a href="/project/3'), 1)
Ejemplo n.º 54
0
    def test_map_project(self):
        """ Test the map_project function of Distro. """
        create_distro(self.session)
        create_project(self.session)

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 0)

        # Map `geany` project to CentOS
        anitya.lib.map_project(
            self.session,
            project=project_obj,
            package_name='geany',
            distribution='CentOS',
            user_mail='*****@*****.**',
            old_package_name=None,
        )
        self.session.commit()

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 1)
        self.assertEqual(project_obj.packages[0].package_name, 'geany')
        self.assertEqual(project_obj.packages[0].distro, 'CentOS')

        # Map `geany` project to CentOS, exactly the same way
        anitya.lib.map_project(
            self.session,
            project=project_obj,
            package_name='geany2',
            distribution='CentOS',
            user_mail='*****@*****.**',
            old_package_name=None,
        )
        self.session.commit()

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 2)
        self.assertEqual(project_obj.packages[0].package_name, 'geany')
        self.assertEqual(project_obj.packages[0].distro, 'CentOS')
        self.assertEqual(project_obj.packages[1].package_name, 'geany2')
        self.assertEqual(project_obj.packages[1].distro, 'CentOS')

        # Edit the mapping of the `geany` project to Fedora
        anitya.lib.map_project(
            self.session,
            project=project_obj,
            package_name='geany3',
            distribution='Fedora',
            user_mail='*****@*****.**',
            old_package_name='geany',
            old_distro_name='CentOS',
        )
        self.session.commit()

        project_obj = anitya.lib.model.Project.get(self.session, 1)
        self.assertEqual(project_obj.name, 'geany')
        self.assertEqual(len(project_obj.packages), 2)
        pkgs = sorted(project_obj.packages, key=lambda x: x.package_name)
        self.assertEqual(pkgs[0].package_name, 'geany2')
        self.assertEqual(pkgs[0].distro, 'CentOS')
        self.assertEqual(pkgs[1].package_name, 'geany3')
        self.assertEqual(pkgs[1].distro, 'Fedora')

        # Edit the mapping of the `geany` project to Fedora
        project_obj = anitya.lib.model.Project.get(self.session, 2)
        self.assertEqual(project_obj.name, 'subsurface')
        self.assertEqual(len(project_obj.packages), 0)

        self.assertRaises(
            anitya.lib.exceptions.AnityaException,
            anitya.lib.map_project,
            self.session,
            project=project_obj,
            package_name='geany2',
            distribution='CentOS',
            user_mail='*****@*****.**',
        )
Ejemplo n.º 55
0
    def test_api_get_version(self):
        """ Test the api_get_version function of the API. """
        create_distro(self.session)

        output = self.app.post('/api/version/get')
        self.assertEqual(output.status_code, 400)
        data = _read_json(output)

        exp = {"error": ["No project id specified"], "output": "notok"}
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        data = {'id': 10}
        output = self.app.post('/api/version/get', data=data)
        self.assertEqual(output.status_code, 404)
        data = _read_json(output)

        exp = {"error": "No such project", "output": "notok"}
        self.assertEqual(data, exp)

        # Modify the project so that it fails
        project = model.Project.get(self.session, 1)
        project.version_url = "http://www.geany.org/Down"
        self.session.add(project)
        self.session.commit()

        data = {'id': 1}
        output = self.app.post('/api/version/get', data=data)
        self.assertEqual(output.status_code, 400)
        data = _read_json(output)

        exp = {
            "error": [
                "geany: no upstream version found. "
                "- http://www.geany.org/Down - "
                " " + REGEX % ({
                    'name': 'geany'
                })
            ],
            "output":
            "notok"
        }

        # This test will break for every update of geany, so we need to
        # keep the output easy on hand.
        #print output.data
        self.assertEqual(data, exp)

        # Modify it back:
        project.version_url = "http://www.geany.org/Download/Releases"
        self.session.add(project)
        self.session.commit()

        data = {'id': 1}
        output = self.app.post('/api/version/get', data=data)
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)
        del (data['created_on'])
        del (data['updated_on'])

        exp = {
            "id": 1,
            "backend": "custom",
            "homepage": "http://www.geany.org/",
            "name": "geany",
            "regex": "DEFAULT",
            "version": "1.24.1",
            "version_url": "http://www.geany.org/Download/Releases",
            "versions": ["1.24.1"],
            "packages": [{
                "distro": "Fedora",
                "package_name": "geany"
            }],
        }

        # This test will break for every update of geany, so we need to
        # keep the output easy on hand.
        #print output.data
        self.assertEqual(data, exp)
Ejemplo n.º 56
0
    def test_api_get_version(self):
        """ Test the api_get_version function of the API. """
        create_distro(self.session)

        output = self.app.post('/api/version/get')
        self.assertEqual(output.status_code, 400)
        data = json.loads(output.data)

        exp = {"error": ["No project id specified"], "output": "notok"}
        self.assertEqual(data, exp)

        create_project(self.session)
        create_package(self.session)

        data = {'id': 10}
        output = self.app.post('/api/version/get', data=data)
        self.assertEqual(output.status_code, 404)
        data = json.loads(output.data)

        exp = {"error": "No such project", "output": "notok"}
        self.assertEqual(data, exp)

        # Modify the project so that it fails
        project = model.Project.get(self.session, 1)
        project.version_url = "http://www.geany.org/Down"
        self.session.add(project)
        self.session.commit()

        data = {'id': 1}
        output = self.app.post('/api/version/get', data=data)
        self.assertEqual(output.status_code, 400)
        data = json.loads(output.data)

        exp = {
            "error": [
                "geany: no upstream version found. "
                "- http://www.geany.org/Down - "
                " " + REGEX % ({'name': 'geany'})
            ],
            "output": "notok"
        }

        # This test will break for every update of geany, so we need to
        # keep the output easy on hand.
        #print output.data
        self.assertEqual(data, exp)

        # Modify it back:
        project.version_url = "http://www.geany.org/Download/Releases"
        self.session.add(project)
        self.session.commit()

        data = {'id': 1}
        output = self.app.post('/api/version/get', data=data)
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)
        del(data['created_on'])
        del(data['updated_on'])

        exp = {
            "id": 1,
            "backend": "custom",
            "homepage": "http://www.geany.org/",
            "name": "geany",
            "regex": "DEFAULT",
            "version": "1.24.1",
            "version_url": "http://www.geany.org/Download/Releases",
            "versions": ["1.24.1"],
            "packages": [
                {
                  "distro": "Fedora",
                  "package_name": "geany"
                }
            ],
        }

        # This test will break for every update of geany, so we need to
        # keep the output easy on hand.
        #print output.data
        self.assertEqual(data, exp)