Exemplo n.º 1
0
    def test_view_creates_guid(self, mock_from_addon, mock_wrapped_key):

        mock_from_addon.return_value = create_mock_wrapper()
        mock_wrapped_key.return_value = create_mock_key()

        guid_count = S3GuidFile.find().count()

        # View file for the first time
        url = self.project.url + 's3/test.py'
        res = self.app.get(url, auth=self.user.auth).maybe_follow(auth=self.user.auth)

        guids = S3GuidFile.find()

        # GUID count has been incremented by one
        assert_equal(
            guids.count(),
            guid_count + 1
        )

        # Client has been redirected to GUID
        assert_equal(
            res.request.path.strip('/'),
            guids[guids.count() - 1]._id
        )

        # View file for the second time
        self.app.get(url, auth=self.user.auth).follow(auth=self.user.auth)

        # GUID count has not been incremented
        assert_equal(
            S3GuidFile.find().count(),
            guid_count + 1
        )
Exemplo n.º 2
0
    def test_view_creates_guid(self, mock_from_addon, mock_wrapped_key):

        mock_from_addon.return_value = create_mock_wrapper()
        mock_wrapped_key.return_value = create_mock_key()

        guid_count = S3GuidFile.find().count()

        # View file for the first time
        url = self.project.url + 's3/test.py'
        res = self.app.get(
            url, auth=self.user.auth).maybe_follow(auth=self.user.auth)

        guids = S3GuidFile.find()

        # GUID count has been incremented by one
        assert_equal(guids.count(), guid_count + 1)

        # Client has been redirected to GUID
        assert_equal(res.request.path.strip('/'), guids[guids.count() - 1]._id)

        # View file for the second time
        self.app.get(url, auth=self.user.auth).follow(auth=self.user.auth)

        # GUID count has not been incremented
        assert_equal(S3GuidFile.find().count(), guid_count + 1)
Exemplo n.º 3
0
 def test_view_file(self, mock_from_addon, mock_wrapped_key):
     mock_from_addon.return_value = create_mock_wrapper()
     mock_wrapped_key.return_value = create_mock_key()
     url = '/project/{0}/s3/view/pizza.png/'.format(self.project._id)
     res = self.app.get(
         url,
         auth=self.user.auth,
     ).maybe_follow(auth=self.user.auth, )
     assert_equal(res.status_code, 200)
     assert_in('Delete <i class="icon-trash"></i>', res)
Exemplo n.º 4
0
 def test_view_file(self, mock_from_addon, mock_wrapped_key):
     mock_from_addon.return_value = create_mock_wrapper()
     mock_wrapped_key.return_value = create_mock_key()
     url = '/project/{0}/s3/view/pizza.png/'.format(self.project._id)
     res = self.app.get(
         url,
         auth=self.user.auth,
     ).maybe_follow(
         auth=self.user.auth,
     )
     assert_equal(res.status_code, 200)
     assert_in('Delete <i class="icon-trash"></i>', res)
Exemplo n.º 5
0
 def test_view_file_non_contributor(self, mock_from_addon,
                                    mock_wrapped_key):
     mock_from_addon.return_value = create_mock_wrapper()
     mock_wrapped_key.return_value = create_mock_key()
     self.project.is_public = True
     self.project.save()
     user2 = AuthUserFactory()
     url = '/project/{0}/s3/view/pizza.png/'.format(self.project._id)
     res = self.app.get(
         url,
         auth=user2.auth,
     ).maybe_follow(auth=user2.auth, )
     assert_equal(res.status_code, 200)
     assert_not_in('Delete <i class="icon-trash"></i>', res)
Exemplo n.º 6
0
    def test_s3_set_bucket_registered(self, mock_from_addon):

        mock_from_addon.return_value = create_mock_wrapper()

        registration = self.project.register_node(
            None, self.consolidated_auth, '', ''
        )

        url = registration.api_url + 's3/settings/'
        res = self.app.post_json(
            url, {'s3_bucket': 'hammertofall'}, auth=self.user.auth,
            expect_errors=True,
        )

        assert_equal(res.status_code, http.BAD_REQUEST)
Exemplo n.º 7
0
 def test_view_file_non_contributor(self, mock_from_addon, mock_wrapped_key):
     mock_from_addon.return_value = create_mock_wrapper()
     mock_wrapped_key.return_value = create_mock_key()
     self.project.is_public = True
     self.project.save()
     user2 = AuthUserFactory()
     url = '/project/{0}/s3/view/pizza.png/'.format(self.project._id)
     res = self.app.get(
         url,
         auth=user2.auth,
     ).maybe_follow(
         auth=user2.auth,
     )
     assert_equal(res.status_code, 200)
     assert_not_in('Delete <i class="icon-trash"></i>', res)
Exemplo n.º 8
0
    def test_s3_set_bucket_registered(self, mock_from_addon):

        mock_from_addon.return_value = create_mock_wrapper()

        registration = self.project.register_node(
            None, self.consolidated_auth, '', ''
        )

        url = registration.api_url + 's3/settings/'
        res = self.app.post_json(
            url, {'s3_bucket': 'hammertofall'}, auth=self.user.auth,
            expect_errors=True,
        )

        assert_equal(res.status_code, http.BAD_REQUEST)