Add pricing checks and controlled defect for issue #8
startup-product-ci/pipeline/pr-main There was a failure building this commit
startup-product-ci/pipeline/pr-main There was a failure building this commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
Vendored
+12
-16
@@ -1,30 +1,26 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent { label 'controller-small-trusted' }
|
||||||
|
options {
|
||||||
|
skipDefaultCheckout()
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
timeout(time: 5, unit: 'MINUTES')
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '20'))
|
||||||
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
checkout scm
|
checkout scm
|
||||||
|
sh 'git rev-parse HEAD && python3 --version'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage('Syntax check') {
|
||||||
stage('Lint') {
|
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh 'python3 -m py_compile pricing.py tests/test_pricing.py'
|
||||||
set -eu
|
|
||||||
test -f README.md
|
|
||||||
grep -qi "startup" README.md
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage('Unit tests') {
|
||||||
stage('Automated Test') {
|
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh 'python3 -m unittest discover -s tests -v'
|
||||||
set -eu
|
|
||||||
printf "CI smoke test for startup-product\\n"
|
|
||||||
find . -maxdepth 2 -type f | sort | head -20
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
def total_price(unit_price, quantity):
|
||||||
|
if quantity < 1:
|
||||||
|
raise ValueError("Quantity must be positive")
|
||||||
|
return unit_price + quantity
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from pricing import total_price
|
||||||
|
|
||||||
|
|
||||||
|
class PricingTests(unittest.TestCase):
|
||||||
|
def test_total(self):
|
||||||
|
self.assertEqual(total_price(10, 3), 30)
|
||||||
|
|
||||||
|
def test_single_item(self):
|
||||||
|
self.assertEqual(total_price(12.5, 1), 12.5)
|
||||||
|
|
||||||
|
def test_invalid_quantity(self):
|
||||||
|
for quantity in (0, -1):
|
||||||
|
with self.subTest(quantity=quantity):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
total_price(10, quantity)
|
||||||
Reference in New Issue
Block a user