コード例 #1
0
 def test_password_required(self):
     """ if either username or password are entered both are required """
     relation = ['username', 'password']
     for property in relation:
         data_ = self.data.copy()
         del data_[property]
         form = EditClusterForm(data_)
         self.assertFalse(form.is_valid())
コード例 #2
0
 def test_password_required(self):
     """ if either username or password are entered both are required """
     relation = ['username', 'password']
     for property in relation:
         data_ = self.data.copy()
         del data_[property]
         form = EditClusterForm(data_)
         self.assertFalse(form.is_valid())
コード例 #3
0
ファイル: cluster.py プロジェクト: bsu/GWM2
 def test_read_only(self):
     """ success without username or password """
     data_ = self.data
     del data_['username']
     del data_['password']
     form = EditClusterForm(data_)
     self.assertTrue(form.is_valid())
     cluster = form.save()
     for k, v in data_.items():
         self.assertEqual(v, getattr(cluster, k))
コード例 #4
0
 def test_valid_edit(self):
     """
     successfully edit a cluster
     """
     data = self.data
     form = EditClusterForm(data, instance=self.cluster)
     self.assertTrue(form.is_valid())
     cluster = form.save()
     for k, v in data.items():
         self.assertEqual(v, getattr(cluster, k))
コード例 #5
0
 def test_valid_edit(self):
     """
     successfully edit a cluster
     """
     data = self.data
     form = EditClusterForm(data, instance=self.cluster)
     self.assertTrue(form.is_valid())
     cluster = form.save()
     for k, v in data.items():
         self.assertEqual(v, getattr(cluster, k))
コード例 #6
0
 def test_read_only(self):
     """ success without username or password """
     data_ = self.data
     del data_['username']
     del data_['password']
     form = EditClusterForm(data_)
     self.assertTrue(form.is_valid())
     cluster = form.save()
     for k, v in data_.items():
         self.assertEqual(v, getattr(cluster, k))
     cluster.delete()
コード例 #7
0
 def test_required_fields(self):
     """
     Tests adding a new cluster
     """
     data = self.data
     required = ['hostname', 'port']
     for property in required:
         data_ = data.copy()
         del data_[property]
         form = EditClusterForm(data_)
         self.assertFalse(form.is_valid())
コード例 #8
0
 def test_required_fields(self):
     """
     Tests adding a new cluster
     """
     data = self.data
     required = ['hostname', 'port']
     for property in required:
         data_ = data.copy()
         del data_[property]
         form = EditClusterForm(data_)
         self.assertFalse(form.is_valid())
コード例 #9
0
 def test_optional_fields(self):
     data = self.data
     non_required = ['slug', 'description', 'virtual_cpus', 'disk', 'ram']
     for property in non_required:
         data_ = data.copy()
         del data_[property]
         form = EditClusterForm(data_)
         self.assertTrue(form.is_valid())
         cluster = form.save()
         for k, v in data_.items():
             self.assertEqual(v, getattr(cluster, k))
         cluster.delete()
コード例 #10
0
 def test_no_username_or_password_for_read_only(self):
     """
     tests that username and password are optional for read only cluster
     """
     data = self.data
     del data['username']
     del data['password']
     form = EditClusterForm(data, instance=self.cluster)
     self.assertTrue(form.is_valid())
     cluster = form.save()
     self.assertEqual('', cluster.username)
     self.assertEqual('', cluster.password)
コード例 #11
0
    def test_username_required_for_writeable_new_password(self):
        """
        if password is entered for a cluster, username is required always
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        del data['username']
        form = EditClusterForm(data, instance=self.cluster)
        self.assertFalse(form.is_valid())
コード例 #12
0
    def test_username_required_for_writeable_new_password(self):
        """
        if password is entered for a cluster, username is required always
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        del data['username']
        form = EditClusterForm(data, instance=self.cluster)
        self.assertFalse(form.is_valid())
コード例 #13
0
 def test_no_username_or_password_for_read_only(self):
     """
     tests that username and password are optional for read only cluster
     """
     data = self.data
     del data['username']
     del data['password']
     form = EditClusterForm(data, instance=self.cluster)
     self.assertTrue(form.is_valid())
     cluster = form.save()
     self.assertEqual('', cluster.username)
     self.assertEqual('', cluster.password)
