def test_from_json(self):
        """
        Test from_json() class method
          - Directly from JSON
          - From to_json() method of existing Endpoint.
        """
        ep_id = "aabbccddeeff112233"
        expected = {"state": "active",
                    "name": "caliaabbccddeef",
                    "mac": "11-22-33-44-55-66",
                    "container:if_name": "eth0",
                    "profile_id": "TEST23",
                    "ipv4_nets": ["192.168.3.2/32", "10.3.4.23/32"],
                    "ipv6_nets": ["fd20::4:2:1/128"],
                    "ipv4_gateway": "10.3.4.2",
                    "ipv6_gateway": "2001:2:4a::1"}
        endpoint = Endpoint.from_json(ep_id, json.dumps(expected))
        assert_equal(endpoint.state, "active")
        assert_equal(endpoint.ep_id, ep_id)
        assert_equal(endpoint.mac, "11-22-33-44-55-66")
        assert_equal(endpoint.profile_id, "TEST23")
        assert_equal(endpoint.ipv4_gateway, IPAddress("10.3.4.2"))
        assert_equal(endpoint.ipv6_gateway, IPAddress("2001:2:4a::1"))
        assert_set_equal(endpoint.ipv4_nets, {IPNetwork("192.168.3.2/32"),
                                              IPNetwork("10.3.4.23/32")})
        assert_set_equal(endpoint.ipv6_nets, {IPNetwork("fd20::4:2:1/128")})

        endpoint2 = Endpoint.from_json(ep_id, endpoint.to_json())
        assert_equal(endpoint.state, endpoint2.state)
        assert_equal(endpoint.ep_id, endpoint2.ep_id)
        assert_equal(endpoint.mac, endpoint2.mac)
        assert_equal(endpoint.profile_id, endpoint2.profile_id)
        assert_equal(endpoint.ipv4_gateway, endpoint2.ipv4_gateway)
        assert_equal(endpoint.ipv6_gateway, endpoint2.ipv6_gateway)
        assert_set_equal(endpoint.ipv4_nets, endpoint2.ipv4_nets)
        assert_set_equal(endpoint.ipv6_nets, endpoint2.ipv6_nets)
    def test_remove_workload_from_profile(self):
        """
        Test remove_workload_from_profile() when the workload exists.
        """
        ep = Endpoint.from_json(EP_12.ep_id, EP_12.to_json())

        def mock_read(path):
            if path == TEST_CONT_ENDPOINT_PATH:
                return mock_read_2_ep_for_cont(path)
            elif path == TEST_CONT_ENDPOINT_PATH + ep.ep_id:
                return mock_read_for_endpoint(ep)(path)
            else:
                assert_true(False)

        self.etcd_client.read.side_effect = mock_read
        self.datastore.remove_workload_from_profile(TEST_HOST, TEST_CONT_ID)
        ep.profile_id = None
        expected_write_json = ep.to_json()
        self.etcd_client.write.assert_called_once_with(TEST_ENDPOINT_PATH,
                                                       expected_write_json)