from pnc_cli import utils
from pnc_cli import productversions
from pnc_cli.swagger_client.apis import ProductversionsApi
from test import testutils


versions_api = ProductversionsApi(utils.get_api_client())


def create_product_version():
    return versions_api.create_new_product_version(
            body=productversions.create_product_version_object(
            product_id=1,
            version=testutils.gen_random_version())).content


def test_get_all():
    create_product_version()
    product_versions = versions_api.get_all().content
    assert product_versions is not None


def test_create_product_version():
    created_version = create_product_version()
    product_versions = [v.version for v in versions_api.get_all().content]
    assert created_version.version in product_versions


def test_get_product_version():
    created_version = create_product_version()
    retrieved_version = versions_api.get_specific(id=created_version.id).content
    assert created_version.to_dict() == retrieved_version.to_dict()


#currently unable to update build_configuration_ids
def test_update_product_version():
    created_version = create_product_version()
    created_version.build_configuration_ids = [1, 2, 3]
    versions_api.update(id=created_version.id, body=created_version)
    updated = versions_api.get_specific(id=created_version.id).content
    assert updated.to_dict() == created_version.to_dict()


def test_version_exists():
    created_version = create_product_version()
    assert productversions.version_exists(created_version.id)


@@ -1,28 +1,42 @@
+import pytest%0A
 from pnc_cli import utils%0Afr
@@ -220,27 +220,49 @@
 ))%0A%0A
-%0Adef create_product
+@pytest.fixture(scope='function')%0Adef new
 _ver
@@ -277,14 +277,17 @@
     
-return
+version =
  ver
@@ -479,56 +479,57 @@
 ent%0A
-%0A%0Adef test_get_all():%0A    create_product
+    return version%0A%0A%0Adef test_get_all(new
 _version
 ()%0A 
@@ -516,34 +516,34 @@
 _all(new_version
-(
 )
+:
 %0A    product_ver
@@ -659,55 +659,19 @@
 ion(
-):%0A    created_version = create_product
+new
 _version
 ()%0A 
@@ -662,26 +662,26 @@
 (new_version
-(
 )
+:
 %0A    product
@@ -747,39 +747,35 @@
 ent%5D%0A    assert 
-created
+new
 _version.version
@@ -830,55 +830,19 @@
 ion(
-):%0A    created_version = create_product
+new
 _version
 ()%0A 
@@ -833,26 +833,26 @@
 (new_version
-(
 )
+:
 %0A    retriev
@@ -885,39 +885,35 @@
 get_specific(id=
-created
+new
 _version.id).con
@@ -928,23 +928,19 @@
  assert 
-created
+new
 _version
@@ -1071,55 +1071,19 @@
 ion(
-):%0A    created_version = create_product
+new
 _version
 ()%0A 
@@ -1082,22 +1082,18 @@
 sion
-(
 )
+:
 %0A    
-created
+new
 _ver
@@ -1156,31 +1156,27 @@
 i.update(id=
-created
+new
 _version.id,
@@ -1181,23 +1181,19 @@
 d, body=
-created
+new
 _version
@@ -1237,23 +1237,19 @@
 ific(id=
-created
+new
 _version
@@ -1293,23 +1293,19 @@
 ct() == 
-created
+new
 _version
@@ -1345,55 +1345,19 @@
 sts(
-):%0A    created_version = create_product
+new
 _version
 ()%0A 
@@ -1352,18 +1352,18 @@
 _version
-(
 )
+:
 %0A    ass
@@ -1401,15 +1401,11 @@
 sts(
-created
+new
 _ver

convert to use test fixtures