import pytest

from micromanager.resources import Resource
from micromanager.resources import BQDataset
from micromanager.resources import Bucket
from micromanager.resources import SQLInstance

test_cases = [
    (
        {'resource_kind': 'storage#bucket'},
        Bucket
    ),
    (
        {'resource_kind': 'sql#instance'},
        SQLInstance
    ),
    (
        {'resource_kind': 'bigquery#dataset'},
        BQDataset
    )
]


@pytest.mark.parametrize(
    "input,expected",
    test_cases,
    ids=[cls.__name__ for (_, cls) in test_cases])
def test_resource_factory(input, expected):
        r = Resource.factory(input)
        assert r.__class__ == expected

def test_resource_factory_invalid():
        with pytest.raises(AssertionError):
            r = Resource.factory({})

import pytest

from .util import load_test_data
from .util import discovery_cache

from .mock import HttpMockSequenceEx

from googleapiclient.http import HttpMockSequence

from micromanager.resources import Resource
from micromanager.resources.gcp import GcpBigqueryDataset
from micromanager.resources.gcp import GcpComputeInstance
from micromanager.resources.gcp import GcpSqlInstance
from micromanager.resources.gcp import GcpStorageBucket
from micromanager.resources.gcp import GcpStorageBucketIamPolicy

test_cases = [
    (
        {'resource_type': 'bigquery.datasets', 'resource_name': '', 'project_id': ''},
        GcpBigqueryDataset,
        'gcp.bigquery.datasets'
    ),
    (
        {'resource_type': 'compute.instances', 'resource_name': '', 'project_id': ''},
        GcpComputeInstance,
        'gcp.compute.instances'
    ),
    (
        {'resource_type': 'sqladmin.instances', 'resource_name': '', 'project_id': ''},
        GcpSqlInstance,
        'gcp.sqladmin.instances'
    ),
    (
        {'resource_type': 'storage.buckets', 'resource_name': '', 'project_id': ''},
        GcpStorageBucket,
        'gcp.storage.buckets'
    ),
    (
        {'resource_type': 'storage.buckets.iam', 'resource_name': '', 'project_id': ''},
        GcpStorageBucketIamPolicy,
        'gcp.storage.buckets.iam'
    )
]


@pytest.mark.parametrize(
    "input,cls,rtype",
    test_cases,
    ids=[cls.__name__ for (_, cls, _) in test_cases])
def test_gcp_resource_factory(input, cls, rtype):
    r = Resource.factory("gcp", input)
    assert r.__class__ == cls
    assert r.type() == rtype

def test_gcp_resource_factory_invalid():
    with pytest.raises(AssertionError):
        r = Resource.factory('gcp', {})

Update tests after lots of work on Resources
Update tests after lots of work on Resources

  import pytest
  
+ from .util import load_test_data
+ from .util import discovery_cache
+ 
+ from .mock import HttpMockSequenceEx
+ 
+ from googleapiclient.http import HttpMockSequence
+ 
  from micromanager.resources import Resource
- from micromanager.resources import BQDataset
+ from micromanager.resources.gcp import GcpBigqueryDataset
- from micromanager.resources import Bucket
+ from micromanager.resources.gcp import GcpComputeInstance
- from micromanager.resources import SQLInstance
+ from micromanager.resources.gcp import GcpSqlInstance
+ from micromanager.resources.gcp import GcpStorageBucket
+ from micromanager.resources.gcp import GcpStorageBucketIamPolicy
  
  test_cases = [
      (
-         {'resource_kind': 'storage#bucket'},
-         Bucket
+         {'resource_type': 'bigquery.datasets', 'resource_name': '', 'project_id': ''},
+         GcpBigqueryDataset,
+         'gcp.bigquery.datasets'
      ),
      (
-         {'resource_kind': 'sql#instance'},
-         SQLInstance
+         {'resource_type': 'compute.instances', 'resource_name': '', 'project_id': ''},
+         GcpComputeInstance,
+         'gcp.compute.instances'
      ),
      (
-         {'resource_kind': 'bigquery#dataset'},
-         BQDataset
+         {'resource_type': 'sqladmin.instances', 'resource_name': '', 'project_id': ''},
+         GcpSqlInstance,
+         'gcp.sqladmin.instances'
+     ),
+     (
+         {'resource_type': 'storage.buckets', 'resource_name': '', 'project_id': ''},
+         GcpStorageBucket,
+         'gcp.storage.buckets'
+     ),
+     (
+         {'resource_type': 'storage.buckets.iam', 'resource_name': '', 'project_id': ''},
+         GcpStorageBucketIamPolicy,
+         'gcp.storage.buckets.iam'
      )
  ]
  
  
  @pytest.mark.parametrize(
-     "input,expected",
+     "input,cls,rtype",
      test_cases,
-     ids=[cls.__name__ for (_, cls) in test_cases])
+     ids=[cls.__name__ for (_, cls, _) in test_cases])
- def test_resource_factory(input, expected):
+ def test_gcp_resource_factory(input, cls, rtype):
-         r = Resource.factory(input)
+     r = Resource.factory("gcp", input)
-         assert r.__class__ == expected
+     assert r.__class__ == cls
+     assert r.type() == rtype
  
