Esempio n. 1
0
    def publish_obj(self, obj, previous_obj=None):
        """
        Publish a Program to the marketing site.

        Arguments:
            obj (Program): Program instance to be published.

        Keyword Arguments:
            previous_obj (Program): Previous state of the program. Inspected to
                determine if publication is necessary. May not exist if the program
                is being saved for the first time.
        """
        types_to_publish = {
            'XSeries',
            'MicroMasters',
            'Professional Certificate',
            'Masters',
        }

        if obj.type.name in types_to_publish:
            node_data = self.serialize_obj(obj)

            changed = False
            node_id = None
            if previous_obj:
                node_id = self.node_id(
                    obj)  # confirm that it already exists on marketing side
            if not node_id:
                node_id = self.create_node(node_data)
                changed = True
            else:
                trigger_fields = (
                    'marketing_slug',
                    'status',
                    'title',
                    'type',
                )

                if any(
                        getattr(obj, field) != getattr(previous_obj, field)
                        for field in trigger_fields):
                    # Drupal does not allow modification of the UUID field.
                    node_data.pop('uuid', None)

                    self.edit_node(node_id, node_data)
                    changed = True

            if changed:
                self.get_and_delete_alias(uslugify(obj.title))
                self.update_node_alias(obj, node_id, previous_obj)
Esempio n. 2
0
 def test_uslugify(self, string, expected):
     output = utils.uslugify(string)
     self.assertEqual(output, expected)