Esempio n. 1
0
    def test_ansible_inventory_default_tags(self):
        fireflash = Item('fireflash')
        mole = Item('mole')
        fab1 = Item('fab1')
        linux = Tag('linux')
        ansible = Tag('ansible-managed')
        windows = Tag('windows')
        multiple = Tag('multiple')
        fireflash.add_to(linux)
        mole.add_to(ansible)
        fab1.add_to(windows)
        fireflash.add_to(multiple)
        fab1.add_to(multiple)
        linux.save()
        ansible.save()
        windows.save()
        multiple.save()

        with app.test_client() as c:
            rv = self.get_json(c, '/api/ansible_inventory/')
            data = json.loads(rv.data)
            assert rv.status_code == 200
            print data
            assert data == {
                'linux': {'hosts': ['fireflash']},
                'ansible-managed': {'hosts': ['mole']},
                'windows': {'hosts': []},
                'multiple': {'hosts': ['fireflash']},
                '_meta': {'hostvars': {'fireflash': {}, 'mole': {}}}
            }
Esempio n. 2
0
 def test_api_incorrect_tag_update(self):
     Tag('laptop').save()
     with app.test_client() as c:
         rv = self.get_json(c, '/api/tag/laptop/')
         data = json.loads(rv.data)
         data['name'] = 'desktop'
         rv = self.put_json(c, '/api/tag/laptop/', data)
         print rv
         assert rv.status_code == 400
Esempio n. 3
0
 def test_api_incorrect_item_update(self):
     Item('fireflash').save()
     with app.test_client() as c:
         rv = self.get_json(c, '/api/item/fireflash/')
         data = json.loads(rv.data)
         data['name'] = 'hood'
         rv = self.put_json(c, '/api/item/fireflash/', data)
         print rv
         assert rv.status_code == 400
Esempio n. 4
0
 def test_api_create_tag(self):
     data = {
         'name': 'laptop'
     }
     with app.test_client() as c:
         rv = self.post_json(c, '/api/tag/', data)
         print rv
     laptop = Tag.find('laptop')
     assert laptop is not None
     assert laptop.name == 'laptop'
Esempio n. 5
0
    def test_api_set_variable(self):
        Item('fireflash').save()

        with app.test_client() as c:
            rv = self.get_json(c, '/api/item/fireflash/')
            data = json.loads(rv.data)
            data['vars'].append({'key':'hello', 'value':'world'})
            rv = self.put_json(c, '/api/item/fireflash/', data)
            print rv
            assert rv.status_code == 200
        fireflash = Item.find('fireflash')
        assert fireflash.variables['hello'] == 'world'
Esempio n. 6
0
    def test_api_add_tag(self):
        Item('fireflash').save()
        Tag('laptop').save()

        with app.test_client() as c:
            rv = self.get_json(c, '/api/item/fireflash/')
            data = json.loads(rv.data)
            data['tags'].append({'name':'laptop'})
            rv = self.put_json(c, '/api/item/fireflash/', data)
            print rv
            assert rv.status_code == 200
        laptop = Tag.find('laptop')
        assert laptop.items[0].name == 'fireflash'
Esempio n. 7
0
 def test_api_create_item(self):
     Tag('laptop').save()
     data = {
         'name': 'fireflash',
     }
     with app.test_client() as c:
         rv = self.post_json(c, '/api/tag/laptop/', data)
         print rv
         assert rv.status_code == 201
     fireflash = Item.find('fireflash')
     assert fireflash is not None
     assert fireflash.name == 'fireflash'
     assert len(fireflash.tags) == 1
     assert fireflash.tags[0].name == 'laptop'
Esempio n. 8
0
    def test_api_update_variable(self):
        fireflash = Item('fireflash')
        fireflash.set_variable('test', 'one')
        fireflash.save()

        with app.test_client() as c:
            rv = self.get_json(c, '/api/item/fireflash/')
            data = json.loads(rv.data)
            data['vars'] = [{'key':'test', 'value':'two'}]
            rv = self.put_json(c, '/api/item/fireflash/', data)
            print rv
            assert rv.status_code == 200
        fireflash = Item.find('fireflash')
        assert fireflash.variables['test'] == 'two'
Esempio n. 9
0
    def test_api_add_child(self):
        Item('home').save()
        Item('fireflash').save()

        with app.test_client() as c:
            rv = self.get_json(c, '/api/item/home/')
            data = json.loads(rv.data)
            data['children'].append({'name':'fireflash'})
            rv = self.put_json(c, '/api/item/home/', data)
            print rv
            assert rv.status_code == 200
        fireflash = Item.find('fireflash')
        home = Item.find('home')
        assert fireflash.parents[0].name == 'home'
        assert home.children[0].name == 'fireflash'
Esempio n. 10
0
    def test_ansible_inventory(self):
        fireflash = Item('fireflash')
        linux = Tag('linux')
        linux.set_variable('test', 'one')
        fireflash.add_to(linux)
        linux.save()

        with app.test_client() as c:
            rv = self.get_json(c, '/api/ansible_inventory/')
            data = json.loads(rv.data)
            assert rv.status_code == 200
            print data
            assert data == {
                'linux': {'hosts': ['fireflash']},
                '_meta': {'hostvars': {'fireflash': {'test': 'one'}}}
            }
Esempio n. 11
0
    def test_api_set_tag_variable(self):
        fireflash = Item('fireflash')
        laptop = Tag('laptop')
        laptop.set_variable('test', 'one')
        fireflash.add_to(laptop)
        laptop.save()

        with app.test_client() as c:
            rv = self.get_json(c, '/api/tag/laptop/')
            data = json.loads(rv.data)
            data['vars']['test']= 'two'
            rv = self.put_json(c, '/api/tag/laptop/', data)
            print rv
            assert rv.status_code == 200
        fireflash = Item.find('fireflash')
        laptop = Tag.find('laptop')
        assert laptop.variables['test'] == 'two'
        assert fireflash.get_all_variables()['test'] == 'two'