|
Pierre-Yves Chibon |
ded1fa |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
"""
|
|
Pierre-Yves Chibon |
ded1fa |
(c) 2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
Authors:
|
|
Pierre-Yves Chibon |
ded1fa |
Clement Verna <cverna@tutanota.com></cverna@tutanota.com>
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
"""
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
import unittest
|
|
Pierre-Yves Chibon |
ded1fa |
import sys
|
|
Pierre-Yves Chibon |
ded1fa |
import os
|
|
Pierre-Yves Chibon |
ded1fa |
import time
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
import mock
|
|
Pierre-Yves Chibon |
ded1fa |
import pygit2
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
73d120 |
sys.path.insert(
|
|
Pierre-Yves Chibon |
73d120 |
0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
import pagure.lib.git
|
|
Pierre-Yves Chibon |
ded1fa |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
ded1fa |
import tests
|
|
Pierre-Yves Chibon |
ded1fa |
from tests.test_pagure_lib_git_get_tags_objects import add_repo_tag
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
class PagureFlaskUiArchivesTest(tests.Modeltests):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Tests checking the archiving mechanism. """
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def setUp(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
ded1fa |
super(PagureFlaskUiArchivesTest, self).setUp()
|
|
Pierre-Yves Chibon |
ded1fa |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query._get_project(self.session, "test")
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
# test has both commits and tags
|
|
Pierre-Yves Chibon |
73d120 |
repopath = os.path.join(self.path, "repos", "test.git")
|
|
Pierre-Yves Chibon |
ded1fa |
tests.add_readme_git_repo(repopath)
|
|
Pierre-Yves Chibon |
ded1fa |
repo = pygit2.Repository(repopath)
|
|
Pierre-Yves Chibon |
73d120 |
add_repo_tag(self.path, repo, ["v1.0", "v1.1"], "test.git")
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
# test2 has only commits
|
|
Pierre-Yves Chibon |
73d120 |
tests.add_readme_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test2.git")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
# somenamespace/test3 has neither commits nor tags
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
# Create the archive folder:
|
|
Pierre-Yves Chibon |
73d120 |
self.archive_path = os.path.join(self.path, "archives")
|
|
Pierre-Yves Chibon |
ded1fa |
os.mkdir(self.archive_path)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_no_conf(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive when pagure isn't configured. """
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/somenamespace/test3/archive/tag1/test3-tag1.zip",
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertIn(
|
|
Pierre-Yves Chibon |
ded1fa |
"This pagure instance isn't configured to support "
|
|
Pierre-Yves Chibon |
73d120 |
"this feature",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(os.listdir(self.archive_path), [])
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_invalid_conf(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive when pagure is wrongly configured. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "invalid")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/somenamespace/test3/archive/tag1/test3-tag1.zip",
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 500)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertIn(
|
|
Pierre-Yves Chibon |
ded1fa |
"Incorrect configuration, please contact your admin",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(os.listdir(self.archive_path), [])
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_invalid_format(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive when the format provided is invalid. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/somenamespace/test3/archive/tag1/test3-tag1.unzip",
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(os.listdir(self.archive_path), [])
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_no_commit(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive of an empty project. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/somenamespace/test3/archive/tag1/test3-tag1.zip",
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Invalid commit provided ", output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(os.listdir(self.archive_path), [])
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_no_tag(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive of a non-empty project but without
|
|
Pierre-Yves Chibon |
ded1fa |
tags. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test2/archive/tag1/test2-tag1.zip", follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Invalid commit provided ", output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(os.listdir(self.archive_path), [])
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_no_tag(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive of an empty project. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test2/archive/tag1/test2-tag1.zip", follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Invalid commit provided ", output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(os.listdir(self.archive_path), [])
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_w_tag_zip(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive from a tag. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/archive/v1.0/test-v1.0.zip", follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(os.listdir(self.archive_path), ["test"])
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test")), ["tags"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test", "tags")),
|
|
Pierre-Yves Chibon |
73d120 |
["v1.0"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
len(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.archive_path, "test", "tags", "v1.0")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
),
|
|
Pierre-Yves Chibon |
73d120 |
1,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
files = os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.archive_path, "test", "tags", "v1.0")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.archive_path, "test", "tags", "v1.0", files[0]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
),
|
|
Pierre-Yves Chibon |
73d120 |
["test-v1.0.zip"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_w_tag_tar(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive from a tag. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/archive/v1.0/test-v1.0.tar", follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(os.listdir(self.archive_path), ["test"])
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test")), ["tags"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test", "tags")),
|
|
Pierre-Yves Chibon |
73d120 |
["v1.0"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
len(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.archive_path, "test", "tags", "v1.0")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
),
|
|
Pierre-Yves Chibon |
73d120 |
1,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
files = os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.archive_path, "test", "tags", "v1.0")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.archive_path, "test", "tags", "v1.0", files[0]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
),
|
|
Pierre-Yves Chibon |
73d120 |
["test-v1.0.tar"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_w_tag_tar_gz(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive from a tag. """
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/archive/v1.0/test-v1.0.tar.gz", follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(os.listdir(self.archive_path), ["test"])
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test")), ["tags"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test", "tags")),
|
|
Pierre-Yves Chibon |
73d120 |
["v1.0"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
len(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.archive_path, "test", "tags", "v1.0")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
),
|
|
Pierre-Yves Chibon |
73d120 |
1,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
files = os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.archive_path, "test", "tags", "v1.0")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.archive_path, "test", "tags", "v1.0", files[0]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
),
|
|
Pierre-Yves Chibon |
73d120 |
["test-v1.0.tar.gz"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_w_commit_tar_gz(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive from a commit. """
|
|
Pierre-Yves Chibon |
73d120 |
repopath = os.path.join(self.path, "repos", "test.git")
|
|
Pierre-Yves Chibon |
ded1fa |
repo = pygit2.Repository(repopath)
|
|
Pierre-Yves Chibon |
ded1fa |
commit = repo.head.target.hex
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/archive/%s/test-v1.0.tar.gz" % commit,
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(os.listdir(self.archive_path), ["test"])
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test")), [commit]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test", commit)),
|
|
Pierre-Yves Chibon |
73d120 |
["test-v1.0.tar.gz"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
def test_project_w_commit_tar_gz_twice(self):
|
|
Pierre-Yves Chibon |
ded1fa |
""" Test getting the archive from a commit twice, so we hit the
|
|
Pierre-Yves Chibon |
ded1fa |
disk cache. """
|
|
Pierre-Yves Chibon |
73d120 |
repopath = os.path.join(self.path, "repos", "test.git")
|
|
Pierre-Yves Chibon |
ded1fa |
repo = pygit2.Repository(repopath)
|
|
Pierre-Yves Chibon |
ded1fa |
commit = repo.head.target.hex
|
|
Pierre-Yves Chibon |
ded1fa |
with mock.patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config",
|
|
Pierre-Yves Chibon |
73d120 |
{"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/archive/%s/test-v1.0.tar.gz" % commit,
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/archive/%s/test-v1.0.tar.gz" % commit,
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(os.listdir(self.archive_path), ["test"])
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test")), [commit]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
os.listdir(os.path.join(self.archive_path, "test", commit)),
|
|
Pierre-Yves Chibon |
73d120 |
["test-v1.0.tar.gz"],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
ded1fa |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
ded1fa |
unittest.main(verbosity=2)
|