def test_rules(self):
        """
        Create a detailed set of rules, convert from and to json and compare
        the results.
        """
        # Convert a JSON blob into a Rules object.
        rules = Rules.from_json(RULES_JSON)

        # Convert the Rules object to JSON and then back again.
        new_json = rules.to_json()
        new_rules = Rules.from_json(new_json)

        # Compare the two rules objects.
        assert_equal(rules.id, new_rules.id)
        assert_equal(rules.inbound_rules,
                     new_rules.inbound_rules)
        assert_equal(rules.outbound_rules,
                     new_rules.outbound_rules)

        # Check the values of one of the inbound Rule objects.
        assert_equal(len(rules.inbound_rules), 4)
        inbound_rule = rules.inbound_rules[3]
        assert_equal(inbound_rule["protocol"], "udp")
        assert_equal(inbound_rule["src_tag"], "SRC_TAG")
        assert_equal(inbound_rule["src_ports"], [10, 20,30])
        assert_equal(inbound_rule["src_net"], IPNetwork("192.168.77.0/30"))
        assert_equal(inbound_rule["dst_tag"], "DST_TAG")
        assert_equal(inbound_rule["dst_net"], IPNetwork("1.2.3.4"))
        assert_equal(inbound_rule["icmp_type"], 30)
        assert_equal(inbound_rule["action"], "deny")
 def test_create_profile(self):
     """
     Test create_profile()
     """
     self.datastore.create_profile("TEST")
     rules = Rules(id="TEST",
                   inbound_rules=[Rule(action="allow",
                                       src_tag="TEST"),
                                  Rule(action="deny")],
                   outbound_rules=[Rule(action="allow")])
     expected_calls = [call(TEST_PROFILE_PATH + "tags", '["TEST"]'),
                       call(TEST_PROFILE_PATH + "rules", rules.to_json())]
     self.etcd_client.write.assert_has_calls(expected_calls, any_order=True)