Commit b3957384 by Matthew Piatetsky

Publish alias when creating new node

ECOM-6793
parent 0ea5a495
...@@ -147,7 +147,8 @@ class MarketingSitePublisher(object): ...@@ -147,7 +147,8 @@ class MarketingSitePublisher(object):
node_url = '{root}/node.json'.format(root=api_client.api_url) node_url = '{root}/node.json'.format(root=api_client.api_url)
response = api_client.api_session.post(node_url, data=json.dumps(node_data)) response = api_client.api_session.post(node_url, data=json.dumps(node_data))
if response.status_code == 201: if response.status_code == 201:
return response.json() response_json = response.json()
return response_json['id']
else: else:
raise ProgramPublisherException("Marketing site page creation failed!") raise ProgramPublisherException("Marketing site page creation failed!")
...@@ -228,7 +229,7 @@ class MarketingSitePublisher(object): ...@@ -228,7 +229,7 @@ class MarketingSitePublisher(object):
self._edit_node(api_client, node_id, node_data) self._edit_node(api_client, node_id, node_data)
else: else:
# We should create a new node # We should create a new node
self._create_node(api_client, node_data) node_id = self._create_node(api_client, node_data)
before_alias = self._make_alias(self.program_before) if self.program_before else None before_alias = self._make_alias(self.program_before) if self.program_before else None
new_alias = self._make_alias(program) new_alias = self._make_alias(program)
before_slug = self.program_before.marketing_slug if self.program_before else None before_slug = self.program_before.marketing_slug if self.program_before else None
......
...@@ -115,6 +115,12 @@ class MarketingSitePublisherTests(MarketingSitePublisherTestMixin): ...@@ -115,6 +115,12 @@ class MarketingSitePublisherTests(MarketingSitePublisherTestMixin):
self.password, self.password,
self.api_root self.api_root
) )
self.expected_node = {
'uuid': '945bb2c7-0a57-4a3f-972a-8c7f94aa0661',
'resource': 'node',
'uri': 'https://stage.edx.org/node/28426',
'id': '28426'
}
def test_get_node_data(self): def test_get_node_data(self):
publisher = MarketingSitePublisher() publisher = MarketingSitePublisher()
...@@ -169,16 +175,11 @@ class MarketingSitePublisherTests(MarketingSitePublisherTestMixin): ...@@ -169,16 +175,11 @@ class MarketingSitePublisherTests(MarketingSitePublisherTestMixin):
@responses.activate @responses.activate
def test_create_node(self): def test_create_node(self):
self.mock_api_client(200) self.mock_api_client(200)
expected = { self.mock_node_create(self.expected_node, 201)
'list': [{
'nid': self.node_id
}]
}
self.mock_node_create(expected, 201)
publisher = MarketingSitePublisher() publisher = MarketingSitePublisher()
publish_data = publisher._get_node_data(self.program, self.user_id) # pylint: disable=protected-access 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 data = publisher._create_node(self.api_client, publish_data) # pylint: disable=protected-access
self.assertEqual(data, expected) self.assertEqual(data, self.expected_node['id'])
@responses.activate @responses.activate
def test_create_node_failed(self): def test_create_node_failed(self):
...@@ -192,13 +193,8 @@ class MarketingSitePublisherTests(MarketingSitePublisherTestMixin): ...@@ -192,13 +193,8 @@ class MarketingSitePublisherTests(MarketingSitePublisherTestMixin):
@responses.activate @responses.activate
def test_publish_program_create(self): def test_publish_program_create(self):
self.mock_api_client(200) self.mock_api_client(200)
expected = {
'list': [{
'node_id': self.node_id
}]
}
self.mock_node_retrieval(self.program.uuid, exists=False) self.mock_node_retrieval(self.program.uuid, exists=False)
self.mock_node_create(expected, 201) self.mock_node_create(self.expected_node, 201)
publisher = MarketingSitePublisher() publisher = MarketingSitePublisher()
self.mock_add_alias() self.mock_add_alias()
with mock.patch.object(MarketingSitePublisher, '_get_headers', return_value={}): with mock.patch.object(MarketingSitePublisher, '_get_headers', return_value={}):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment