Ejemplo n.º 1
0
    def test_list_packages_items_per_page_with_page(self):
        """Assert retrieving other pages works."""
        project = models.Project(name="requests",
                                 homepage="https://pypi.io/project/requests",
                                 backend="PyPI")
        fedora_package = models.Packages(distro_name="Fedora",
                                         project=project,
                                         package_name="python-requests")
        debian_package = models.Packages(distro_name="Debian",
                                         project=project,
                                         package_name="python-requests")
        Session.add_all([project, fedora_package, debian_package])
        Session.commit()
        output = self.app.get("/api/v2/packages/?items_per_page=1&page=2")
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {
            "page":
            2,
            "items_per_page":
            1,
            "total_items":
            2,
            "items": [{
                "distribution": "Debian",
                "name": "python-requests",
                "project": "requests",
                "ecosystem": "pypi",
            }],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 2
0
    def setUp(self):
        super(DeleteProjectMappingTests, self).setUp()
        self.project = models.Project(
            name='test_project',
            homepage='https://example.com/test_project',
            backend='PyPI',
        )
        self.distro = models.Distro(name='Fedora')
        self.package = models.Packages(
            distro=self.distro.name, project=self.project, package_name='test-project')

        # Add a regular user and an admin user
        session = Session()
        self.user = models.User(email='*****@*****.**', username='******')
        self.admin = models.User(email='*****@*****.**', username='******')

        session.add_all([self.user, self.admin, self.distro, self.project, self.package])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)

        self.client = self.flask_app.test_client()
Ejemplo n.º 3
0
    def setUp(self):
        super(IsAdminTests, self).setUp()

        # Add a regular user and an admin user
        session = Session()
        self.user = models.User(
            email='*****@*****.**',
            username='******',
        )
        user_social_auth = social_models.UserSocialAuth(
            user_id=self.user.id,
            user=self.user
        )

        session.add(self.user)
        session.add(user_social_auth)
        self.admin = models.User(email='*****@*****.**', username='******')
        admin_social_auth = social_models.UserSocialAuth(
            user_id=self.admin.id,
            user=self.admin
        )
        session.add_all([admin_social_auth, self.admin])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)
Ejemplo n.º 4
0
    def setUp(self):
        super(DeleteProjectVersionTests, self).setUp()
        session = Session()

        # Add a project with a version to delete.
        self.project = models.Project(
            name='test_project',
            homepage='https://example.com/test_project',
            backend='PyPI',
        )
        self.project_version = models.ProjectVersion(project=self.project, version='1.0.0')

        # Add a regular user and an admin user
        self.user = models.User(email='*****@*****.**', username='******')
        self.admin = models.User(email='*****@*****.**', username='******')

        session.add_all([self.user, self.admin, self.project, self.project_version])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)

        self.client = self.flask_app.test_client()
Ejemplo n.º 5
0
    def setUp(self):
        super(EditDistroTests, self).setUp()

        # Add a regular user and an admin user
        session = Session()
        self.user = models.User(
            email='*****@*****.**',
            username='******',
        )
        user_social_auth = social_models.UserSocialAuth(
            user_id=self.user.id,
            user=self.user
        )

        session.add(self.user)
        session.add(user_social_auth)
        self.admin = models.User(email='*****@*****.**', username='******')
        admin_social_auth = social_models.UserSocialAuth(
            user_id=self.admin.id,
            user=self.admin
        )

        # Add distributions to edit
        self.fedora = models.Distro(name='Fedora')
        self.centos = models.Distro(name='CentOS')

        session.add_all([admin_social_auth, self.admin, self.fedora, self.centos])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)

        self.client = self.flask_app.test_client()
Ejemplo n.º 6
0
    def setUp(self):
        super(SetFlagStateTests, self).setUp()
        session = Session()

        # Add a regular user and an admin user
        self.user = models.User(email='*****@*****.**', username='******')
        self.admin = models.User(email='*****@*****.**', username='******')

        self.project1 = models.Project(
            name='test_project', homepage='https://example.com/test_project', backend='PyPI')
        self.project2 = models.Project(
            name='project2', homepage='https://example.com/project2', backend='PyPI')
        self.flag1 = models.ProjectFlag(
            reason='I wanted to flag it', user='******', project=self.project1)
        self.flag2 = models.ProjectFlag(
            reason='This project is wrong', user='******', project=self.project2)

        session.add_all(
            [self.user, self.admin, self.project1, self.project2, self.flag1, self.flag2])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)

        self.client = self.flask_app.test_client()
