def test_if_related_object_does_not_exist_validation_error_is_raised(self): from waldur_core.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 setUp(self): from waldur_core.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', field_name='customer__uuid')
def test_if_user_does_not_have_permissions_for_related_object_validation_error_is_raised( self): from waldur_core.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 test_user_can_not_create_submission_for_unrelated_customer(self): self.client.force_authenticate(self.user) del self.payload['customer_create_request'] self.payload['customer'] = CustomerFactory.get_url( self.fixture.customer) response = self.client.post(self.list_url, self.payload) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def get_valid_payload(self): return { 'name': 'Azure service', 'customer': CustomerFactory.get_url(self.fixture.customer), 'tenant_id': uuid.uuid4(), 'client_id': uuid.uuid4(), 'client_secret': uuid.uuid4(), 'subscription_id': uuid.uuid4(), }
def get_valid_payload(self): return { 'type': 'SLURM', 'name': 'SLURM service', 'customer': CustomerFactory.get_url(self.fixture.customer), 'options': { 'username': '******', 'hostname': 'slurm.waldur.com', 'default_account': 'waldur_user', 'port': 22, 'use_sudo': True, 'gateway': '8.8.8.8', }, }
def setUp(self): self.fixture = ProjectFixture() self.url = ServiceSettingsFactory.get_list_url() self.valid_payload = { 'type': 'Azure', 'name': 'Azure service', 'customer': CustomerFactory.get_url(self.fixture.customer), 'options': { 'tenant_id': uuid.uuid4().hex, 'client_id': uuid.uuid4().hex, 'client_secret': uuid.uuid4().hex, 'subscription_id': uuid.uuid4().hex, }, }
def test_user_can_create_submission_for_existing_customer(self): self.client.force_authenticate(self.user) del self.payload['customer_create_request'] self.payload['customer'] = CustomerFactory.get_url( self.fixture.customer) self.fixture.project.add_user(self.user, ProjectRole.MEMBER) response = self.client.post(self.list_url, self.payload) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) flow = FlowTracker.objects.get(uuid=response.data['uuid']) self.assertEqual(flow.customer_create_request, None) self.assertEqual(flow.customer, self.fixture.customer)
def test_if_related_object_exists_it_is_deserialized(self): from waldur_core.structure.tests.factories import CustomerFactory customer = CustomerFactory() valid_url = CustomerFactory.get_url(customer) self.assertEqual(self.field.to_internal_value(valid_url), customer)