Beispiel #1
0
    def test_get_works(self):
        ruleid = u'2'
        rules = [{ u'id': 1, u'FAKE': u'fst' },
                 { u'id': 2, u'FAKE': u'snd' },
                 { u'id': 4, u'FAKE': u'lst' } ]
        sg = doubles.make(self.mox, doubles.SecurityGroup,
                          id=u'42', name='Test SG',
                          rules=rules, tenant_id='PID')

        self.fake_client_set.compute.security_groups.get(sg.id).AndReturn(sg)
        fw_rules.auth.assert_admin_or_project_user('PID', eperm_status=404)

        fw_rules._fw_rule_dict_to_view(rules[1]).AndReturn('REPLY')

        self.mox.ReplayAll()
        rv = self.client.get('/v1/fw-rule-sets/%s/rules/%s' % (sg.id, ruleid))
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, 'REPLY')
Beispiel #2
0
    def test_list_works(self):
        sg = doubles.make(self.mox, doubles.SecurityGroup,
                          id=u'42', name='Test SG', tenant_id='TENANT',
                          rules=['RULE1', 'RULE2'])

        self.fake_client_set.compute.security_groups.get(sg.id).AndReturn(sg)
        fw_rules.auth.assert_admin_or_project_user('TENANT', eperm_status=404)
        fw_rules._fw_rule_dict_to_view('RULE1').AndReturn('REPLY1')
        fw_rules._fw_rule_dict_to_view('RULE2').AndReturn('REPLY2')

        expected = {
            'collection': {
                'name': 'rules',
                'size': 2,
                'parent-href': '/v1/fw-rule-sets/%s' % sg.id
            },
            'rules': [ 'REPLY1', 'REPLY2' ]
        }

        self.mox.ReplayAll()
        rv = self.client.get('/v1/fw-rule-sets/%s/rules/' % sg.id)
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, expected)
Beispiel #3
0
 def test_rule_dict_to_view_works(self):
     self.mox.ReplayAll()
     with self.app.test_request_context():
         res = fw_rules._fw_rule_dict_to_view(self.to_view)
     self.assertEquals(res, self.expected)