Ejemplo n.º 7
0
    def setUp(self):
        super(BrowseLogsTests, self).setUp()
        session = Session()

        # Add a regular user and an admin user
        self.user = models.User(email='*****@*****.**', username='******')
        self.admin = models.User(email='*****@*****.**', username='******')

        self.user_log = models.Log(
            user='******',
            project='relational_db',
            distro='Fedora',
            description='This is a log',
        )
        self.admin_log = models.Log(
            user='******',
            project='best_project',
            distro='CentOS',
            description='This is also a log',
        )

        session.add_all([self.user, self.admin, self.user_log, self.admin_log])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)

        self.client = self.flask_app.test_client()
Ejemplo n.º 8
0
    def setUp(self):
        super(EditProjectMappingTests, self).setUp()

        # Set up a mapping to edit
        session = Session()
        self.user = models.User(
            email='*****@*****.**',
            username='******',
        )
        user_social_auth = social_models.UserSocialAuth(user_id=self.user.id,
                                                        user=self.user)

        self.session.add(self.user)
        self.session.add(user_social_auth)
        self.distro1 = models.Distro(name='CentOS')
        self.distro2 = models.Distro(name='Fedora')
        self.project = models.Project(
            name='python_project',
            homepage='https://example.com/python_project',
            backend='PyPI',
            ecosystem_name='pypi',
        )
        self.package = models.Packages(package_name='python_project',
                                       distro=self.distro1.name,
                                       project=self.project)
        session.add_all(
            [self.distro1, self.distro2, self.project, self.package])
        session.commit()
        self.client = self.flask_app.test_client()
