def test_if_user_does_not_have_permissions_for_related_object_validation_error_is_raised(self): from nodeconductor.structure.tests.factories import CustomerFactory customer = CustomerFactory() valid_url = CustomerFactory.get_url(customer) self.user.is_staff = False self.user.save() self.assertRaises(serializers.ValidationError, self.field.to_internal_value, valid_url)
def setUp(self): from nodeconductor.structure.tests.factories import CustomerFactory self.customer = CustomerFactory() self.url = CustomerFactory.get_url(self.customer) self.customer_filter = core_filters.URLFilter( view_name='customer-detail', name='customer__uuid' )
def test_if_related_object_does_not_exist_validation_error_is_raised(self): from nodeconductor.structure.tests.factories import CustomerFactory customer = CustomerFactory() valid_url = CustomerFactory.get_url(customer) customer.delete() self.assertRaises(serializers.ValidationError, self.field.to_internal_value, valid_url)
def test_if_related_object_exists_it_is_deserialized(self): from nodeconductor.structure.tests.factories import CustomerFactory customer = CustomerFactory() valid_url = CustomerFactory.get_url(customer) self.assertEqual(self.field.to_internal_value(valid_url), customer)
def get_url(self): return CustomerFactory.get_url(self.customer, 'balance_history')