Ejemplo n.º 1
0
    def check_update_happens(self,
                             node,
                             dependency,
                             update_params=None,
                             expected_match_clause=None,
                             mock_scan=None,
                             delete=False):
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        nodes_to_sync = list_nodes_to_update()
        self.assertNotIn(node, nodes_to_sync)

        if delete:
            dependency.delete()
        else:
            setattr(dependency, update_params['field'], update_params['value'])
            dependency.save()

        nodes_ids_to_update = [{"_id": node.id}]
        mock_scan.return_value = nodes_ids_to_update

        nodes_to_sync = list_nodes_to_update()

        call_args = mock_scan.call_args
        query = call_args[1]['query']
        self.assertEqual(call_args[1]['doc_type'], ES_SETTINGS.NODE_TYPE)
        self.assertDictContainsSubset({'fields': []}, query)
        self.assertIn(expected_match_clause,
                      call_args[1]['query']['filter']['bool']['should'])

        self.assertEqual(call_args[1]['index'], ES_SETTINGS.INDEX)
        self.assertIn(node, nodes_to_sync)
Ejemplo n.º 2
0
    def check_update_happens(self, node, dependency, update_params=None, expected_match_clause=None, mock_scan=None,
                             delete=False):
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        nodes_to_sync = list_nodes_to_update()
        self.assertNotIn(node, nodes_to_sync)

        if delete:
            dependency.delete()
        else:
            setattr(dependency, update_params['field'], update_params['value'])
            dependency.save()

        nodes_ids_to_update = [{"_id": node.id}]
        mock_scan.return_value = nodes_ids_to_update

        nodes_to_sync = list_nodes_to_update()

        call_args = mock_scan.call_args
        query = call_args[1]['query']
        self.assertEqual(call_args[1]['doc_type'], ES_SETTINGS.NODE_TYPE)
        self.assertDictContainsSubset({'fields': []}, query)
        self.assertIn(expected_match_clause, call_args[1]['query']['filter']['bool']['should'])

        self.assertEqual(call_args[1]['index'], ES_SETTINGS.INDEX)
        self.assertIn(node, nodes_to_sync)
Ejemplo n.º 3
0
 def test_should_post_node_mapping_to_elasticsearch_when_no_sync_info_exists(
         self, mock_post, mock_put, *_):
     mock_post.return_value = FakeResponse({}, status_code=HTTP_200_OK)
     mock_put.return_value = FakeResponse({}, status_code=HTTP_200_OK)
     url = '%s/delivery_node/' % settings.ELASTIC_SEARCH.MAPPING
     list_nodes_to_update()
     mock_post.assert_called_with(url, json=DELIVERY_NODE_MAPPING)
Ejemplo n.º 4
0
    def test_should_add_changed_node_to_sync_data(self, *_):
        node = DeliveryNodeFactory(location='Kampala')
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        list_nodes_to_update()

        node.location = 'Changed location'
        node.save()
        nodes_to_sync = list_nodes_to_update()

        self.assertIn(node, nodes_to_sync)
Ejemplo n.º 5
0
    def test_should_add_changed_node_to_sync_data(self, *_):
        node = DeliveryNodeFactory(location='Kampala')
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        list_nodes_to_update()

        node.location = 'Changed location'
        node.save()
        nodes_to_sync = list_nodes_to_update()

        self.assertIn(node, nodes_to_sync)
Ejemplo n.º 6
0
    def test_should_not_include_match_clauses_with_empty_id_lists(self, mock_scan):
        node = DeliveryNodeFactory(location='Kampala')
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        list_nodes_to_update()

        node.location = 'Changed location'
        node.save()
        nodes_to_sync = list_nodes_to_update()

        self.assertFalse(mock_scan.called)
        self.assertIn(node, nodes_to_sync)
Ejemplo n.º 7
0
    def test_should_not_include_match_clauses_with_empty_id_lists(
            self, mock_scan):
        node = DeliveryNodeFactory(location='Kampala')
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        list_nodes_to_update()

        node.location = 'Changed location'
        node.save()
        nodes_to_sync = list_nodes_to_update()

        self.assertFalse(mock_scan.called)
        self.assertIn(node, nodes_to_sync)
Ejemplo n.º 8
0
    def test_should_include_all_nodes_on_first_sync(self, mock_put, mock_post):
        mock_post.return_value = FakeResponse({}, status_code=HTTP_200_OK)
        mock_put.return_value = FakeResponse({}, status_code=HTTP_200_OK)
        self.assertEqual(SyncInfo.objects.count(), 0)
        node_one = DeliveryNodeFactory()
        node_two = DeliveryNodeFactory()

        nodes_to_sync = list_nodes_to_update()

        self.assertEqual(len(nodes_to_sync), 2)
        self.assertIn(node_one, nodes_to_sync)
        self.assertIn(node_two, nodes_to_sync)
Ejemplo n.º 9
0
    def test_should_include_all_nodes_on_first_sync(self, mock_put, mock_post):
        mock_post.return_value = FakeResponse({}, status_code=HTTP_200_OK)
        mock_put.return_value = FakeResponse({}, status_code=HTTP_200_OK)
        self.assertEqual(SyncInfo.objects.count(), 0)
        node_one = DeliveryNodeFactory()
        node_two = DeliveryNodeFactory()

        nodes_to_sync = list_nodes_to_update()

        self.assertEqual(len(nodes_to_sync), 2)
        self.assertIn(node_one, nodes_to_sync)
        self.assertIn(node_two, nodes_to_sync)
Ejemplo n.º 10
0
    def xtest_should_include_new_nodes_in_sync_queryset(self):
        pre_sync_node = DeliveryNodeFactory()

        last_sync_time = timezone.datetime.now()
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL, start_time=last_sync_time)
        post_sync_node_one = DeliveryNodeFactory()
        post_sync_node_two = DeliveryNodeFactory()

        nodes_to_sync = list_nodes_to_update()

        self.assertEqual(len(nodes_to_sync), 2)
        self.assertIn(post_sync_node_one, nodes_to_sync)
        self.assertIn(post_sync_node_two, nodes_to_sync)
        self.assertNotIn(pre_sync_node, nodes_to_sync)
Ejemplo n.º 11
0
    def xtest_should_include_new_nodes_in_sync_queryset(self):
        pre_sync_node = DeliveryNodeFactory()

        last_sync_time = timezone.datetime.now()
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL,
                                start_time=last_sync_time)
        post_sync_node_one = DeliveryNodeFactory()
        post_sync_node_two = DeliveryNodeFactory()

        nodes_to_sync = list_nodes_to_update()

        self.assertEqual(len(nodes_to_sync), 2)
        self.assertIn(post_sync_node_one, nodes_to_sync)
        self.assertIn(post_sync_node_two, nodes_to_sync)
        self.assertNotIn(pre_sync_node, nodes_to_sync)
Ejemplo n.º 12
0
def run():
    sync = SyncInfo.objects.create()
    nodes_to_update = serialise_nodes(list_nodes_to_update())
    _push_to_elasticsearch(nodes_to_update, list_nodes_to_delete(), sync)
Ejemplo n.º 13
0
 def test_should_post_node_mapping_to_elasticsearch_when_no_sync_info_exists(self, mock_post, mock_put, *_):
     mock_post.return_value = FakeResponse({}, status_code=HTTP_200_OK)
     mock_put.return_value = FakeResponse({}, status_code=HTTP_200_OK)
     url = '%s/delivery_node/' % settings.ELASTIC_SEARCH.MAPPING
     list_nodes_to_update()
     mock_post.assert_called_with(url, json=DELIVERY_NODE_MAPPING)