示例#1
0
    def test_find_all_machines(self):
        Machine().insert({
            'name': 'machine10',
            'description': 'cool machine10',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        })

        Machine().insert({
            'name': 'machine11',
            'description': 'cool machine11',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        })

        machines = Machine().find()

        self.assertIsInstance(machines.data, list,
                              'Machines data is not a list')
        self.assertEqual(len(machines.data), 2,
                         'There are more than 2 machines')
示例#2
0
    def test_update_machine(self):
        m = {
            'name': 'machine12',
            'description': 'cool machine12',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        }

        Machine().insert(m)

        m['description'] = 'TEST'
        m['network'] = '10.0.0.0'

        status = Machine().update({'name': m['name']}, m)
        machine = Machine().find({'name': m['name']})

        self.assertNotEqual(status, False, 'Machine not updated')

        self.assertIsInstance(machine.data, dict, 'Machine data is not a dict')
        self.assertEqual(machine.data['network'], '10.0.0.0', 'Wrong network')
        self.assertEqual(machine.data['description'], 'TEST',
                         'Wrong description')
示例#3
0
    def test_find_full_machine(self):
        m = {
            'name': 'machine9',
            'description': 'cool machine9',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        }

        keys = [
            '_id', 'name', 'description', 'type', 'ipv4', 'ipv6', 'mac',
            'broadcast', 'gateway', 'netmask', 'network', 'deleted'
        ]

        Machine().insert(m)
        machine = Machine().find({'name': m['name']})

        self.assertNotEqual(machine, None, 'Machine not created')
        self.assertIsInstance(machine.data, dict, 'Machine data is not a dict')
        self.assertListEqual(list(machine.data.keys()), keys,
                             'Keys are not equal')
示例#4
0
    def test_find_all_machines(self):
        Machine().insert({
            'name': 'machine10',
            'description': 'cool machine10',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        })

        Machine().insert({
            'name': 'machine11',
            'description': 'cool machine11',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        })

        response = self.app.post(self.path + '/query',
                                 headers=self.headers,
                                 data=json.dumps({'query': {}}))
        self.assertEqual(response.status_code, 200, 'Machines not found')
        self.assertEqual(json.loads(response.data)['total'], 2)
示例#5
0
    def test_create_full_machine(self):
        status = Machine().insert({
            'name': 'machine1',
            'description': 'cool machine1',
            'type': 'local',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        })
        self.assertEqual(status, True, 'Machine (local) not added')

        status = Machine().insert({
            'name': 'machine2',
            'description': 'cool machine2',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        })
        self.assertEqual(status, True, 'Machine (remote) not added')
示例#6
0
    def post():
        data = validate_or_abort(QuerySchema, request.get_json())
        user = Machine().find(
            criteria=data['query'],
            projection=data['filter'] if 'filter' in data.keys() else {})

        return parse_data(MachineSchema, user.data)
示例#7
0
    def test_find_full_machine(self):
        m = {
            'name': 'machine9',
            'description': 'cool machine9',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        }

        Machine().insert(m)

        response = self.app.get(self.path + '/' + m['name'],
                                headers=self.headers)

        data = json.loads(response.data)

        self.assertEqual(response.status_code, 200, 'Machine not found')
        self.assertIsInstance(data, dict, 'Machine data is not a dict')

        self.assertEqual(m['name'], data['name'], 'Wrong name')
        self.assertEqual(m['description'], data['description'],
                         'Wrong description')
        self.assertEqual(m['gateway'], data['gateway'], 'Wrong gateway')
        self.assertEqual(m['mac'], data['mac'], 'Wrong mac')
示例#8
0
    def test_remove_machine(self):
        m = {
            'name': 'machine13',
            'description': 'cool machine13',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        }

        Machine().insert(m)
        status = Machine().remove({'name': m['name']})
        self.assertEqual(status, True, 'Machine not deleted')
示例#9
0
 def create_machine_with_missing_info(self):
     status = Machine().insert({
         'name': 'machine5',
         'description': 'cool machine5',
         'type': 'remote',
         'ipv4': '192.168.1.10',
         'broadcast': '192.168.1.255',
         'network': '192.168.1.0'
     })
     self.assertEqual(status, True, 'Machine not added')
