コード例 #1
0
 def test_network_list(self):
     """Get networks list"""
     for i in xrange(10):
         network = Network(name='Network %i' % i,
                           description='Description %i' % i,
                           user=self.user)
         network.save()
     response = self.client.get(reverse('network_list'))
     self.assertEqual(response.status_code, 200)
コード例 #2
0
def create_hostonly(user, host, ip, netmask, lower_ip, upper_ip):
    data_dict = dict(request_type="network", request_id=random_str(), request_userid=user.id,
                     operation_type=CREATE_HOSTONLY, ip=ip, netmask=netmask, lower_ip=lower_ip, upper_ip=upper_ip)

    response_dict = communicate(data_dict, host.ip, host.vm_manager_port)
    net_name = response_dict["net_name"]
    network = Network(name=net_name, type=INTNET, host=host, ip=ip, netmask=netmask, lower_ip=lower_ip,
                      upper_ip=upper_ip, machines=json.dumps([]))
    network.save()
コード例 #3
0
 def test_network_update(self):
     """Update existing network"""
     network = Network(name='Network', description='Description', user=self.user)
     network.save()
     network_data = {
         'name': 'New name',
         'description': 'New description'
     }
     response = self.client.post(reverse('network_update', args=[network.pk]), network_data)
     self.assertEqual(response.status_code, 302)
コード例 #4
0
class UserAccessTest(TestCase):
    """Tests for user access and sharing objects"""
    
    def setUp(self):
        self.client = Client()
        
        self.user = User.objects.create_user('user', '*****@*****.**', 'userpassword')
        self.client.login(username='******', password='******')
        
        self.other_user = User.objects.create_user('other', '*****@*****.**', 'otherpassword')
        
        self.host = Host(name="Host", description="Description",
                         ipv4='1.2.3.4', ipv6='2002:0:0:0:0:0:c22:384e',
                         user=self.user)
        self.host.save()
        
        self.net = Network(name="Net", description="Description", user=self.user)
        self.net.save()
        
    def test_user_host_access(self):
        access = user_has_access(self.host, self.user)
        self.assertEqual(access, True)
        
        access = user_has_access(self.host, self.other_user)
        self.assertEqual(access, False)
        
    def test_user_host_share(self):
        grant_access(self.host, self.other_user)
        access = user_has_access(self.host, self.other_user)
        self.assertEqual(access, True)
        
        access = user_can_edit(self.host, self.other_user)
        self.assertEqual(access, True)
        
        revoke_edit(self.host, self.other_user)
        access = user_can_edit(self.host, self.other_user)
        self.assertEqual(access, False)
        
        revoke_access(self.host, self.other_user)
        access = user_has_access(self.host, self.other_user)
        self.assertEqual(access, False)
        
    def test_user_network_access(self):
        access = user_has_access(self.net, self.user)
        self.assertEqual(access, True)
        
        access = user_has_access(self.net, self.other_user)
        self.assertEqual(access, False)
        
    def test_user_network_share(self):
        grant_access(self.net, self.other_user)
        access = user_has_access(self.net, self.other_user)
        self.assertEqual(access, True)
        
        access = user_can_edit(self.net, self.other_user)
        self.assertEqual(access, True)
        
        revoke_edit(self.net, self.other_user)
        access = user_can_edit(self.net, self.other_user)
        self.assertEqual(access, False)
        
        revoke_access(self.net, self.other_user)
        access = user_has_access(self.net, self.other_user)
        self.assertEqual(access, False)
コード例 #5
0
 def test_network_delete(self):
     """Deleting existing network"""
     network = Network(name='Network', description='Description', user=self.user)
     network.save()
     response = self.client.post(reverse('network_delete', args=[network.pk]))
     self.assertEqual(response.status_code, 302)
コード例 #6
0
 def test_network_detail(self):
     """Get network details"""
     network = Network(name='Network', description='Description', user=self.user)
     network.save()
     response = self.client.get(reverse('network_detail', args=[network.pk]))
     self.assertEqual(response.status_code, 200)