Skip to content

Instantly share code, notes, and snippets.

View katiayn's full-sized avatar

Kátia Nakamura katiayn

View GitHub Profile
class Property(models.Model):
# fields
class Meta:
abstract = True
class Property(models.Model):
price = models.DecimalField(max_digits=15, decimal_places=2)
rooms = models.PositiveIntegerField()
address = models.TextField(null=True, blank=True)
city = models.CharField(max_length=255)
country = models.CharField(max_length=255)
class Meta:
abstract = True
$ # mut.py --target node --unit-test test_node
$ mut.py --target calculator --unit-test test_calculator -m
[*] Start mutation process:
- targets: calculator
- tests: test_calculator
[*] All tests passed:
- test_calculator [0.00031 s]
[*] Start mutants generation and execution:
- [# 1] AOR calculator.py:2 :
--------------------------------------------------------------------
1: def mul(x, y):
~2: return x / y
class ProductQuestionnaireCreateTestCase(SimpleTestCase):
def test_vat_20_if_biscuit_coated_in_chocolate(self):
calc = VATCalculator()
self.assertEqual(
calc.calculate_vat(
is_biscuit=True,
is_coated_in_chocolate=True
), 20)
class VATCalculator(object):
def calculate_vat(self, **kwargs):
is_biscuit = kwargs['is_biscuit']
is_coated_in_chocolate = kwargs['is_coated_in_chocolate']
if is_biscuit and is_coated_in_chocolate:
return 20
class ProductQuestionnaireTestCase(TestCase):
def test_vat_20_if_biscuit_coated_in_chocolate(self):
product = ProductFactory()
form = ProductQuestionnaireForm(data={
'is_biscuit': True,
'is_coated_in_chocolate': True
})
self.assertTrue(form.is_valid())
form.save()
class ProductQuestionnaireForm(forms.ModelForm):
class Meta:
model = ProductQuestionnaire
exclude = (
'id',
'product',
)
def save(self, commit=True):
class ProductQuestionnaireTestCase(TestCase):
def test_vat_20_if_biscuit_coated_in_chocolate(self):
product = ProductFactory()
url = '/{}/questionnaire/'.format(product.pk)
self.client.post(url, {
'is_biscuit': True,
'is_coated_in_chocolate': True
})
product.refresh_from_db()
def form_valid(self, form):
self.instance = form.save(commit=False)
object = self.get_object()
if self.instance.is_biscuit and self.instance.is_coated_in_chocolate:
object.set_vat_20()
return super().form_valid(form)