コード例 #14
0
ファイル: cluster.py プロジェクト: bsu/GWM2
 def test_optional_fields(self):
     data = self.data
     non_required = ['slug','description','virtual_cpus','disk','ram']
     for property in non_required:
         data_ = data.copy()
         del data_[property]
         form = EditClusterForm(data_)
         self.assertTrue(form.is_valid())
         cluster = form.save()
         for k, v in data_.items():
             self.assertEqual(v, getattr(cluster, k))
         Cluster.objects.all().delete()
コード例 #15
0
    def test_no_password_for_writeable_new_username(self):
        """
        tests that the password is required when the username has changed
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        del data['password']
        data['username'] = '******'
        form = EditClusterForm(data, instance=self.cluster)
        self.assertFalse(form.is_valid())
コード例 #16
0
 def test_optional_fields(self):
     data = self.data
     non_required = ['slug', 'description', 'virtual_cpus', 'disk', 'ram']
     for field in non_required:
         data_ = data.copy()
         del data_[field]
         form = EditClusterForm(data_)
         self.assertTrue(form.is_valid(),
                         "Field %r was incorrectly required" % field)
         cluster = form.save()
         for k, v in data_.items():
             self.assertEqual(v, getattr(cluster, k))
         cluster.delete()
コード例 #17
0
    def test_no_password_for_writeable_new_username(self):
        """
        tests that the password is required when the username has changed
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        del data['password']
        data['username'] = '******'
        form = EditClusterForm(data, instance=self.cluster)
        self.assertFalse(form.is_valid())
コード例 #18
0
 def test_unique_fields(self):
     # test unique fields
     form = EditClusterForm(self.data)
     form.is_valid()
     form.save()
     for property in ['hostname', 'slug']:
         data_ = self.data.copy()
         data_[property] = 'different'
         form = EditClusterForm(data_)
         self.assertFalse(form.is_valid())
コード例 #19
0
def edit(request, cluster_slug=None):
    """
    Edit a cluster
    """
    if cluster_slug:
        cluster = get_object_or_404(Cluster, slug=cluster_slug)
    else:
        cluster = None

    user = request.user
    if not (user.is_superuser or (cluster and user.has_perm(
            'admin', cluster))):
        raise PermissionDenied(NO_PRIVS)

    if request.method == 'POST':
        form = EditClusterForm(request.POST, instance=cluster)
        if form.is_valid():
            cluster = form.save()
            # TODO Create post signal to import
            #   virtual machines on edit of cluster
            if cluster.info is None:
                try:
                    cluster.sync_nodes()
                    cluster.sync_virtual_machines()
                except GanetiApiError:
                    # ganeti errors here are silently discarded.  It's
                    # valid to enter bad info.  A user might be adding
                    # info for an offline cluster.
                    pass

            log_action('EDIT' if cluster_slug else 'CREATE', user, cluster)

            return HttpResponseRedirect(reverse('cluster-detail',
                                                args=[cluster.slug]))

    elif request.method == 'DELETE':
        cluster.delete()
        return HttpResponse('1', mimetype='application/json')

    else:
        form = EditClusterForm(instance=cluster)

    return render_to_response("ganeti/cluster/edit.html", {
        'form': form,
        'cluster': cluster,
    },
        context_instance=RequestContext(request),
    )
コード例 #20
0
    def test_username_and_password_change(self):
        """
        tests changing the password for a cluster that already had username and
        password set
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        form = EditClusterForm(data, instance=self.cluster)
        self.assertTrue(form.is_valid())
        cluster = form.save()

        self.assertEqual('tester', cluster.username)
        self.assertEqual('secret', cluster.password)
コード例 #21
0
    def test_no_password_for_writeable(self):
        """
        Tests that password is not required when the cluster already has the
        password available.  assumes username is the same
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        del data['password']
        form = EditClusterForm(data, instance=self.cluster)
        self.assertTrue(form.is_valid())
        cluster = form.save()
        self.assertEqual('tester', cluster.username)
        self.assertEqual('secret', cluster.password)
