예제 #1
0
파일: test_api.py 프로젝트: 4i60r/ralph
 def setUp(self):
     self.user = UserFactory(
         username='******', email='*****@*****.**', is_staff=True,
         is_superuser=True,
     )
     self.user.set_password('QWEasd')
     self.user.save()
     self.net_1 = NetworkFactory(
         name='test-net-1.dc',
         address="192.168.1.0/24",
     )
     self.net_1.save()
     self.net_2 = NetworkFactory(
         name='test-net-2.dc',
         address="192.168.56.0/24",
     )
     self.net_2.save()
예제 #2
0
 def setUp(self):
     self.user = UserFactory(
         username='******',
         email='*****@*****.**',
         is_staff=True,
         is_superuser=True,
     )
     self.user.set_password('QWEasd')
     self.user.save()
     self.net_1 = NetworkFactory(
         name='test-net-1.dc',
         address="192.168.1.0/24",
     )
     self.net_1.save()
     self.net_2 = NetworkFactory(
         name='test-net-2.dc',
         address="192.168.56.0/24",
     )
     self.net_2.save()
예제 #3
0
 def setUp(self):
     self.client = login_as_su()
     self.device_environment = DeviceEnvironmentFactory(name='testenv')
     self.service = ServiceCatalogFactory(name='testservice')
     self.preboot = PrebootFactory(name="prebotname")
     self.ethernet = EthernetFactory.create(mac="0025b0000000", )
     self.network = NetworkFactory.create(
         address='10.80.80.0/20',
         name='testnetwork',
     )
     self.network.save()
     self.venture_role = VentureRoleFactory(name="testventurerole",
                                            venture__symbol='testventure',
                                            venture__name='testventure')
예제 #4
0
 def setUp(self):
     self.client = login_as_su()
     self.device_environment = DeviceEnvironmentFactory(name='testenv')
     self.service = ServiceCatalogFactory(name='testservice')
     self.preboot = PrebootFactory(name="prebotname")
     self.ethernet = EthernetFactory.create(
         mac="0025b0000000",
     )
     self.network = NetworkFactory.create(
         address='10.80.80.0/20',
         name='testnetwork',
     )
     self.network.save()
     self.venture_role = VentureRoleFactory(
         name="testventurerole",
         venture__symbol='testventure',
         venture__name='testventure'
     )
예제 #5
0
파일: test_api.py 프로젝트: 4i60r/ralph
class TestNetworksResource(TestCase):

    def setUp(self):
        self.user = UserFactory(
            username='******', email='*****@*****.**', is_staff=True,
            is_superuser=True,
        )
        self.user.set_password('QWEasd')
        self.user.save()
        self.net_1 = NetworkFactory(
            name='test-net-1.dc',
            address="192.168.1.0/24",
        )
        self.net_1.save()
        self.net_2 = NetworkFactory(
            name='test-net-2.dc',
            address="192.168.56.0/24",
        )
        self.net_2.save()

    def _get_networks_names(self, result):
        return [
            network['name'] for network in result['objects']
        ]

    def test_resource(self):
        path = "/api/v0.9/networks/"
        # sort by min_ip
        response = self.client.get(
            path=path,
            data={
                'format': 'json',
                'username': self.user.username,
                'api_key': self.user.api_key.key,
                'order_by': 'min_ip',
            },
            format='json',
        )
        self.assertEqual(response.status_code, 200)
        result = json.loads(response.content)
        self.assertEqual(result['meta']['total_count'], 2)
        self.assertEqual(
            self._get_networks_names(result),
            ['test-net-1.dc', 'test-net-2.dc'],
        )
        # sort by max_ip
        response = self.client.get(
            path=path,
            data={
                'format': 'json',
                'username': self.user.username,
                'api_key': self.user.api_key.key,
                'order_by': '-max_ip',
            },
            format='json',
        )
        self.assertEqual(response.status_code, 200)
        result = json.loads(response.content)
        self.assertEqual(result['meta']['total_count'], 2)
        self.assertEqual(
            self._get_networks_names(result),
            ['test-net-2.dc', 'test-net-1.dc'],
        )
        # filter by min_ip
        response = self.client.get(
            path=path,
            data={
                'format': 'json',
                'username': self.user.username,
                'api_key': self.user.api_key.key,
                'min_ip__lte': '3232235777',
            },
            format='json',
        )
        self.assertEqual(response.status_code, 200)
        result = json.loads(response.content)
        self.assertEqual(result['meta']['total_count'], 1)
        self.assertEqual(
            self._get_networks_names(result),
            ['test-net-1.dc'],
        )
예제 #6
0
class TestNetworksResource(TestCase):
    def setUp(self):
        self.user = UserFactory(
            username='******',
            email='*****@*****.**',
            is_staff=True,
            is_superuser=True,
        )
        self.user.set_password('QWEasd')
        self.user.save()
        self.net_1 = NetworkFactory(
            name='test-net-1.dc',
            address="192.168.1.0/24",
        )
        self.net_1.save()
        self.net_2 = NetworkFactory(
            name='test-net-2.dc',
            address="192.168.56.0/24",
        )
        self.net_2.save()

    def _get_networks_names(self, result):
        return [network['name'] for network in result['objects']]

    def test_resource(self):
        path = "/api/v0.9/networks/"
        # sort by min_ip
        response = self.client.get(
            path=path,
            data={
                'format': 'json',
                'username': self.user.username,
                'api_key': self.user.api_key.key,
                'order_by': 'min_ip',
            },
            format='json',
        )
        self.assertEqual(response.status_code, 200)
        result = json.loads(response.content)
        self.assertEqual(result['meta']['total_count'], 2)
        self.assertEqual(
            self._get_networks_names(result),
            ['test-net-1.dc', 'test-net-2.dc'],
        )
        # sort by max_ip
        response = self.client.get(
            path=path,
            data={
                'format': 'json',
                'username': self.user.username,
                'api_key': self.user.api_key.key,
                'order_by': '-max_ip',
            },
            format='json',
        )
        self.assertEqual(response.status_code, 200)
        result = json.loads(response.content)
        self.assertEqual(result['meta']['total_count'], 2)
        self.assertEqual(
            self._get_networks_names(result),
            ['test-net-2.dc', 'test-net-1.dc'],
        )
        # filter by min_ip
        response = self.client.get(
            path=path,
            data={
                'format': 'json',
                'username': self.user.username,
                'api_key': self.user.api_key.key,
                'min_ip__lte': '3232235777',
            },
            format='json',
        )
        self.assertEqual(response.status_code, 200)
        result = json.loads(response.content)
        self.assertEqual(result['meta']['total_count'], 1)
        self.assertEqual(
            self._get_networks_names(result),
            ['test-net-1.dc'],
        )