- def test_resource_factory_invalid():
+ def test_gcp_resource_factory_invalid():
-         with pytest.raises(AssertionError):
+     with pytest.raises(AssertionError):
-             r = Resource.factory({})
+         r = Resource.factory('gcp', {})
  
Update tests after lots of work on Resources
## Code Before:
import pytest

from micromanager.resources import Resource
from micromanager.resources import BQDataset
from micromanager.resources import Bucket
from micromanager.resources import SQLInstance

test_cases = [
    (
        {'resource_kind': 'storage#bucket'},
        Bucket
    ),
    (
        {'resource_kind': 'sql#instance'},
        SQLInstance
    ),
    (
        {'resource_kind': 'bigquery#dataset'},
        BQDataset
    )
]


@pytest.mark.parametrize(
    "input,expected",
    test_cases,
    ids=[cls.__name__ for (_, cls) in test_cases])
def test_resource_factory(input, expected):
        r = Resource.factory(input)
        assert r.__class__ == expected

def test_resource_factory_invalid():
        with pytest.raises(AssertionError):
            r = Resource.factory({})

## Instruction:
Update tests after lots of work on Resources
## Code After:
import pytest

from .util import load_test_data
from .util import discovery_cache

from .mock import HttpMockSequenceEx

from googleapiclient.http import HttpMockSequence

from micromanager.resources import Resource
from micromanager.resources.gcp import GcpBigqueryDataset
from micromanager.resources.gcp import GcpComputeInstance
from micromanager.resources.gcp import GcpSqlInstance
from micromanager.resources.gcp import GcpStorageBucket
from micromanager.resources.gcp import GcpStorageBucketIamPolicy

test_cases = [
    (
        {'resource_type': 'bigquery.datasets', 'resource_name': '', 'project_id': ''},
        GcpBigqueryDataset,
        'gcp.bigquery.datasets'
    ),
    (
        {'resource_type': 'compute.instances', 'resource_name': '', 'project_id': ''},
        GcpComputeInstance,
        'gcp.compute.instances'
    ),
    (
        {'resource_type': 'sqladmin.instances', 'resource_name': '', 'project_id': ''},
        GcpSqlInstance,
        'gcp.sqladmin.instances'
    ),
    (
        {'resource_type': 'storage.buckets', 'resource_name': '', 'project_id': ''},
        GcpStorageBucket,
        'gcp.storage.buckets'
    ),
    (
        {'resource_type': 'storage.buckets.iam', 'resource_name': '', 'project_id': ''},
        GcpStorageBucketIamPolicy,
        'gcp.storage.buckets.iam'
    )
]


@pytest.mark.parametrize(
    "input,cls,rtype",
    test_cases,
    ids=[cls.__name__ for (_, cls, _) in test_cases])
def test_gcp_resource_factory(input, cls, rtype):
    r = Resource.factory("gcp", input)
    assert r.__class__ == cls
    assert r.type() == rtype

def test_gcp_resource_factory_invalid():
    with pytest.raises(AssertionError):
        r = Resource.factory('gcp', {})
