Beispiel #1
0
    def test_fork_reverts_to_using_user_storage_default(self):
        user = UserFactory()
        user2 = UserFactory()
        us = RegionFactory()
        canada = RegionFactory()

        user_settings = user.get_addon('osfstorage')
        user_settings.default_region = us
        user_settings.save()
        user2_settings = user2.get_addon('osfstorage')
        user2_settings.default_region = canada
        user2_settings.save()

        project = ProjectFactory(creator=user, is_public=True)
        child = NodeFactory(parent=project, creator=user, is_public=True)
        child_settings = child.get_addon('osfstorage')
        child_settings.region_id = canada.id
        child_settings.save()

        fork = project.fork_node(Auth(user))
        child_fork = models.Node.objects.get_children(fork).first()
        assert fork.get_addon('osfstorage').region_id == us.id
        assert fork.get_addon('osfstorage').user_settings == user.get_addon(
            'osfstorage')
        assert child_fork.get_addon('osfstorage').region_id == us.id

        fork = project.fork_node(Auth(user2))
        child_fork = models.Node.objects.get_children(fork).first()
        assert fork.get_addon('osfstorage').region_id == canada.id
        assert fork.get_addon('osfstorage').user_settings == user2.get_addon(
            'osfstorage')
        assert child_fork.get_addon('osfstorage').region_id == canada.id
Beispiel #2
0
    def project_with_different_regions(self, user):
        """
        A complex project configuration with many regions.
        :param user:
        :return:
        """
        parent_node = root_node = ProjectFactory(creator=user)

        # components have nested children
        for _ in range(0, 1):
            parent_node = ProjectFactory(creator=user, parent=parent_node)
            addon = parent_node.get_addon('osfstorage')
            addon.region = RegionFactory()
            addon.save()

        # root project has two direct children
        for _ in range(0, 1):
            parent_node = ProjectFactory(creator=user, parent=root_node)
            addon = parent_node.get_addon('osfstorage')
            addon.region = RegionFactory()
            addon.save()

        addon = root_node.get_addon('osfstorage')
        addon.region = RegionFactory()
        addon.save()

        return root_node
Beispiel #3
0
    def test_encrypted_json_field(self):
        new_test_creds = {
            'storage': {
                'go': 'science',
                'hey': ['woo', 'yeah', 'great']
            }
        }
        region = RegionFactory()
        region.waterbutler_credentials = new_test_creds
        region.save()

        assert region.waterbutler_credentials == new_test_creds
Beispiel #4
0
    def test_encrypted_json_field(self):
        new_test_creds = {
            'storage': {
                'go': 'science',
                'hey': ['woo', 'yeah', 'great']
            }
        }
        region = RegionFactory()
        region.waterbutler_credentials = new_test_creds
        region.save()

        assert region.waterbutler_credentials == new_test_creds
Beispiel #5
0
    def test_move_nested_between_regions(self):
        canada = RegionFactory()
        new_component = NodeFactory(parent=self.project)
        component_node_settings = new_component.get_addon('osfstorage')
        component_node_settings.region = canada
        component_node_settings.save()

        move_to = component_node_settings.get_root()
        to_move = self.node_settings.get_root().append_folder(
            'Aaah').append_folder('Woop')
        child = to_move.append_file('There it is')

        for _ in range(2):
            version = factories.FileVersionFactory(
                region=self.node_settings.region)
            child.add_version(version)
        child.save()

        moved = to_move.move_under(move_to)
        child.reload()

        assert new_component == child.target
        versions = child.versions.order_by('-created')
        assert versions.first().region == component_node_settings.region
        assert versions.last().region == self.node_settings.region
Beispiel #6
0
def test_file_update_respects_region(project, user, create_test_file):
    test_file = create_test_file(target=project)
    version = test_file.versions.first()
    original_region = project.osfstorage_region
    assert version.region == original_region

    # update the region on the project, ensure the new version has the new region
    node_settings = NodeSettings.objects.get(owner=project.id)
    new_region = RegionFactory()
    node_settings.region = new_region
    node_settings.save()
    test_file.save()
    test_file.reload()

    new_version = test_file.create_version(
        user, {
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
            'object': '07d80a',
        }, {
            'sha256': 'existing',
        }
    )
    assert new_region != original_region
    assert new_version.region == new_region
Beispiel #7
0
    def test_region_wb_url_from_creators_defaults(self):
        user = UserFactory()
        region = RegionFactory()

        user_settings = user.get_addon('osfstorage')
        user_settings.default_region = region
        user_settings.save()

        project = ProjectFactory(creator=user)
        node_settings = project.get_addon('osfstorage')

        assert node_settings.region_id == region.id
Beispiel #8
0
 def region2(self):
     return RegionFactory()
 def region(self):
     return RegionFactory(name='Frankfort', _id='eu-central-1')
