Repository: Azure/msrest-for-python

Issue:
v0.4.12 breaks mixed dict with enum if model-as-string=true
This breaks:
``` python
        async_security_rule = self.network_client.security_rules.create_or_update(
            self.group_name,
            security_group_name,
            new_security_rule_name,
            {
                    'access':azure.mgmt.network.models.SecurityRuleAccess.allow,
                    'description':'New Test security rule',
                    'destination_address_prefix':'*',
                    'destination_port_range':'123-3500',
                    'direction':azure.mgmt.network.models.SecurityRuleDirection.outbound,
                    'priority':400,
                    'protocol':azure.mgmt.network.models.SecurityRuleProtocol.tcp,
                    'source_address_prefix':'*',
                    'source_port_range':'655',
            }
        )
``` 

Discussion:

Patch:
diff --git a/msrest/serialization.py b/msrest/serialization.py
index 063f2e6..a3d50cd 100644
--- a/msrest/serialization.py
+++ b/msrest/serialization.py
@@ -1200,6 +1200,12 @@ class Deserializer(object):
         :param str data: response string to be deserialized.
         :rtype: str or unicode
         """
+        # We might be here because we have an enum modeled as string,
+        # and we try to deserialize a partial dict with enum inside
+        if isinstance(data, Enum):
+            return data
+
+        # Consider this is real string
         try:
             if isinstance(data, unicode):
                 return data


Test patch:
diff --git a/tests/test_serialization.py b/tests/test_serialization.py
index 787a086..10fb82f 100644
--- a/tests/test_serialization.py
+++ b/tests/test_serialization.py
@@ -353,10 +353,10 @@ class TestRuntimeSerialized(unittest.TestCase):
         class TestEnum(Enum):
             val = "Value"
 
-        t = test_obj
+        t = test_obj()
         t.abc = TestEnum.val
 
-        serialized = self.s._serialize(test_obj)
+        serialized = self.s._serialize(t)
         expected = {
             "ABC": "Value"
         }
@@ -374,6 +374,31 @@ class TestRuntimeSerialized(unittest.TestCase):
         with self.assertRaises(SerializationError):
             serializer._serialize(t)
 
+        serializer = Serializer({
+            'TestEnumObj': test_obj,
+            'TestEnum': TestEnum
+        })
+        serialized = serializer.body({
+            'abc': TestEnum.val
+        }, 'TestEnumObj')
+        expected = {
+            'ABC': 'Value'
+        }
+        self.assertEqual(expected, serialized)
+
+        # model-as-string=True
+        test_obj._attribute_map = {
+            "abc":{"key":"ABC", "type":"str"}
+        }
+        serialized = serializer.body({
+            'abc': TestEnum.val
+        }, 'TestEnumObj')
+        expected = {
+            'ABC': 'Value'
+        }
+        self.assertEqual(expected, serialized)
+
+
     def test_attr_none(self):
         """
         Test serializing an object with None attributes.