示例#10
0
 def create_machine_with_wrong_mac(self):
     status = Machine().insert({
         'name': 'machine8',
         'description': 'cool machine8',
         'type': 'remote',
         'ipv4': '192.168.1.10',
         'mac': '00:0a:95:9d',
         'broadcast': '192.168.1.255',
         'network': '192.168.1.0'
     })
     self.assertEqual(status, False, 'Machine with wrong mac added')
示例#11
0
    def create_machine_with_wrong_ip(self):
        status = Machine().insert({
            'name': 'machine6',
            'description': 'cool machine6',
            'type': 'remote',
            'ipv4': '192.168.1.500',
            'broadcast': '192.168.1.255',
            'network': '192.168.1.0'
        })
        self.assertEqual(status, False, 'Machine with wrong ipv4 added')

        status = Machine().insert({
            'name': 'machine7',
            'description': 'cool machine7',
            'type': 'remote',
            'ipv6': '192.168.1.500',
            'broadcast': '192.168.1.255',
            'network': '192.168.1.0'
        })
        self.assertEqual(status, False, 'Machine with wrong ipv6 added')
示例#12
0
    def test_update_machine(self):
        m = {
            'name': 'machine12',
            'description': 'cool machine12',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        }

        Machine().insert(m)

        response = self.app.put(self.path,
                                headers=self.headers,
                                data=json.dumps({
                                    'name': m['name'],
                                    'data': {
                                        'name': 'machine12',
                                        'description': 'TEST machine',
                                        'type': 'local',
                                        'ipv4': '10.0.0.10',
                                        'ipv6': 'fdf8:f53b:82e4::53',
                                        'mac': '00:0a:95:9d:68:16',
                                        'broadcast': '192.168.1.255',
                                        'gateway': '192.168.1.1',
                                        'netmask': '255.255.255.0',
                                        'network': '10.0.0.0'
                                    }
                                }))
        self.assertEqual(response.status_code, 200, 'Machine not updated')

        machine = Machine().find({'name': m['name']})

        self.assertIsInstance(machine.data, dict, 'Machine data is not a dict')
        self.assertEqual(machine.data['network'], '10.0.0.0', 'Wrong network')
        self.assertEqual(machine.data['description'], 'TEST machine',
                         'Wrong description')
示例#13
0
    def test_remove_machine(self):
        m = {
            'name': 'machine13',
            'description': 'cool machine13',
            'type': 'remote',
            'ipv4': '192.168.1.10',
            'ipv6': 'fdf8:f53b:82e4::53',
            'mac': '00:0a:95:9d:68:16',
            'broadcast': '192.168.1.255',
            'gateway': '192.168.1.1',
            'netmask': '255.255.255.0',
            'network': '192.168.1.0'
        }

        Machine().insert(m)
        response = self.app.delete(self.path,
                                   headers=self.headers,
                                   data=json.dumps({'name': m['name']}))
        self.assertEqual(response.status_code, 204, 'Machine not deleted')
示例#14
0
 def post():
     data = validate_or_abort(MachineSchema, request.get_json())
     return response_by_success(Machine().insert(data))
示例#15
0
 def get(name):
     user = Machine().find(criteria={'name': name})
     return parse_data(MachineSchema, user.data)
示例#16
0
    def test_create_duplicated_customer(self):
        Machine().insert({'name': 'machine4', 'type': 'local'})

        status = Machine().insert({'name': 'machine4', 'type': 'local'})
        self.assertEqual(status, False, 'Duplicated machine added')
示例#17
0
 def put():
     data = validate_or_abort(MachineSchemaPut, request.get_json())
     return response_by_success(Machine().update(
         criteria={'name': data['name']}, data=data['data']))
示例#18
0
 def delete():
     data = validate_or_abort(MachineSchemaDelete, request.get_json())
     return response_by_success(
         Machine().remove(criteria={'name': data['name']}), is_remove=True)
示例#19
0
 def create_empty_machine(self):
     status = Machine().insert({'name': 'machine3', 'type': 'local'})
     self.assertEqual(status, True, 'Machine not added')