# coding=utf-8

import unittest

from loadimpact.clients import Client
from loadimpact.resources import Resource, TestConfig


class MockClient(Client):
    def _requests_request(self, method, *args, **kwargs):
        pass


class MockResource(Resource):
    fields = {}

    def __init__(self, client, field_cls, field_value=None):
        self.__class__.fields['field'] = field_cls
        super(MockResource, self).__init__(client, field=field_value)


class TestResourcesResource(unittest.TestCase):
    def test_getattr(self):
        pass

    def test_setattr(self):
        pass


class TestResourcesTestConfig(unittest.TestCase):
    def setUp(self):
        self.client = MockClient()

    def test_user_type_enums(self):
        self.assertEquals(TestConfig.SBU, 'sbu')
        self.assertEquals(TestConfig.VU, 'vu')

    def test_user_type_getter(self):
        c = TestConfig(self.client)
        self.assertEquals(c.user_type, TestConfig.SBU)

    def test_user_type_setter(self):
        c = TestConfig(self.client)
        c.user_type = TestConfig.VU
        self.assertEquals(c.user_type, TestConfig.VU)

    def test_user_type_setter_valueerror(self):
        c = TestConfig(self.client)
        def assign_bad_user_type():
            c.user_type = 'something bad'
        self.assertRaises(ValueError, assign_bad_user_type)

@@ -9,16 +9,28 @@
 =utf-8%0A%0A
+import json%0A
 import u
@@ -133,107 +133,1212 @@
 nfig
-%0A%0A%0Aclass MockClient(Client):%0A    def _requests_request(self, method, *args, **kwargs):%0A        pass
+, UserScenario%0A%0A%0Aclass MockRequestsResponse(object):%0A    def __init__(self, status_code=200, **kwargs):%0A        self.status_code = status_code%0A        self.kwargs = kwargs%0A        for k, v in kwargs.iteritems():%0A            setattr(self, k, v)%0A%0A    def json(self):%0A        d = self.kwargs%0A        d.update(%7B'status_code': self.status_code%7D)%0A        return d%0A%0A%0Aclass MockClient(Client):%0A    def __init__(self, **kwargs):%0A        super(MockClient, self).__init__()%0A        self.kwargs = kwargs%0A        self.last_request_method = None%0A        self.last_request_args = None%0A        self.last_request_kwargs = None%0A%0A    def _requests_request(self, method, *args, **kwargs):%0A        self.last_request_method = method%0A        self.last_request_args = args%0A        self.last_request_kwargs = kwargs%0A        if isinstance(kwargs.get('data'), str):%0A            self.last_request_kwargs%5B'data'%5D = json.loads(kwargs%5B'data'%5D)%0A        nkwargs = %7B%7D%0A        if kwargs.get('data'):%0A            if isinstance(kwargs%5B'data'%5D, dict):%0A                nkwargs = kwargs%5B'data'%5D%0A            elif isinstance(kwargs%5B'data'%5D, str):%0A                nkwargs = json.loads(kwargs%5B'data'%5D)%0A        return MockRequestsResponse(**nkwargs)
 %0A%0A%0Ac
@@ -1381,16 +1381,47 @@
 lds = %7B%7D
+%0A    resource_name = 'resource'
 %0A%0A    de
@@ -2486,8 +2486,989 @@
 r_type)%0A
+%0A%0Aclass TestResourcesUserScenario(unittest.TestCase):%0A    def setUp(self):%0A        self.client = MockClient()%0A%0A    def test_update_with_dict(self):%0A        name_change = 'Test User Scenario'%0A        user_scenario = UserScenario(self.client)%0A        user_scenario.update(%7B'name': name_change%7D)%0A%0A        self.assertEquals(self.client.last_request_method, 'put')%0A        self.assertEquals(self.client.last_request_kwargs%5B'data'%5D%5B'name'%5D,%0A                          name_change)%0A        self.assertEquals(user_scenario.name, name_change)%0A%0A    def test_update_with_attribute(self):%0A        name_change = 'Test User Scenario'%0A        user_scenario = UserScenario(self.client)%0A        user_scenario.name = name_change%0A        user_scenario.update()%0A%0A        self.assertEquals(self.client.last_request_method, 'put')%0A        self.assertEquals(self.client.last_request_kwargs%5B'data'%5D%5B'name'%5D,%0A                          name_change)%0A        self.assertEquals(user_scenario.name, name_change)%0A

Add UserScenario.update test cases.