Exemplo n.º 1
0
    def test_field_type(self):
        data = {
            'kind': FuzzyText('', 100).fuzz(),
            'amount': FuzzyText('', 100).fuzz(),
            'target_amount': FuzzyText('', 100).fuzz(),
            'is_minimum_purchase': FuzzyText('', 100).fuzz(),
        }
        obj = self.Model(**data)

        try:
            obj.full_clean()
        except ValidationError as e:
            for key, _ in data.items():
                self.assertTrue(key in e.message_dict)
Exemplo n.º 2
0
    def test_validation_error_field_value_out_of_scope(self):
        """
        Test the validation of model with the field value out of scope.
        """
        data = {
            'name': FuzzyText('', 200).fuzz(),
            'email': None,
            'is_active': FuzzyText().fuzz(),
        }

        customer = Customer(**data)
        try:
            customer.full_clean()
        except ValidationError as e:
            for key, _ in data.items():
                self.assertTrue(key in e.message_dict)
Exemplo n.º 3
0
    def test_field_type(self):
        data = {
            'is_active': FuzzyText('', 100).fuzz(),
        }
        obj = Reward(**data)

        try:
            obj.full_clean()
        except ValidationError as e:
            for key, _ in data.items():
                self.assertTrue(key in e.message_dict)
Exemplo n.º 4
0
    def test_model_can_be_updated(self):
        data = {'name': FuzzyText('', 100).fuzz()}

        # Create new one
        obj = self.Factory()

        # Update
        for key, value in data.items():
            setattr(obj, key, value)
        obj.save()

        # Check data
        self.assertEqual(obj.name, data['name'])
Exemplo n.º 5
0
    def test_validation_error_field_type(self):
        """
        Test the validation of model.
        """
        data = {
            'is_active': FuzzyText().fuzz(),
        }

        customer = Customer(**data)
        try:
            customer.full_clean()
        except ValidationError as e:
            for key, _ in data.items():
                self.assertTrue(key in e.message_dict)
Exemplo n.º 6
0
    def test_model_can_be_updated(self):
        update_data = {
            'parent': self.Factory(),
            'name': FuzzyText('', 100).fuzz(),
        }

        obj = self.Model.objects.last()
        for key, value in update_data.items():
            setattr(obj, key, value)

        obj.save()

        self.assertTrue(isinstance(obj.parent, self.Model))
        self.assertEqual(obj.name, update_data['name'])
Exemplo n.º 7
0
    def test_customer_can_be_updated(self):
        update_data = {
            'name': FuzzyText('customer').fuzz(),
            'is_active': False,
            'total_earned_point': 3000,
        }

        customer = Customer.objects.first()

        for key, value in update_data.items():
            setattr(customer, key, value)

        customer.save()
        customer.refresh_from_db()

        # Check customer updated data
        self.assertEqual(customer.name, update_data['name'])
        self.assertEqual(customer.is_active, update_data['is_active'])
        self.assertEqual(customer.total_earned_point,
                         update_data['total_earned_point'])
        self.assertNotEqual(customer.membership, None)
Exemplo n.º 8
0
    def test_model_can_be_updated(self):

        obj = self.Model.objects.last()

        updated_data = {
            'name': FuzzyText('', 100).fuzz(),
            'category': CategoryFactory(),
            'usage': UsageFactory(),
            'article_type': ArticleTypeFactory(),
            'season': SeasonFactory(),
        }

        for key, value in updated_data.items():
            setattr(obj, key, value)

        obj.save()
        self.assertEqual(obj.category.id, updated_data['category'].id)
        self.assertEqual(obj.usage.id, updated_data['usage'].id)
        self.assertEqual(obj.article_type.id, updated_data['article_type'].id)
        self.assertEqual(obj.season.id, updated_data['season'].id)
        self.assertEqual(obj.name, updated_data['name'])