Ejemplo n.º 1
0
    def test_namehasprefix(self):
        export = mock.MagicMock()
        export.name = 'export_frete'

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

        isexport = namehasprefix('export_')

        self.assertTrue(isexport.apply(export))
        self.assertFalse(isexport.apply(notexport))
Ejemplo 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)