Beispiel #1
0
 def test_upload_bad_action(self):
     """ Upload endpoint only respects 'file_upload' action """
     self.params = {
         ':action': 'blah',
     }
     name, version, content = 'foo', 'bar', 'baz'
     with self.assertRaises(HTTPBadRequest):
         upload(self.request, name, version, content)
Beispiel #2
0
 def test_upload_bad_action(self):
     """ Upload endpoint only respects 'file_upload' action """
     self.params = {
         ':action': 'blah',
     }
     name, version, content = 'foo', 'bar', 'baz'
     with self.assertRaises(HTTPBadRequest):
         upload(self.request, name, version, content)
Beispiel #3
0
    def test_search(self):
        """ Pip search executes successfully """
        self.params = {":action": "file_upload"}
        name1, version1, content1 = "foo", "1.1", MagicMock()
        content1.filename = "bar-1.2.tar.gz"
        name2, version2, content2 = "bar", "1.0", MagicMock()
        content2.filename = "bar-1.2.tar.gz"
        upload(self.request, content1, name1, version1)
        upload(self.request, content2, name2, version2)

        criteria = {"name": ["foo"], "summary": ["foo"]}
        response = search(self.request, criteria, "or")
        expected = [{"name": "foo", "version": "1.1", "summary": ""}]
        self.assertListEqual(response, expected)
Beispiel #4
0
    def test_search(self):
        """Pip search executes successfully"""
        self.params = {":action": "file_upload"}
        name1, version1, content1 = "foo", "1.1", FileUpload("testfile", b"test1234")
        content1.filename = "bar-1.2.tar.gz"
        name2, version2, content2 = "bar", "1.0", FileUpload("testfile", b"test1234")
        content2.filename = "bar-1.2.tar.gz"
        upload(self.request, content1, name1, version1)
        upload(self.request, content2, name2, version2)

        criteria = {"name": ["foo"], "summary": ["foo"]}
        response = search(self.request, criteria, "or")
        expected = [{"name": "foo", "version": "1.1", "summary": ""}]
        self.assertListEqual(response, expected)
Beispiel #5
0
    def test_upload(self):
        """Upload endpoint returns the result of api call"""
        self.params = {":action": "file_upload"}
        name, version, content = "foo", "bar", FileUpload("testfile", b"test1234")
        content.filename = "foo-1.2.tar.gz"
        pkg = upload(self.request, content, name, version)

        self.assertEqual(pkg, self.request.db.packages[content.filename])
Beispiel #6
0
 def test_upload_duplicate(self):
     """ Uploading a duplicate package returns 409 """
     self.params = {":action": "file_upload"}
     name, version, content = "foo", "1.2", MagicMock()
     content.filename = "foo-1.2.tar.gz"
     self.db.upload(content.filename, content, name)
     response = upload(self.request, content, name, version)
     self.assertEqual(response.status_code, 409)
Beispiel #7
0
 def test_upload_no_write_permission(self):
     """ Upload without write permission returns 403 """
     self.params = {":action": "file_upload"}
     name, version, content = "foo", "bar", MagicMock()
     content.filename = "foo-1.2.tar.gz"
     self.request.access.has_permission.return_value = False
     response = upload(self.request, content, name, version)
     self.assertEqual(response, self.request.forbid())
Beispiel #8
0
 def test_upload_no_write_permission(self):
     """Upload without write permission returns 403"""
     self.params = {":action": "file_upload"}
     name, version, content = "foo", "bar", FileUpload("testfile", b"test1234")
     content.filename = "foo-1.2.tar.gz"
     self.request.access.has_permission.return_value = False
     response = upload(self.request, content, name, version)
     self.assertEqual(response, self.request.forbid())
Beispiel #9
0
    def test_upload(self):
        """ Upload endpoint returns the result of api call """
        self.params = {":action": "file_upload"}
        name, version, content = "foo", "bar", MagicMock()
        content.filename = "foo-1.2.tar.gz"
        pkg = upload(self.request, content, name, version)

        self.assertEqual(pkg, self.request.db.packages[content.filename])
