Beispiel #1
0
 def test_edit_node(self):
     self.mock_api_client(200)
     self.mock_node_edit(200)
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     publisher._edit_node(self.api_client, self.node_id, publish_data)  # pylint: disable=protected-access
     self.assert_responses_call_count(5)
Beispiel #2
0
 def test_get_node_id(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     publisher = MarketingSitePublisher()
     node_id = publisher._get_node_id(self.api_client, self.program.uuid)  # pylint: disable=protected-access
     self.assert_responses_call_count(5)
     self.assertEqual(node_id, self.node_id)
Beispiel #3
0
 def test_publish_delete_program(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_delete(204)
     publisher = MarketingSitePublisher()
     publisher.delete_program(self.program)
     self.assert_responses_call_count(6)
 def test_publish_delete_program(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_delete(204)
     publisher = MarketingSitePublisher()
     publisher.delete_program(self.program)
     self.assert_responses_call_count(5)
Beispiel #5
0
 def test_publish_program_no_credential(self):
     self.program.partner.marketing_site_api_password = None
     self.program.partner.marketing_site_api_username = None
     publisher = MarketingSitePublisher()
     with self.assertRaises(ProgramPublisherException):
         publisher.publish_program(self.program)
         self.assert_responses_call_count(0)
 def test_create_node_failed(self):
     self.mock_api_client(200)
     self.mock_node_create({}, 500)
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     with self.assertRaises(ProgramPublisherException):
         publisher._create_node(self.api_client, publish_data)  # pylint: disable=protected-access
Beispiel #7
0
 def test_create_node(self):
     self.mock_api_client(200)
     self.mock_node_create(self.expected_node, 201)
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     data = publisher._create_node(self.api_client, publish_data)  # pylint: disable=protected-access
     self.assertEqual(data, self.expected_node['id'])
 def test_edit_node(self):
     self.mock_api_client(200)
     self.mock_node_edit(200)
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     publisher._edit_node(self.api_client, self.nid, publish_data)  # pylint: disable=protected-access
     self.assert_responses_call_count(4)
 def test_get_node_id(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     publisher = MarketingSitePublisher()
     node_id = publisher._get_node_id(self.api_client, self.program.uuid)  # pylint: disable=protected-access
     self.assert_responses_call_count(4)
     self.assertEqual(node_id, self.nid)
Beispiel #10
0
 def test_create_node_failed(self):
     self.mock_api_client(200)
     self.mock_node_create({}, 500)
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     with self.assertRaises(ProgramPublisherException):
         publisher._create_node(self.api_client, publish_data)  # pylint: disable=protected-access
Beispiel #11
0
 def test_publish_program_no_credential(self):
     self.program.partner.marketing_site_api_password = None
     self.program.partner.marketing_site_api_username = None
     publisher = MarketingSitePublisher()
     with self.assertRaises(ProgramPublisherException):
         publisher.publish_program(self.program)
         self.assert_responses_call_count(0)
Beispiel #12
0
 def test_publish_modified_program(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_edit(200)
     program_before = ProgramFactory()
     publisher = MarketingSitePublisher(program_before)
     publisher.publish_program(self.program)
     self.assert_responses_call_count(6)
Beispiel #13
0
 def test_publish_modified_program(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_edit(200)
     program_before = ProgramFactory()
     publisher = MarketingSitePublisher(program_before)
     publisher.publish_program(self.program)
     self.assert_responses_call_count(6)
Beispiel #14
0
 def test_create_node(self):
     self.mock_api_client(200)
     expected = {'list': [{'nid': self.nid}]}
     self.mock_node_create(expected, 201)
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     data = publisher._create_node(self.api_client, publish_data)  # pylint: disable=protected-access
     self.assertEqual(data, expected)
Beispiel #15
0
 def test_publish_program_create(self):
     self.mock_api_client(200)
     expected = {'list': [{'nid': self.nid}]}
     self.mock_node_retrieval(self.program.uuid, exists=False)
     self.mock_node_create(expected, 201)
     publisher = MarketingSitePublisher()
     publisher.publish_program(self.program)
     self.assert_responses_call_count(6)
Beispiel #16
0
 def test_add_alias_failed(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_edit(200)
     publisher = MarketingSitePublisher()
     self.mock_add_alias(500)
     with mock.patch.object(MarketingSitePublisher, '_get_form_build_id_and_form_token', return_value={}):
         with self.assertRaises(ProgramPublisherException):
             publisher.publish_program(self.program)
Beispiel #17
0
 def test_get_alias_form(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_edit(200)
     publisher = MarketingSitePublisher()
     self.mock_add_alias()
     self.mock_get_alias_form()
     with mock.patch.object(MarketingSitePublisher, '_get_headers', return_value={}):
         publisher.publish_program(self.program)
         self.assert_responses_call_count(9)
Beispiel #18
0
 def test_publish_program_create(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid, exists=False)
     self.mock_node_create(self.expected_node, 201)
     publisher = MarketingSitePublisher()
     self.mock_add_alias()
     with mock.patch.object(MarketingSitePublisher, '_get_headers', return_value={}):
         with mock.patch.object(MarketingSitePublisher, '_get_form_build_id_and_form_token', return_value={}):
             publisher.publish_program(self.program)
             self.assert_responses_call_count(8)
Beispiel #19
0
 def test_get_delete_form_failed(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_edit(200)
     program_before = ProgramFactory()
     publisher = MarketingSitePublisher(program_before)
     self.mock_add_alias()
     self.mock_get_delete_form(program_before.marketing_slug, 500)
     with mock.patch.object(MarketingSitePublisher, '_get_headers', return_value={}):
         with mock.patch.object(MarketingSitePublisher, '_get_form_build_id_and_form_token', return_value={}):
             with self.assertRaises(ProgramPublisherException):
                 publisher.publish_program(self.program)
Beispiel #20
0
 def test_create_node(self):
     self.mock_api_client(200)
     expected = {
         'list': [{
             'nid': self.nid
         }]
     }
     self.mock_node_create(expected, 201)
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     data = publisher._create_node(self.api_client, publish_data)  # pylint: disable=protected-access
     self.assertEqual(data, expected)
Beispiel #21
0
 def test_publish_program_create(self):
     self.mock_api_client(200)
     expected = {
         'list': [{
             'nid': self.nid
         }]
     }
     self.mock_node_retrieval(self.program.uuid, exists=False)
     self.mock_node_create(expected, 201)
     publisher = MarketingSitePublisher()
     publisher.publish_program(self.program)
     self.assert_responses_call_count(6)
Beispiel #22
0
 def test_publish_modified_program(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid)
     self.mock_node_edit(200)
     program_before = ProgramFactory()
     publisher = MarketingSitePublisher(program_before)
     self.mock_add_alias()
     self.mock_delete_alias()
     with mock.patch.object(MarketingSitePublisher, '_get_headers', return_value={}):
         with mock.patch.object(MarketingSitePublisher, '_get_form_build_id_and_form_token', return_value={}):
             with mock.patch.object(MarketingSitePublisher, '_get_delete_alias_url', return_value='/foo'):
                 publisher.publish_program(self.program)
                 self.assert_responses_call_count(9)
Beispiel #23
0
 def test_get_node_data(self):
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     expected = {
         'type': str(self.program.type).lower(),
         'title': self.program.title,
         'field_uuid': str(self.program.uuid),
         'uuid': str(self.program.uuid),
         'author': {
             'id': self.user_id,
         },
         'status': 1 if self.program.status == ProgramStatus.Active else 0
     }
     self.assertDictEqual(publish_data, expected)
Beispiel #24
0
 def test_get_node_data(self):
     publisher = MarketingSitePublisher()
     publish_data = publisher._get_node_data(self.program, self.user_id)  # pylint: disable=protected-access
     expected = {
         'type': str(self.program.type).lower(),
         'title': self.program.title,
         'field_uuid': str(self.program.uuid),
         'uuid': str(self.program.uuid),
         'author': {
             'id': self.user_id,
         },
         'status': 1 if self.program.status == ProgramStatus.Active else 0
     }
     self.assertDictEqual(publish_data, expected)
Beispiel #25
0
    def save(self, *args, **kwargs):
        if waffle.switch_is_active('publish_program_to_marketing_site') and self.partner.has_marketing_site:
            # Before save, get from database the existing data if exists
            existing_program = None
            if self.id:
                existing_program = Program.objects.get(id=self.id)
            # Pass existing data to the publisher so it can decide whether we should publish
            publisher = MarketingSitePublisher(existing_program)

            with transaction.atomic():
                super(Program, self).save(*args, **kwargs)
                # Once save complete, we need to update the marketing site
                # So the marketing page for this program is automatically updated
                publisher.publish_program(self)
        else:
            super(Program, self).save(*args, **kwargs)
        self.reindex_courses()
Beispiel #26
0
    def save(self, *args, **kwargs):
        if waffle.switch_is_active('publish_program_to_marketing_site') and self.partner.has_marketing_site:
            # Before save, get from database the existing data if exists
            existing_program = None
            if self.id:
                existing_program = Program.objects.get(id=self.id)
            # Pass existing data to the publisher so it can decide whether we should publish
            publisher = MarketingSitePublisher(existing_program)

            with transaction.atomic():
                super(Program, self).save(*args, **kwargs)
                # Once save complete, we need to update the marketing site
                # So the marketing page for this program is automatically updated
                publisher.publish_program(self)
        else:
            super(Program, self).save(*args, **kwargs)
        self.reindex_courses()
Beispiel #27
0
 def test_get_non_existent_node_id(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid, exists=False)
     publisher = MarketingSitePublisher()
     node_id = publisher._get_node_id(self.api_client, self.program.uuid)  # pylint: disable=protected-access
     self.assertIsNone(node_id)
Beispiel #28
0
 def test_publish_unmodified_program(self):
     self.mock_api_client(200)
     publisher = MarketingSitePublisher(self.program)
     publisher.publish_program(self.program)
     self.assert_responses_call_count(0)
Beispiel #29
0
 def test_get_non_existent_node_id(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid, exists=False)
     publisher = MarketingSitePublisher()
     node_id = publisher._get_node_id(self.api_client, self.program.uuid)  # pylint: disable=protected-access
     self.assertIsNone(node_id)
Beispiel #30
0
 def test_publish_xseries_program(self):
     self.program.type = ProgramType.objects.get(name='XSeries')
     publisher = MarketingSitePublisher()
     publisher.publish_program(self.program)
     self.assert_responses_call_count(0)
Beispiel #31
0
 def test_publish_delete_xseries(self):
     self.program = ProgramFactory(type=ProgramType.objects.get(name='XSeries'))
     publisher = MarketingSitePublisher()
     publisher.delete_program(self.program)
     self.assert_responses_call_count(0)
Beispiel #32
0
 def test_publish_delete_non_existent_program(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid, exists=False)
     publisher = MarketingSitePublisher()
     publisher.delete_program(self.program)
     self.assert_responses_call_count(5)
Beispiel #33
0
 def test_publish_delete_non_existent_program(self):
     self.mock_api_client(200)
     self.mock_node_retrieval(self.program.uuid, exists=False)
     publisher = MarketingSitePublisher()
     publisher.delete_program(self.program)
     self.assert_responses_call_count(4)
Beispiel #34
0
def delete_program(sender, instance, **kwargs):  # pylint: disable=unused-argument
    if waffle.switch_is_active('publish_program_to_marketing_site') and \
            instance.partner.has_marketing_site:
        publisher = MarketingSitePublisher()
        publisher.delete_program(instance)
Beispiel #35
0
 def test_publish_xseries_program(self):
     self.program.type = ProgramType.objects.get(name='XSeries')
     publisher = MarketingSitePublisher()
     publisher.publish_program(self.program)
     self.assert_responses_call_count(0)
Beispiel #36
0
 def test_publish_unmodified_program(self):
     self.mock_api_client(200)
     publisher = MarketingSitePublisher(self.program)
     publisher.publish_program(self.program)
     self.assert_responses_call_count(0)