Beispiel #10
0
    def test_data_storage_usage_command(self):
        import logging
        logger = logging.getLogger(__name__)

        expected_summary_data = OrderedDict([
            ('date', None),
            ('total', 0),
            ('deleted', 0),
            ('registrations', 0),
            ('nd_quick_files', 0),
            ('nd_public_nodes', 0),
            ('nd_private_nodes', 0),
            ('nd_preprints', 0),
            ('nd_supp_nodes', 0),
            ('canada_montreal', 0),
            ('australia_sydney', 0),
            ('germany_frankfurt', 0),
            ('united_states', 0),
        ])
        user = UserFactory()
        user_addon = user.get_addon('osfstorage')
        user_addon.default_region_id = self.region_us
        region_ca = RegionFactory(_id='CA-1', name=u'Canada - Montréal')
        region_de = RegionFactory(_id='DE-1', name='Germany - Frankfurt')
        region_au = RegionFactory(_id='AU-1', name='Australia - Sydney')

        project_public_us = self.project(creator=user, is_public=True)
        small_size = next_file_size()
        file_size = next(small_size)
        project_public_us_test_file = create_test_file(
            target=project_public_us,
            user=user,
            size=file_size
        )
        logger.debug(u'Public project, US: {}'.format(file_size))
        expected_summary_data['total'] += file_size
        expected_summary_data['nd_public_nodes'] += file_size
        expected_summary_data['united_states'] += file_size
        file_size = next(small_size)
        self.add_file_version(
            project_public_us_test_file,
            user=user,
            size=file_size,
        )
        logger.debug(u'Public project file version, US: {}'.format(file_size))
        expected_summary_data['total'] += file_size
        expected_summary_data['nd_public_nodes'] += file_size
        expected_summary_data['united_states'] += file_size

        project_private_au = self.project(creator=user, is_public=False, region=region_au)
        file_size = next(small_size)
        create_test_file(
            target=project_private_au,
            user=user,
            size=file_size
        )
        logger.debug(u'Private project, AU: {}'.format(file_size))
        expected_summary_data['total'] += file_size
        expected_summary_data['nd_private_nodes'] += file_size
        expected_summary_data['australia_sydney'] += file_size

        component_private_small_deleted_de = self.project(
            creator=user,
            is_public=False,
            region=region_de,
            parent=project_public_us
        )
        file_size = next(small_size)
        deleted_file = create_test_file(
            target=component_private_small_deleted_de,
            user=user,
            size=file_size,
        )
        logger.debug('Before deletion: {}'.format(deleted_file.target.title))

        deleted_file.delete(user=user, save=True)
        logger.debug(u'Deleted project, DE: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['deleted'] += file_size
        expected_summary_data['germany_frankfurt'] += file_size
        logger.debug('After deletion: {}'.format(deleted_file.target.title))

        file_size = next(small_size)
        PreprintFactory(creator=user, file_size=file_size)  # preprint_us
        logger.debug(u'Preprint, US: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['nd_preprints'] += file_size
        expected_summary_data['united_states'] += file_size

        user_addon.default_region_id = region_ca
        user_addon.save()
        file_size = next(small_size)
        preprint_with_supplement_ca = PreprintFactory(creator=user, file_size=file_size)
        logger.debug(u'Preprint, CA: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['nd_preprints'] += file_size
        expected_summary_data['canada_montreal'] += file_size
        user_addon.default_region_id = self.region_us
        user_addon.save()
        supplementary_node_public_au = self.project(creator=user, is_public=True, region=region_au)
        preprint_with_supplement_ca.node = supplementary_node_public_au
        preprint_with_supplement_ca.save()
        file_size = next(small_size)
        create_test_file(
            target=supplementary_node_public_au,
            user=user,
            size=file_size
        )
        logger.debug(u'Public supplemental project of Canadian preprint, US: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['nd_supp_nodes'] += file_size
        expected_summary_data['nd_public_nodes'] += file_size
        expected_summary_data['australia_sydney'] += file_size

        file_size = next(small_size)
        withdrawn_preprint_us = PreprintFactory(creator=user, file_size=file_size)
        withdrawn_preprint_us.date_withdrawn = timezone.now()
        withdrawn_preprint_us.save()
        logger.debug(u'Withdrawn preprint, US: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['nd_preprints'] += file_size
        expected_summary_data['united_states'] += file_size

        quickfiles_node_us = QuickFilesNode.objects.get(creator=user)
        file_size = next(small_size)
        create_test_file(target=quickfiles_node_us, user=user, size=file_size)
        logger.debug(u'Quickfile, US: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['nd_quick_files'] += file_size
        expected_summary_data['united_states'] += file_size

        file_size = next(small_size)
        quickfile_deleted = create_test_file(
            filename='deleted_test_file',
            target=quickfiles_node_us,
            user=user,
            size=file_size
        )
        quickfile_deleted.delete(user=user, save=True)
        logger.debug(u'Deleted quickfile, US: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['deleted'] += file_size
        expected_summary_data['united_states'] += file_size

        project_to_register_us = self.project(creator=user, is_public=True, region=self.region_us)

        registration = self.registration(project=project_to_register_us, creator=user)
        file_size = next(small_size)
        create_test_file(
            target=registration,
            user=user,
            size=file_size
        )
        assert registration.get_addon('osfstorage').region == self.region_us
        logger.debug(u'Registration, US: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['united_states'] += file_size
        expected_summary_data['registrations'] += file_size

        withdrawal = self.registration(project=project_to_register_us, creator=user, withdrawn=True)
        file_size = next(small_size)
        create_test_file(
            target=withdrawal,
            user=user,
            size=file_size
        )
        logger.debug(u'Withdrawn registration, US: {}'.format(file_size))

        expected_summary_data['total'] += file_size
        expected_summary_data['united_states'] += file_size
        expected_summary_data['registrations'] += file_size

        actual_summary_data = process_usages(dry_run=True, page_size=2)

        actual_keys = actual_summary_data.keys()
        for key in actual_summary_data:
            logger.info('Actual field: {}'.format(key))
        expected_keys = expected_summary_data.keys()
        for key in expected_summary_data:
            logger.info('Expected field: {}'.format(key))
        assert actual_keys == expected_keys
        assert len(actual_keys) != 0

        for key in actual_keys:
            if key != 'date':
                assert (key, expected_summary_data[key]) == (key, actual_summary_data[key])
Beispiel #11
0
 def setUp(self):
     super(TestDataStorageUsage, self).setUp()
     self.region_us = RegionFactory(_id='US', name='United States')
Beispiel #12
0
 def setUp(self):
     super(TestMigrateDeletedDate, self).setUp()
     self.region_us = RegionFactory(_id='US', name='United States')