Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 84a44f0477 | |||
| a5180ad781 | |||
| 8ba340e32f | |||
| c5538a84d1 | |||
| 81c343ddb6 | |||
| 091a9a9695 | |||
| ab0bcc25f3 | |||
| fa22a0d512 | |||
| b779817f2c | |||
| b899233138 |
@@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
||||||
Vendored
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// CI pipeline for Scrap-Web (SSW 590, Continuous Integration with Jenkins).
|
||||||
|
// Runs for every pull request through the Multibranch Pipeline job and reports
|
||||||
|
// its result to Gitea as a commit status. Uses only the Python 3 standard
|
||||||
|
// library, so no packages are downloaded during the build.
|
||||||
|
pipeline {
|
||||||
|
// Builds run on the Jenkins controller executor (see the IT manual for the
|
||||||
|
// documented risk). python3 must be installed in the Jenkins container.
|
||||||
|
agent any
|
||||||
|
|
||||||
|
options {
|
||||||
|
skipDefaultCheckout()
|
||||||
|
timeout(time: 10, unit: 'MINUTES')
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
// Record exactly which commit is being tested, for traceability.
|
||||||
|
sh 'git rev-parse HEAD'
|
||||||
|
sh 'python3 --version'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Syntax check') {
|
||||||
|
steps {
|
||||||
|
sh 'python3 -m py_compile pricing.py tests/test_pricing.py'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Test') {
|
||||||
|
steps {
|
||||||
|
sh 'python3 -m unittest discover -s tests -v'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success { echo 'All checks passed.' }
|
||||||
|
failure { echo 'A stage failed: see the stage view for which one.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# Jenkins controller image for the Scrap-Web CI pipeline (SSW 590).
|
|
||||||
# The official Jenkins LTS image does not include Python, which the
|
|
||||||
# Jenkinsfile needs (builds run on the controller executor).
|
|
||||||
#
|
|
||||||
# Replace <LTS-TAG> with the exact tag currently in the Compose file,
|
|
||||||
# e.g. 2.xxx.y-lts-jdk21, so the recorded Jenkins version does not change.
|
|
||||||
FROM jenkins/jenkins:<LTS-TAG>
|
|
||||||
|
|
||||||
USER root
|
|
||||||
RUN apt-get update \
|
|
||||||
&& apt-get install -y --no-install-recommends python3 \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
USER jenkins
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
"""Pricing helper for the Scrap-Web CI pipeline (SSW 590, Jenkins assignment)."""
|
||||||
|
|
||||||
|
|
||||||
|
def total_price(unit_price, quantity):
|
||||||
|
"""Return the total price for `quantity` items at `unit_price` each."""
|
||||||
|
if quantity < 1:
|
||||||
|
raise ValueError("Quantity must be positive")
|
||||||
|
return unit_price * quantity
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from pricing import total_price
|
||||||
|
|
||||||
|
|
||||||
|
class PricingTests(unittest.TestCase):
|
||||||
|
def test_total(self):
|
||||||
|
self.assertEqual(total_price(10, 3), 30)
|
||||||
|
|
||||||
|
def test_invalid_quantity(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
total_price(10, 0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user