Beispiel #10
0
 def test_upload_duplicate(self):
     """Uploading a duplicate package returns 409"""
     self.params = {":action": "file_upload"}
     name, version, content = "foo", "1.2", FileUpload("testfile", b"test1234")
     content.filename = "foo-1.2.tar.gz"
     self.db.upload(content.filename, content.file, name)
     response = upload(self.request, content, name, version)
     self.assertEqual(response.status_code, 409)
Beispiel #11
0
 def test_upload_bad_action(self):
     """ Upload endpoint only respects 'file_upload' action """
     self.params = {
         ':action': 'blah',
     }
     name, version, content = 'foo', 'bar', 'baz'
     response = upload(self.request, name, version, content)
     self.assertEqual(response.status_code, 400)
Beispiel #12
0
 def test_upload_bad_action(self):
     """ Upload endpoint only respects 'file_upload' action """
     self.params = {
         ':action': 'blah',
     }
     name, version, content = 'foo', 'bar', 'baz'
     response = upload(self.request, content, name, version)
     self.assertEqual(response.status_code, 400)
Beispiel #13
0
    def test_upload(self):
        """ Upload endpoint returns the result of api call """
        self.params = {
            ':action': 'file_upload',
        }
        name, version, content = 'foo', 'bar', MagicMock()
        pkg = upload(self.request, name, version, content)

        self.assertEquals(pkg, self.request.db.packages[name][version])
Beispiel #14
0
    def test_upload(self):
        """ Upload endpoint returns the result of api call """
        self.params = {
            ':action': 'file_upload',
        }
        name, version, content = 'foo', 'bar', MagicMock()
        pkg = upload(self.request, name, version, content)

        self.assertEquals(pkg, self.request.db.packages[name][version])
Beispiel #15
0
 def test_upload_duplicate(self):
     """ Uploading a duplicate package returns 400 """
     self.params = {
         ':action': 'file_upload',
     }
     name, version, content = 'foo', '1.2', MagicMock()
     content.filename = 'foo-1.2.tar.gz'
     self.db.upload(content.filename, content, name)
     response = upload(self.request, name, version, content)
     self.assertEqual(response.status_code, 400)
Beispiel #16
0
 def test_upload_no_write_permission(self):
     """ Upload without write permission returns 403 """
     self.params = {
         ':action': 'file_upload',
     }
     name, version, content = 'foo', 'bar', MagicMock()
     content.filename = 'foo-1.2.tar.gz'
     self.request.access.has_permission.return_value = False
     response = upload(self.request, name, version, content)
     self.assertEqual(response, self.request.forbid())
Beispiel #17
0
 def test_upload_duplicate(self):
     """ Uploading a duplicate package returns 409 """
     self.params = {
         ':action': 'file_upload',
     }
     name, version, content = 'foo', '1.2', MagicMock()
     content.filename = 'foo-1.2.tar.gz'
     self.db.upload(content.filename, content, name)
     response = upload(self.request, content, name, version)
     self.assertEqual(response.status_code, 409)
Beispiel #18
0
 def test_upload_no_write_permission(self):
     """ Upload without write permission returns 403 """
     self.params = {
         ':action': 'file_upload',
     }
     name, version, content = 'foo', 'bar', MagicMock()
     content.filename = 'foo-1.2.tar.gz'
     self.request.access.has_permission.return_value = False
     response = upload(self.request, content, name, version)
     self.assertEqual(response, self.request.forbid())
Beispiel #19
0
    def test_search(self):
        """ Pip search executes successfully """
        self.params = {
            ':action': 'file_upload',
        }
        name1, version1, content1 = 'foo', '1.1', MagicMock()
        content1.filename = 'bar-1.2.tar.gz'
        name2, version2, content2 = 'bar', '1.0', MagicMock()
        content2.filename = 'bar-1.2.tar.gz'
        upload(self.request, content1, name1, version1)
        upload(self.request, content2, name2, version2)

        criteria = {'name': ['foo'], 'summary': ['foo']}
        response = search(self.request, criteria, 'or')
        expected = [{
            'name': 'foo',
            'version': '1.1',
            'summary': '',
        }]
        self.assertListEqual(response, expected)
