Unit test cases for pypi package download redirection
@@ -15,6 +15,7 @@ import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -37,9 +38,9 @@ public class PypiArtifactControllerTest extends PypiRestAssuredBaseTest
super.init();
}
+ @Test
@ExtendWith({ RepositoryManagementTestExecutionListener.class,
ArtifactManagementTestExecutionListener.class })
- @Test
public void testUploadPackageFlow(@PypiTestRepository(repositoryId = REPOSITORY_RELEASES, storageId = REPOSITORY_STORAGE) Repository repository,
@PypiTestArtifact(repositoryId = REPOSITORY_RELEASES, storageId = REPOSITORY_STORAGE, id = "hello_world_pipy", versions = "1.3") Path packagePath)
throws Exception
@@ -47,7 +48,7 @@ public class PypiArtifactControllerTest extends PypiRestAssuredBaseTest
final String storageId = repository.getStorage().getId();
final String repositoryId = repository.getId();
- RepositoryPath repositoryPath = (RepositoryPath) packagePath.normalize();
+ final RepositoryPath repositoryPath = (RepositoryPath) packagePath.normalize();
String url = getContextBaseUrl() + "/storages/{storageId}/{repositoryId}";
@@ -98,4 +99,32 @@ public class PypiArtifactControllerTest extends PypiRestAssuredBaseTest
.body(Matchers.containsString("The artifact was deployed successfully."));
}
+ @Test
+ @ExtendWith({ RepositoryManagementTestExecutionListener.class,
+ ArtifactManagementTestExecutionListener.class })
+ public void testDownloadPackageRedirectionFlow(@PypiTestRepository(repositoryId = REPOSITORY_RELEASES, storageId = REPOSITORY_STORAGE) Repository repository)
+ throws Exception
+ {
+ final String storageId = repository.getStorage().getId();
+ final String repositoryId = repository.getId();
+ final String packageName = "hello-world-pypi";
+
+ final String url = getContextBaseUrl() + "/storages/{storageId}/{repositoryId}/{packageName}/";
+
+ final String expectedRedirectionUrl = getContextBaseUrl() + "/storages/" + storageId + "/" + repositoryId
+ + "/simple/" + packageName + "/";
+
+ // Upload with Invalid action
+ mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE)
+ .when()
+ .get(url, storageId, repositoryId, packageName)
+ .then()
+ .log()
+ .all()
+ .statusCode(HttpStatus.SEE_OTHER.value())
+ .contentType(ContentType.TEXT)
+ .header(HttpHeaders.LOCATION, Matchers.is(expectedRedirectionUrl));
+
+ }
+
}
