Beispiel #1
0
 def test_setGrants_no_matching_rule(self):
     repository = self.factory.makeGitRepository()
     [ref] = self.factory.makeGitRefs(repository=repository)
     self.factory.makeGitRule(repository=repository,
                              ref_pattern="refs/heads/*")
     other_repository = self.factory.makeGitRepository()
     self.factory.makeGitRule(repository=other_repository,
                              ref_pattern=ref.path)
     with person_logged_in(repository.owner):
         ref.setGrants([
             IGitNascentRuleGrant({
                 "grantee_type": GitGranteeType.REPOSITORY_OWNER,
                 "can_force_push": True,
             }),
         ], repository.owner)
     self.assertThat(
         list(repository.rules),
         MatchesListwise([
             MatchesStructure(repository=Equals(repository),
                              ref_pattern=Equals(ref.path),
                              grants=MatchesSetwise(
                                  MatchesStructure(
                                      grantee_type=Equals(
                                          GitGranteeType.REPOSITORY_OWNER),
                                      grantee=Is(None),
                                      can_create=Is(False),
                                      can_push=Is(False),
                                      can_force_push=Is(True)))),
             MatchesStructure(repository=Equals(repository),
                              ref_pattern=Equals("refs/heads/*"),
                              grants=MatchesSetwise()),
         ]))
Beispiel #2
0
 def test_getGrants(self):
     repository = self.factory.makeGitRepository()
     [ref] = self.factory.makeGitRefs(repository=repository)
     rule = self.factory.makeGitRule(repository=repository,
                                     ref_pattern=ref.path)
     grants = [
         self.factory.makeGitRuleGrant(rule=rule,
                                       can_create=True,
                                       can_force_push=True),
         self.factory.makeGitRuleGrant(rule=rule, can_push=True),
     ]
     wildcard_rule = self.factory.makeGitRule(repository=repository,
                                              ref_pattern="refs/heads/*")
     self.factory.makeGitRuleGrant(rule=wildcard_rule)
     self.assertThat(
         ref.getGrants(),
         MatchesSetwise(
             MatchesStructure(rule=Equals(rule),
                              grantee_type=Equals(GitGranteeType.PERSON),
                              grantee=Equals(grants[0].grantee),
                              can_create=Is(True),
                              can_push=Is(False),
                              can_force_push=Is(True)),
             MatchesStructure(rule=Equals(rule),
                              grantee_type=Equals(GitGranteeType.PERSON),
                              grantee=Equals(grants[1].grantee),
                              can_create=Is(False),
                              can_push=Is(True),
                              can_force_push=Is(False))))
Beispiel #3
0
 def test__interface_links_create_STATIC(self):
     origin = make_origin()
     Interface, Subnet = origin.Interface, origin.Subnet
     system_id = make_string_without_spaces()
     interface_data = {
         "system_id":
         system_id,
         "id":
         random.randint(0, 100),
         "name":
         make_string_without_spaces(),
         "type":
         InterfaceType.PHYSICAL.value,
         "links": [
             {
                 'id': random.randint(0, 100),
                 'mode': LinkMode.LINK_UP.value,
                 'subnet': {
                     'id': random.randint(0, 100),
                 }
             },
         ],
     }
     interface = Interface(interface_data)
     updated_data = dict(interface_data)
     link_id = random.randint(100, 200)
     subnet_id = random.randint(1, 100)
     updated_data['links'] = [{
         'id': link_id,
         'mode': LinkMode.STATIC.value,
         'ip_address': '192.168.122.10',
         'subnet': {
             'id': subnet_id,
         }
     }]
     Interface._handler.link_subnet.return_value = updated_data
     interface.links.create(LinkMode.STATIC,
                            subnet=Subnet(subnet_id),
                            ip_address='192.168.122.10',
                            default_gateway=True,
                            force=True)
     Interface._handler.link_subnet.assert_called_once_with(
         system_id=interface.node.system_id,
         id=interface.id,
         mode=LinkMode.STATIC.value,
         subnet=subnet_id,
         ip_address='192.168.122.10',
         force=True,
         default_gateway=True)
     self.assertThat(
         interface.links,
         MatchesSetwise(
             MatchesStructure(id=Equals(link_id),
                              mode=Equals(LinkMode.STATIC),
                              ip_address=Equals('192.168.122.10'),
                              subnet=MatchesAll(
                                  IsInstance(Subnet),
                                  MatchesStructure(id=Equals(subnet_id))))))