Exemplo n.º 1
0
    def test_namehassuffix(self):
        odp = mock.MagicMock()
        odp.name = 'presentation.odp'

        notodp = mock.MagicMock()
        notodp.name = 'blargh'

        isodp = namehassuffix('.odp')
        self.assertTrue(isodp.apply(odp))
        self.assertFalse(isodp.apply(notodp))
Exemplo n.º 2
0
    def test_collect_applies_rule(self):
        mock_obj1 = mock.MagicMock() 
        mock_obj1.name = 'pref_name_suf'

        mock_obj2 = mock.MagicMock() 
        mock_obj2.name = 'noprefnosuf'

        mock_cont = mock.MagicMock() 
        mock_cont.get_objects.return_value = [mock_obj1, mock_obj2]

        mock_conn = mock.MagicMock()
        mock_conn.get_all_containers.return_value = [mock_cont]
        mock_conn.get_container.return_value = mock_cont

        with mock.patch('cloudfiles.get_connection', return_value=mock_conn):
            deleted = collect(rule=namehasprefix('pref')&namehassuffix('suf') ,user=mock.ANY, key=mock.ANY)

        self.assertIn(mock.call.delete_object(mock_obj1.name), mock_cont.method_calls)
        self.assertNotIn(mock.call.delete_object(mock_obj2.name), mock_cont.method_calls)
        self.assertItemsEqual([mock_obj1.name], deleted)