Ejemplo n.º 9
0
    def test_list_packages_items_per_page_with_page(self):
        """Assert retrieving other pages works."""
        project = models.Project(
            name="requests", homepage="https://pypi.io/project/requests", backend="PyPI"
        )
        fedora_package = models.Packages(
            distro_name="Fedora", project=project, package_name="python-requests"
        )
        debian_package = models.Packages(
            distro_name="Debian", project=project, package_name="python-requests"
        )
        Session.add_all([project, fedora_package, debian_package])
        Session.commit()
        output = self.app.get("/api/v2/packages/?items_per_page=1&page=2")
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {
            "page": 2,
            "items_per_page": 1,
            "total_items": 2,
            "items": [
                {
                    "distribution": "Debian",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                }
            ],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 10
0
    def test_list_projects_with_same_name(self):
        """Assert two projects with the same name are sorted by the ecosystem."""
        self.maxDiff = None
        session = Session()
        project1 = models.Project(
            name="zlib",
            homepage="https://hackage.haskell.org/package/zlib",
            backend="GitHub",
            ecosystem_name="https://hackage.haskell.org/package/zlib",
        )
        project2 = models.Project(
            name="zlib",
            homepage="http://www.zlib.net/",
            backend="custom",
            regex="DEFAULT",
            ecosystem_name="http://www.zlib.net/",
        )
        session.add_all([project1, project2])
        session.commit()

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

        for item in data["items"]:
            del item["created_on"]
            del item["updated_on"]

        exp = {
            "page": 1,
            "items_per_page": 25,
            "total_items": 2,
            "items": [
                {
                    "id": 2,
                    "backend": "custom",
                    "homepage": "http://www.zlib.net/",
                    "name": "zlib",
                    "regex": "DEFAULT",
                    "version": None,
                    "version_url": None,
                    "versions": [],
                    "ecosystem": "http://www.zlib.net/",
                },
                {
                    "id": 1,
                    "backend": "GitHub",
                    "homepage": "https://hackage.haskell.org/package/zlib",
                    "name": "zlib",
                    "regex": None,
                    "version": None,
                    "version_url": None,
                    "versions": [],
                    "ecosystem": "https://hackage.haskell.org/package/zlib",
                },
            ],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 11
0
    def test_list_projects_with_same_name(self):
        """Assert two projects with the same name are sorted by the ecosystem."""
        self.maxDiff = None
        session = Session()
        project1 = models.Project(
            name="zlib",
            homepage="https://hackage.haskell.org/package/zlib",
            backend='GitHub',
            ecosystem_name="https://hackage.haskell.org/package/zlib",
        )
        project2 = models.Project(
            name="zlib",
            homepage="http://www.zlib.net/",
            backend="custom",
            regex="DEFAULT",
            ecosystem_name="http://www.zlib.net/",
        )
        session.add_all([project1, project2])
        session.commit()

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

        for item in data['items']:
            del item['created_on']
            del item['updated_on']

        exp = {
            'page':
            1,
            'items_per_page':
            25,
            'total_items':
            2,
            'items': [{
                "id": 2,
                "backend": "custom",
                "homepage": "http://www.zlib.net/",
                "name": "zlib",
                "regex": "DEFAULT",
                "version": None,
                "version_url": None,
                "versions": [],
                "ecosystem": "http://www.zlib.net/",
            }, {
                "id": 1,
                "backend": "GitHub",
                "homepage": "https://hackage.haskell.org/package/zlib",
                "name": "zlib",
                "regex": None,
                "version": None,
                "version_url": None,
                "versions": [],
                "ecosystem": "https://hackage.haskell.org/package/zlib",
            }]
        }

        self.assertEqual(data, exp)
Ejemplo n.º 12
0
 def setUp(self):
     super(ProjectsResourceGetTests, self).setUp()
     self.app = self.flask_app.test_client()
     session = Session()
     self.user = models.User(email='*****@*****.**', username='******')
     self.api_token = models.ApiToken(user=self.user)
     session.add_all([self.user, self.api_token])
     session.commit()
Ejemplo n.º 13
0
 def setUp(self):
     super(LoadUserFromRequestTests, self).setUp()
     self.app = self.flask_app.test_client()
     session = Session()
     self.user = User(email='*****@*****.**', username='******')
     self.api_token = ApiToken(user=self.user)
     session.add_all([self.user, self.api_token])
     session.commit()
Ejemplo n.º 14
0
    def test_filter_distribution(self):
        """Assert retrieving other pages works."""
        project = models.Project(
            name='requests',
            homepage='https://pypi.io/project/requests',
            backend='PyPI',
        )
        fedora_package = models.Packages(distro_name='Fedora',
                                         project=project,
                                         package_name='python-requests')
        debian_package = models.Packages(distro_name='Debian',
                                         project=project,
                                         package_name='python-requests')
        Session.add_all([project, fedora_package, debian_package])
        Session.commit()
        fedora = self.app.get('/api/v2/packages/?distribution=Fedora')
        debian = self.app.get('/api/v2/packages/?distribution=Debian')
        self.assertEqual(fedora.status_code, 200)
        self.assertEqual(debian.status_code, 200)
        fedora_data = _read_json(fedora)
        debian_data = _read_json(debian)

        fedora_exp = {
            'page':
            1,
            'items_per_page':
            25,
            'total_items':
            1,
            'items': [
                {
                    "distribution": "Fedora",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi"
                },
            ]
        }
        debian_exp = {
            'page':
            1,
            'items_per_page':
            25,
            'total_items':
            1,
            'items': [
                {
                    "distribution": "Debian",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi"
                },
            ]
        }

        self.assertEqual(fedora_data, fedora_exp)
        self.assertEqual(debian_data, debian_exp)
Ejemplo n.º 15
0
    def test_packages(self):
        """Assert packages are returned when they exist."""
        project = models.Project(
            name='requests',
            homepage='https://pypi.io/project/requests',
            backend='PyPI',
        )
        fedora_package = models.Packages(distro_name='Fedora',
                                         project=project,
                                         package_name='python-requests')
        debian_package = models.Packages(distro_name='Debian',
                                         project=project,
                                         package_name='python-requests')
        jcline_package = models.Packages(distro_name='jcline linux',
                                         project=project,
                                         package_name='requests')
        Session.add_all(
            [project, fedora_package, debian_package, jcline_package])
        Session.commit()

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

        exp = {
            'page':
            1,
            'items_per_page':
            25,
            'total_items':
            3,
            'items': [
                {
                    "distribution": "Fedora",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi"
                },
                {
                    "distribution": "Debian",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi"
                },
                {
                    "distribution": "jcline linux",
                    "name": "requests",
                    "project": "requests",
                    "ecosystem": "pypi"
                },
            ]
        }

        self.assertEqual(data, exp)
Ejemplo n.º 16
0
 def setUp(self):
     super(PackagesResourceGetTests, self).setUp()
     self.app = self.flask_app.test_client()
     session = Session()
     self.user = models.User(email='*****@*****.**', username='******')
     self.api_token = models.ApiToken(user=self.user)
     fedora = models.Distro('Fedora')
     debian = models.Distro('Debian')
     jcline_linux = models.Distro('jcline linux')
     session.add_all(
         [self.user, self.api_token, fedora, debian, jcline_linux])
     session.commit()
Ejemplo n.º 17
0
    def test_packages(self):
        """Assert packages are returned when they exist."""
        project = models.Project(name="requests",
                                 homepage="https://pypi.io/project/requests",
                                 backend="PyPI")
        fedora_package = models.Packages(distro_name="Fedora",
                                         project=project,
                                         package_name="python-requests")
        debian_package = models.Packages(distro_name="Debian",
                                         project=project,
                                         package_name="python-requests")
        jcline_package = models.Packages(distro_name="jcline linux",
                                         project=project,
                                         package_name="requests")
        Session.add_all(
            [project, fedora_package, debian_package, jcline_package])
        Session.commit()

        output = self.app.get("/api/v2/packages/")
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {
            "page":
            1,
            "items_per_page":
            25,
            "total_items":
            3,
            "items": [
                {
                    "distribution": "Fedora",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                },
                {
                    "distribution": "Debian",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                },
                {
                    "distribution": "jcline linux",
                    "name": "requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                },
            ],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 18
0
    def test_filter_distribution(self):
        """Assert retrieving other pages works."""
        project = models.Project(name="requests",
                                 homepage="https://pypi.io/project/requests",
                                 backend="PyPI")
        fedora_package = models.Packages(distro_name="Fedora",
                                         project=project,
                                         package_name="python-requests")
        debian_package = models.Packages(distro_name="Debian",
                                         project=project,
                                         package_name="python-requests")
        Session.add_all([project, fedora_package, debian_package])
        Session.commit()
        fedora = self.app.get("/api/v2/packages/?distribution=Fedora")
        debian = self.app.get("/api/v2/packages/?distribution=Debian")
        self.assertEqual(fedora.status_code, 200)
        self.assertEqual(debian.status_code, 200)
        fedora_data = _read_json(fedora)
        debian_data = _read_json(debian)

        fedora_exp = {
            "page":
            1,
            "items_per_page":
            25,
            "total_items":
            1,
            "items": [{
                "distribution": "Fedora",
                "name": "python-requests",
                "project": "requests",
                "ecosystem": "pypi",
            }],
        }
        debian_exp = {
            "page":
            1,
            "items_per_page":
            25,
            "total_items":
            1,
            "items": [{
                "distribution": "Debian",
                "name": "python-requests",
                "project": "requests",
                "ecosystem": "pypi",
            }],
        }

        self.assertEqual(fedora_data, fedora_exp)
        self.assertEqual(debian_data, debian_exp)
Ejemplo n.º 19
0
    def setUp(self):
        super(IsAdminTests, self).setUp()

        # Add a regular user and an admin user
        session = Session()
        self.user = models.User(email='*****@*****.**', username='******')
        self.admin = models.User(email='*****@*****.**', username='******')
        session.add_all([self.user, self.admin])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)
Ejemplo n.º 20
0
    def test_filter_distribution(self):
        """Assert retrieving other pages works."""
        project = models.Project(
            name="requests", homepage="https://pypi.io/project/requests", backend="PyPI"
        )
        fedora_package = models.Packages(
            distro_name="Fedora", project=project, package_name="python-requests"
        )
        debian_package = models.Packages(
            distro_name="Debian", project=project, package_name="python-requests"
        )
        Session.add_all([project, fedora_package, debian_package])
        Session.commit()
        fedora = self.app.get("/api/v2/packages/?distribution=Fedora")
        debian = self.app.get("/api/v2/packages/?distribution=Debian")
        self.assertEqual(fedora.status_code, 200)
        self.assertEqual(debian.status_code, 200)
        fedora_data = _read_json(fedora)
        debian_data = _read_json(debian)

        fedora_exp = {
            "page": 1,
            "items_per_page": 25,
            "total_items": 1,
            "items": [
                {
                    "distribution": "Fedora",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                }
            ],
        }
        debian_exp = {
            "page": 1,
            "items_per_page": 25,
            "total_items": 1,
            "items": [
                {
                    "distribution": "Debian",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                }
            ],
        }

        self.assertEqual(fedora_data, fedora_exp)
        self.assertEqual(debian_data, debian_exp)
Ejemplo n.º 21
0
    def test_packages(self):
        """Assert packages are returned when they exist."""
        project = models.Project(
            name="requests", homepage="https://pypi.io/project/requests", backend="PyPI"
        )
        fedora_package = models.Packages(
            distro_name="Fedora", project=project, package_name="python-requests"
        )
        debian_package = models.Packages(
            distro_name="Debian", project=project, package_name="python-requests"
        )
        jcline_package = models.Packages(
            distro_name="jcline linux", project=project, package_name="requests"
        )
        Session.add_all([project, fedora_package, debian_package, jcline_package])
        Session.commit()

        output = self.app.get("/api/v2/packages/")
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {
            "page": 1,
            "items_per_page": 25,
            "total_items": 3,
            "items": [
                {
                    "distribution": "Fedora",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                },
                {
                    "distribution": "Debian",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                },
                {
                    "distribution": "jcline linux",
                    "name": "requests",
                    "project": "requests",
                    "ecosystem": "pypi",
                },
            ],
        }

        self.assertEqual(data, exp)
Ejemplo n.º 22
0
    def setUp(self):
        super(PackagesResourcePostTests, self).setUp()
        self.app = self.flask_app.test_client()
        session = Session()
        self.user = models.User(email='*****@*****.**', username='******')
        self.api_token = models.ApiToken(user=self.user)
        self.project = models.Project(
            name='requests',
            homepage='https://pypi.io/project/requests',
            backend='PyPI',
        )
        self.fedora = models.Distro('Fedora')
        session.add_all([self.user, self.api_token, self.project, self.fedora])
        session.commit()

        self.auth = {'Authorization': 'Token ' + self.api_token.token}
Ejemplo n.º 23
0
    def setUp(self):
        super(PackagesResourceGetTests, self).setUp()
        self.app = self.flask_app.test_client()
        session = Session()
        self.user = models.User(email="*****@*****.**", username="******")
        user_social_auth = social_models.UserSocialAuth(
            user_id=self.user.id, user=self.user
        )

        session.add(self.user)
        session.add(user_social_auth)
        self.api_token = models.ApiToken(user=self.user)
        fedora = models.Distro("Fedora")
        debian = models.Distro("Debian")
        jcline_linux = models.Distro("jcline linux")
        session.add_all([self.api_token, fedora, debian, jcline_linux])
        session.commit()
Ejemplo n.º 24
0
    def setUp(self):
        super(PackagesResourceGetTests, self).setUp()
        self.app = self.flask_app.test_client()
        session = Session()
        self.user = models.User(email="*****@*****.**",
                                username="******")
        user_social_auth = social_models.UserSocialAuth(user_id=self.user.id,
                                                        user=self.user)

        session.add(self.user)
        session.add(user_social_auth)
        self.api_token = models.ApiToken(user=self.user)
        fedora = models.Distro("Fedora")
        debian = models.Distro("Debian")
        jcline_linux = models.Distro("jcline linux")
        session.add_all([self.api_token, fedora, debian, jcline_linux])
        session.commit()
Ejemplo n.º 25
0
    def setUp(self):
        super(PackagesResourcePostTests, self).setUp()
        self.app = self.flask_app.test_client()
        session = Session()
        self.user = models.User(email="*****@*****.**", username="******")
        user_social_auth = social_models.UserSocialAuth(
            user_id=self.user.id, user=self.user
        )

        session.add(self.user)
        session.add(user_social_auth)
        self.api_token = models.ApiToken(user=self.user)
        self.project = models.Project(
            name="requests", homepage="https://pypi.io/project/requests", backend="PyPI"
        )
        self.fedora = models.Distro("Fedora")
        session.add_all([self.api_token, self.project, self.fedora])
        session.commit()

        self.auth = {"Authorization": "Token " + self.api_token.token}
Ejemplo n.º 26
0
    def setUp(self):
        super(PackagesResourcePostTests, self).setUp()
        self.app = self.flask_app.test_client()
        session = Session()
        self.user = models.User(email="*****@*****.**",
                                username="******")
        user_social_auth = social_models.UserSocialAuth(user_id=self.user.id,
                                                        user=self.user)

        session.add(self.user)
        session.add(user_social_auth)
        self.api_token = models.ApiToken(user=self.user)
        self.project = models.Project(
            name="requests",
            homepage="https://pypi.io/project/requests",
            backend="PyPI")
        self.fedora = models.Distro("Fedora")
        session.add_all([self.api_token, self.project, self.fedora])
        session.commit()

        self.auth = {"Authorization": "Token " + self.api_token.token}
Ejemplo n.º 27
0
    def setUp(self):
        super(DeleteDistroTests, self).setUp()

        # Add a regular user and an admin user
        session = Session()
        self.user = models.User(email='*****@*****.**', username='******')
        self.admin = models.User(email='*****@*****.**', username='******')

        # Add distributions to delete
        self.fedora = models.Distro(name='Fedora')
        self.centos = models.Distro(name='CentOS')

        session.add_all([self.user, self.admin, self.fedora, self.centos])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)

        self.client = self.flask_app.test_client()
Ejemplo n.º 28
0
    def test_clashing_package_name(self):
        """Assert two projects can't map to the same package name in a distro."""
        # Set up a package to clash with.
        session = Session()
        best_project = models.Project(
            name='best_project',
            homepage='https://example.com/best_project',
            backend='PyPI',
            ecosystem_name='pypi',
        )
        best_package = models.Packages(package_name='best_project',
                                       distro=self.distro1.name,
                                       project=best_project)
        session.add_all([best_project, best_package])
        session.commit()

        with login_user(self.flask_app, self.user):
            pre_edit_output = self.client.get('/project/1/map/1')
            csrf_token = pre_edit_output.data.split(
                b'name="csrf_token" type="hidden" value="')[1].split(b'">')[0]
            data = {
                'package_name': self.project.name,
                'distro': self.distro1.name,
                'csrf_token': csrf_token,
            }
            output = self.client.post('/project/1/map/1',
                                      data=data,
                                      follow_redirects=True)

            self.assertEqual(output.status_code, 200)
            self.assertEqual(2, models.Packages.query.count())
            self.assertEqual(
                1,
                models.Packages.query.filter_by(
                    package_name='best_project').count())
            self.assertEqual(
                1,
                models.Packages.query.filter_by(
                    package_name='python_project').count())
            self.assertTrue(b'Could not edit the mapping' in output.data)
Ejemplo n.º 29
0
    def test_list_packages_items_per_page_with_page(self):
        """Assert retrieving other pages works."""
        project = models.Project(
            name='requests',
            homepage='https://pypi.io/project/requests',
            backend='PyPI',
        )
        fedora_package = models.Packages(distro_name='Fedora',
                                         project=project,
                                         package_name='python-requests')
        debian_package = models.Packages(distro_name='Debian',
                                         project=project,
                                         package_name='python-requests')
        Session.add_all([project, fedora_package, debian_package])
        Session.commit()
        output = self.app.get('/api/v2/packages/?items_per_page=1&page=2')
        self.assertEqual(output.status_code, 200)
        data = _read_json(output)

        exp = {
            'page':
            2,
            'items_per_page':
            1,
            'total_items':
            2,
            'items': [
                {
                    "distribution": "Debian",
                    "name": "python-requests",
                    "project": "requests",
                    "ecosystem": "pypi"
                },
            ]
        }

        self.assertEqual(data, exp)
Ejemplo n.º 30
0
    def setUp(self):
        super(DeleteProjectTests, self).setUp()
        self.project = models.Project(
            name='test_project',
            homepage='https://example.com/test_project',
            backend='PyPI',
        )

        # Add a regular user and an admin user
        session = Session()
        self.user = models.User(
            email='*****@*****.**',
            username='******',
        )
        user_social_auth = social_models.UserSocialAuth(
            user_id=self.user.id,
            user=self.user
        )

        session.add(self.user)
        session.add(user_social_auth)
        self.admin = models.User(email='*****@*****.**', username='******')
        admin_social_auth = social_models.UserSocialAuth(
            user_id=self.admin.id,
            user=self.admin
        )

        session.add_all([admin_social_auth, self.admin, self.project])
        session.commit()

        mock_config = mock.patch.dict(
            models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]})
        mock_config.start()
        self.addCleanup(mock_config.stop)

        self.client = self.flask_app.test_client()