This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Property(models.Model): | |
# fields | |
class Meta: | |
abstract = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ # mut.py --target node --unit-test test_node | |
$ mut.py --target calculator --unit-test test_calculator -m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[*] 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductQuestionnaireForm(forms.ModelForm): | |
class Meta: | |
model = ProductQuestionnaire | |
exclude = ( | |
'id', | |
'product', | |
) | |
def save(self, commit=True): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder