def test_port_case_change(self):
        # Make a case-only rename of a port (port-A1-subport)
        Port.update([
            {
                "variants": ["universal"],
                "portdir": "categoryA\/port-A1",
                "description": "This is port A1 of categoryA",
                "homepage": "http:\/\/portA1.website\/",
                "platforms": "darwin",
                "name": "PORT-A1-SUBPORT",
                "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"],
                "long_description": "Just a test port written to test something.",
                "license": "MIT",
                "maintainers": [{
                    "email": {
                        "domain": "email.com",
                        "name": "user"
                    },
                    "github": "user"
                }],
                "categories": ["categoryA"],
                "version": "1.0.0",
                "revision": "0"
            }
        ])

        # <get> query for port-A1-subport should not fail
        port_a1_subport = Port.objects.get(name__iexact='port-A1-subport')

        # the name of the port should be updated to PORT-A1-SUBPORT
        updated_name = "PORT-A1-SUBPORT"
        self.assertEquals(updated_name, port_a1_subport.name)
Exemplo n.º 2
0
 def handle(self, *args, **options):
     try:
         Port.update(options['path'])
     except FileNotFoundError:
         raise CommandError(
             '"{}" not found. Make sure "{}" is a valid JSON file and is in the root of the project'
             .format(options['path'], options['path']))
 def test_added_back(self):
     Port.mark_deleted({
         'categoryA/port-A1': {
             'port-A1'
         }
     })
     Port.update([
         {
             "variants": ["universal"],
             "portdir": "categoryA\/port-A1",
             "depends_fetch": ["bin:port-A4:port-A4"],
             "description": "This is port A1 of categoryA",
             "homepage": "http:\/\/portA1.website\/",
             "epoch": "0",
             "platforms": "darwin",
             "name": "port-A1-subport",
             "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"],
             "long_description": "Just a test port written to test something.",
             "license": "MIT",
             "maintainers": [{
                 "email": {
                     "domain": "email.com",
                     "name": "user"
                 },
                 "github": "user"
             }],
             "categories": ["categoryA"],
             "version": "1.0.0",
             "revision": "0"
         }
     ])
     port_status = Port.objects.get(name='port-A1-subport').active
     self.assertEquals(port_status, True)
Exemplo n.º 4
0
 def test_updates(self):
     updated_port = [{
         "name": "port-A5",
         "version": "1.0.0",
         "portdir": "categoryA/port-A5",
         "depends_extract": ["bin:port-C1:port-C1"],
         "depends_run": ["port:port-A1"],
     }]
     Port.update(updated_port)
     dependencies = Dependency.objects.filter(
         port_name__name__iexact='port-A5')
     self.assertEquals(
         dependencies.get(type='run').dependencies.all().count(), 1)
     self.assertEquals(
         dependencies.get(type='run').dependencies.all().first().name,
         'port-A1')
     self.assertEquals(dependencies.count(), 2)
Exemplo n.º 5
0
    def handle(self, *args, **options):
        # Fetch the latest version of PortIndex.json and open the file
        data = Port.PortIndexUpdateHandler().sync_and_open_file()

        # If no argument is provided, use the commit-hash from JSON file:
        if options['new_commit'] is None:
            new_commit = data['info']['commit']
        # If argument is provided
        else:
            new_commit = options['new_commit']

        # If no argument is provided, options['old_commit'] will default to None
        # The code will then use the commit from last update which is stored in the database
        updated_portdirs = git_update.get_list_of_changed_ports(
            new_commit, options['old_commit'])

        # Generate a dictionary containing all the portdirs and initialise their values
        # with empty sets. The set would contain the ports under that portdir.
        dict_of_portdirs_with_ports = {}
        for portdir in updated_portdirs:
            dict_of_portdirs_with_ports[portdir] = set()

        # Using the received set of updated portdirs, find corresponding JSON objects for all ports under
        # that portdir.
        ports_to_be_updated_json = []
        for port in data['ports']:
            portdir = port['portdir'].lower()
            portname = port['name'].lower()
            if portdir in updated_portdirs:
                ports_to_be_updated_json.append(port)
                dict_of_portdirs_with_ports[portdir].add(portname)

        # Mark deleted ports
        Port.mark_deleted(dict_of_portdirs_with_ports)

        # Run updates
        Port.update(ports_to_be_updated_json)

        # Write the commit hash into database
        LastPortIndexUpdate.update_or_create_first_object(
            data['info']['commit'])
Exemplo n.º 6
0
    def handle(self, *args, **options):
        # Fetch the latest version of PortIndex.json and open the file
        data = Port.PortIndexUpdateHandler().sync_and_open_file()

        # If no argument is provided, use the commit-hash from JSON file:
        if options['new_commit'] is None:
            new_commit = data['info']['commit']
        # If argument is provided
        else:
            new_commit = options['new_commit']

        # If no argument is provided, options['old_commit'] will default to None
        # The code will then use the commit from last update which is stored in the database
        updated_portdirs = git_update.get_list_of_changed_ports(
            new_commit, options['old_commit'])

        # Using the received list of port names, find related JSON objects
        ports_to_be_updated_json = []
        found_ports_tree = {}
        for port in data['ports']:
            portdir = port['portdir'].lower()
            portname = port['name'].lower()
            if portdir in updated_portdirs:
                ports_to_be_updated_json.append(port)
                if found_ports_tree.get(portdir) is None:
                    found_ports_tree[portdir] = {}
                found_ports_tree[portdir][portname] = True

        # Mark deleted ports
        Port.mark_deleted(found_ports_tree)

        # Run updates
        Port.update(ports_to_be_updated_json)

        # Write the commit hash into database
        LastPortIndexUpdate.update_or_create_first_object(
            data['info']['commit'])
