From b8992331386100141008304352997dabf4ac48b6 Mon Sep 17 00:00:00 2001 From: Samah Keshiro Date: Sun, 18 Oct 2026 15:03:41 -0400 Subject: [PATCH] Add pricing module, tests and Jenkinsfile for CI (#11) --- .gitignore | 1 + Jenkinsfile | 40 ++++++++++++++++++++++++++++++++++++++++ pricing.py | 8 ++++++++ tests/test_pricing.py | 16 ++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 Jenkinsfile create mode 100644 pricing.py create mode 100644 tests/test_pricing.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..5a339af --- /dev/null +++ b/Jenkinsfile @@ -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.' } + } +} diff --git a/pricing.py b/pricing.py new file mode 100644 index 0000000..32ec2d1 --- /dev/null +++ b/pricing.py @@ -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 diff --git a/tests/test_pricing.py b/tests/test_pricing.py new file mode 100644 index 0000000..722298a --- /dev/null +++ b/tests/test_pricing.py @@ -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()