import pytest
import os
import shutil
import tngsdk.project.workspace as workspace
from tngsdk.project.workspace import Workspace
from tngsdk.project.project import Project


class TestProjectUnit:

    # create and return a temporary workspace 'test-ws'
    @pytest.fixture(scope='module')
    def workspace(self):
        # start clean without workspace
        if os.path.isdir('test-ws'):
            shutil.rmtree('test-ws')

        args = workspace.parse_args_workspace([
            '-w', 'test-ws',
            '--debug'
        ])
        workspace.init_workspace(args)
        assert os.path.isdir('test-ws')
        yield 'test-ws'
        shutil.rmtree('test-ws')

    # test descriptors of project 'example-project'
    def test_example_project_descriptors(self, workspace):
        ws = Workspace.load_workspace(workspace)
        example_project = Project.load_project('example-project', workspace=ws)
        example_project.status()

        vnfds = example_project.get_vnfds()
        assert vnfds == ['tango_vnfd0.yml']

        nsds = example_project.get_nsds()
        assert nsds == ['tango_nsd.yml']