コード例 #22
0
    def test_no_password_for_writeable(self):
        """
        Tests that password is not required when the cluster already has the
        password available.  assumes username is the same
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        del data['password']
        form = EditClusterForm(data, instance=self.cluster)
        self.assertTrue(form.is_valid())
        cluster = form.save()
        self.assertEqual('tester', cluster.username)
        self.assertEqual('secret', cluster.password)
コード例 #23
0
    def test_username_and_password_change(self):
        """
        tests changing the password for a cluster that already had username and
        password set
        """
        self.cluster.username = '******'
        self.cluster.password = '******'
        self.cluster.save()

        data = self.data
        form = EditClusterForm(data, instance=self.cluster)
        self.assertTrue(form.is_valid())
        cluster = form.save()

        self.assertEqual('tester', cluster.username)
        self.assertEqual('secret', cluster.password)
コード例 #24
0
    def test_username_and_password_added(self):
        """
        tests setting a username and password for a cluster that did not
        previously have a username and password
        """
        self.cluster.username = ""
        self.cluster.password = ""
        self.cluster.save()

        data = self.data
        data['username'] = '******'
        data['password'] = '******'
        form = EditClusterForm(data, instance=self.cluster)
        self.assertTrue(form.is_valid())

        cluster = form.save()
        self.assertEqual('foo', cluster.username)
        self.assertEqual('bar', cluster.password)
コード例 #25
0
    def test_username_and_password_added(self):
        """
        tests setting a username and password for a cluster that did not
        previously have a username and password
        """
        self.cluster.username = None
        self.cluster.password = None
        self.cluster.save()

        data = self.data
        data['username'] = '******'
        data['password'] = '******'
        form = EditClusterForm(data, instance=self.cluster)
        self.assertTrue(form.is_valid())

        cluster = form.save()
        self.assertEqual('foo', cluster.username)
        self.assertEqual('bar', cluster.password)
コード例 #26
0
 def test_unique_fields(self):
     # test unique fields
     form = EditClusterForm(self.data)
     form.is_valid()
     form.save()
     for property in ['hostname', 'slug']:
         data_ = self.data.copy()
         data_[property] = 'different'
         form = EditClusterForm(data_)
         self.assertFalse(form.is_valid())
コード例 #27
0
def edit(request, cluster_slug=None):
    """
    Edit a cluster
    """
    if cluster_slug:
        cluster = get_object_or_404(Cluster, slug=cluster_slug)
    else:
        cluster = None

    user = request.user
    if not (user.is_superuser or
            (cluster and user.has_perm('admin', cluster))):
        raise Http403(NO_PRIVS)

    if request.method == 'POST':
        form = EditClusterForm(request.POST, instance=cluster)
        if form.is_valid():
            cluster = form.save()
            # TODO Create post signal to import
            #   virtual machines on edit of cluster
            if cluster.info is None:
                try:
                    cluster.sync_nodes()
                    cluster.sync_virtual_machines()
                except GanetiApiError:
                    # ganeti errors here are silently discarded.  It's
                    # valid to enter bad info.  A user might be adding
                    # info for an offline cluster.
                    pass

            log_action('EDIT' if cluster_slug else 'CREATE', user, cluster)

            return HttpResponseRedirect(
                reverse('cluster-detail', args=[cluster.slug]))

    elif request.method == 'DELETE':
        cluster.delete()
        return HttpResponse('1', mimetype='application/json')

    else:
        form = EditClusterForm(instance=cluster)

    return render_to_response(
        "ganeti/cluster/edit.html",
        {
            'form': form,
            'cluster': cluster,
        },
        context_instance=RequestContext(request),
    )
コード例 #28
0
 def test_bound_form(self):
     """ tests binding form with existing instance """
     form = EditClusterForm(self.data)
     self.assertTrue(form.is_valid())
コード例 #29
0
 def test_bound(self):
     form = EditClusterForm(self.data)
     self.assertTrue(form.is_valid())
コード例 #30
0
 def test_bound_form(self):
     """ tests binding form with existing instance """
     form = EditClusterForm(self.data)
     self.assertTrue(form.is_valid())
コード例 #31
0
 def test_unbound(self):
     form = EditClusterForm()
コード例 #32
0
 def test_bound(self):
     form = EditClusterForm(self.data)
     self.assertTrue(form.is_valid())