Exemplo n.º 7
0
 def test_maintainers_updated(self):
     updated_port = [{
         "name":
         "port-A1",
         "portdir":
         "categoryA/port-A1",
         "version":
         "1.0.0",
         "maintainers": [{
             "email": {
                 "domain": "email.com",
                 "name": "new_user"
             },
             "github": "new_user"
         }, {
             "github": "user"
         }]
     }]
     Port.update(updated_port)
     port = Port.objects.get(name="port-A1")
     self.assertEquals(port.maintainers.count(), 2)
     self.assertEquals(Maintainer.objects.all().count(), 7)
     self.assertEquals(
         Port.objects.get(name="port-A3-diff").maintainers.count(), 1)
Exemplo n.º 8
0
    def test_moved(self):
        Port.update([{
            "variants": ["universal"],
            "portdir":
            "categoryA/port-A1",
            "depends_fetch": ["bin:port-A4:port-A4"],
            "description":
            "This is port A1 of categoryA",
            "homepage":
            "http:\/\/portA1.website\/",
            "epoch":
            "0",
            "platforms":
            "darwin",
            "name":
            "port-A2-subport",
            "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"],
            "long_description":
            "Just a test port written to test something.",
            "license":
            "MIT",
            "maintainers": [{
                "email": {
                    "domain": "email.com",
                    "name": "user"
                },
                "github": "user"
            }],
            "categories": ["categoryA"],
            "version":
            "1.0.0",
            "revision":
            "0"
        }, {
            "variants": ["universal"],
            "portdir":
            "categoryA/port-A1",
            "depends_fetch": ["bin:port-A4:port-A4"],
            "description":
            "This is port A1 of categoryA",
            "homepage":
            "http:\/\/portA1.website\/",
            "epoch":
            "0",
            "platforms":
            "darwin",
            "name":
            "port-A3-subport",
            "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"],
            "long_description":
            "Just a test port written to test something.",
            "license":
            "MIT",
            "maintainers": [{
                "email": {
                    "domain": "email.com",
                    "name": "user"
                },
                "github": "user"
            }],
            "categories": ["categoryA"],
            "version":
            "1.0.0",
            "revision":
            "0"
        }])

        port_status_subport1 = Port.objects.get(name='port-A1-subport').active
        port_status_subport2 = Port.objects.get(name='port-A2-subport').active
        port_status_subport3 = Port.objects.get(name='port-A3-subport').active
        self.assertEquals(port_status_subport1, True)
        self.assertEquals(port_status_subport2, True)
        self.assertEquals(port_status_subport3, True)

        # Entire categoryA/port-A1 portdir is removed, but the subports move to other directory
        # All ports under category/port-A1 would be deleted.
        Port.mark_deleted({'categoryA/port-A1': {}})

        port_status_subport1 = Port.objects.get(name='port-A1-subport').active
        port_status_subport2 = Port.objects.get(name='port-A2-subport').active
        port_status_subport3 = Port.objects.get(name='port-A3-subport').active
        self.assertEquals(port_status_subport1, False)
        self.assertEquals(port_status_subport2, False)
        self.assertEquals(port_status_subport3, False)

        # The moved ports would be found at the new location and will be appended to the list of JSON objects
        Port.update([{
            "variants": ["universal"],
            "portdir":
            "categoryTemp/newPorts",
            "depends_fetch": ["bin:port-A4:port-A4"],
            "description":
            "This is port A1 of categoryA",
            "homepage":
            "http:\/\/portA1.website\/",
            "epoch":
            "0",
            "platforms":
            "darwin",
            "name":
            "port-A2-subport",
            "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"],
            "long_description":
            "Just a test port written to test something.",
            "license":
            "MIT",
            "maintainers": [{
                "email": {
                    "domain": "email.com",
                    "name": "user"
                },
                "github": "user"
            }],
            "categories": ["categoryA"],
            "version":
            "1.0.0",
            "revision":
            "0"
        }, {
            "variants": ["universal"],
            "portdir":
            "categoryTemp/newPorts",
            "depends_fetch": ["bin:port-A4:port-A4"],
            "description":
            "This is port A1 of categoryA",
            "homepage":
            "http:\/\/portA1.website\/",
            "epoch":
            "0",
            "platforms":
            "darwin",
            "name":
            "port-A3-subport",
            "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"],
            "long_description":
            "Just a test port written to test something.",
            "license":
            "MIT",
            "maintainers": [{
                "email": {
                    "domain": "email.com",
                    "name": "user"
                },
                "github": "user"
            }],
            "categories": ["categoryA"],
            "version":
            "1.0.0",
            "revision":
            "0"
        }])

        port_status_subport2 = Port.objects.get(name='port-A2-subport').active
        port_status_subport3 = Port.objects.get(name='port-A3-subport').active
        self.assertEquals(port_status_subport2, True)
        self.assertEquals(port_status_subport3, True)