Beispiel #20
0
 def test_search_permission_filter(self):
     """Pip search only gets results that user has read perms for"""
     self.params = {":action": "file_upload"}
     name1, version1, content1 = "pkg1", "1.1", FileUpload("testfile", b"test1234")
     content1.filename = "pkg1-1.1.tar.gz"
     name2, version2, content2 = "pkg2", "1.0", FileUpload("testfile", b"test1234")
     content2.filename = "pkg2-1.0.tar.gz"
     name3, version3, content3 = "other", "1.0", FileUpload("testfile", b"test1234")
     content3.filename = "other-1.0.tar.gz"
     upload(self.request, content1, name1, version1)
     upload(self.request, content2, name2, version2)
     upload(self.request, content3, name3, version3)
     self.request.access.has_permission.side_effect = lambda x, _: x == "pkg1"
     criteria = {"name": ["pkg"]}
     response = search(self.request, criteria, "and")
     self.assertItemsEqual(
         response, [{"name": "pkg1", "version": "1.1", "summary": ""}]
     )
Beispiel #21
0
 def test_search_permission_filter(self):
     """ Pip search only gets results that user has read perms for """
     self.params = {":action": "file_upload"}
     name1, version1, content1 = "pkg1", "1.1", MagicMock()
     content1.filename = "pkg1-1.1.tar.gz"
     name2, version2, content2 = "pkg2", "1.0", MagicMock()
     content2.filename = "pkg2-1.0.tar.gz"
     name3, version3, content3 = "other", "1.0", MagicMock()
     content3.filename = "other-1.0.tar.gz"
     upload(self.request, content1, name1, version1)
     upload(self.request, content2, name2, version2)
     upload(self.request, content3, name3, version3)
     self.request.access.has_permission.side_effect = lambda x, _: x == "pkg1"
     criteria = {"name": ["pkg"]}
     response = search(self.request, criteria, "and")
     self.assertItemsEqual(
         response, [{"name": "pkg1", "version": "1.1", "summary": ""}]
     )
Beispiel #22
0
 def test_search_permission_filter(self):
     """ Pip search only gets results that user has read perms for """
     self.params = {
         ':action': 'file_upload',
     }
     name1, version1, content1 = 'pkg1', '1.1', MagicMock()
     content1.filename = 'pkg1-1.1.tar.gz'
     name2, version2, content2 = 'pkg2', '1.0', MagicMock()
     content2.filename = 'pkg2-1.0.tar.gz'
     name3, version3, content3 = 'other', '1.0', MagicMock()
     content3.filename = 'other-1.0.tar.gz'
     upload(self.request, content1, name1, version1)
     upload(self.request, content2, name2, version2)
     upload(self.request, content3, name3, version3)
     self.request.access.has_permission.side_effect = lambda x, _: x == 'pkg1'
     criteria = {
         'name': ['pkg'],
     }
     response = search(self.request, criteria, 'and')
     self.assertItemsEqual(response, [{
         'name': 'pkg1',
         'version': '1.1',
         'summary': '',
     }])
Beispiel #23
0
 def test_upload_bad_action(self):
     """ Upload endpoint only respects 'file_upload' action """
     self.params = {":action": "blah"}
     name, version, content = "foo", "bar", "baz"
     response = upload(self.request, content, name, version)
     self.assertEqual(response.status_code, 400)
Beispiel #24
0
 def test_upload_bad_action(self):
     """Upload endpoint only respects 'file_upload' action"""
     self.params = {":action": "blah"}
     name, version, content = "foo", "bar", "baz"
     response = upload(self.request, content, name, version)
     self.assertEqual(response.status_code, 400)