def setUp(self):
        self.list_view = ViewSet.as_view({'get': 'list'})
        self.detailed_view = ViewSet.as_view({'get': 'retrieve'})

        self.anonymous_user = AnonymousUserFactory()
        self.user_without_sources = UserFactory.create(username='******')
        self.user_with_sources = UserFactory.create(username='******')
        self.user = self.user_with_sources
        self.provider = ProviderFactory.create()
        self.user_identity = IdentityFactory.create_identity(
            created_by=self.user_without_sources,
            provider=self.provider)
        self.user_identity = IdentityFactory.create_identity(
            created_by=self.user_with_sources,
            provider=self.provider)

        self.allocation_source_1 = AllocationSourceFactory.create(name='TG-TRA110001',
                                                                  compute_allowed=1000)

        self.allocation_source_2 = AllocationSourceFactory.create(name='TG-TRA220002',
                                                                  compute_allowed=2000)

        self.allocation_source_3 = AllocationSourceFactory.create(name='TG-TRA330003',
                                                                  compute_allowed=3000)

        UserAllocationSourceFactory.create(user=self.user_with_sources, allocation_source=self.allocation_source_1)
        UserAllocationSourceFactory.create(user=self.user_with_sources, allocation_source=self.allocation_source_2)
    def setUp(self):
        self.list_view = ViewSet.as_view({'get': 'list'})
        self.detailed_view = ViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.staff_user = UserFactory.create(is_staff=True)

        self.provider = ProviderFactory.create()
        self.quota = QuotaFactory.create()
        self.identity = IdentityFactory.create(
            provider=self.provider, quota=self.quota, created_by=self.user
        )
        IdentityMembershipFactory.create(
            member=self.group,
            identity=self.identity,
        )

        factory = APIRequestFactory()
        detail_url = reverse(
            'api:v2:identity-detail', args=(self.identity.id, )
        )
        self.detail_request = factory.get(detail_url)

        list_url = reverse('api:v2:identity-list')
        self.list_request = factory.get(list_url)
Beispiel #3
0
def create_an_instance(user=None, ip_address=None):
    # This method should be replaced when the InstanceFactory can create an
    # instance w/o requiring any arguments
    import uuid
    from api.tests.factories import (
        UserFactory, InstanceFactory, ProviderMachineFactory, IdentityFactory,
        ProviderFactory)
    from django.utils import timezone

    if not user:
        user = UserFactory.create()
    staff_user = UserFactory.create(is_staff=True, is_superuser=True)
    provider = ProviderFactory.create()
    user_identity = IdentityFactory.create_identity(
        created_by=user,
        provider=provider)
    staff_user_identity = IdentityFactory.create_identity(
        created_by=staff_user,
        provider=provider)
    machine = ProviderMachineFactory.create_provider_machine(staff_user, staff_user_identity)
    start_date = timezone.now()
    return InstanceFactory.create(
        name="",
        provider_alias=uuid.uuid4(),
        source=machine.instance_source,
        ip_address=ip_address,
        created_by=user,
        created_by_identity=user_identity,
        start_date=start_date)
    def setUp(self):
        self.list_view = ViewSet.as_view({'get': 'list'})
        self.detailed_view = ViewSet.as_view({'get': 'retrieve'})

        self.anonymous_user = AnonymousUserFactory()
        self.user_without_sources = UserFactory.create(
            username='******')
        self.user_with_sources = UserFactory.create(
            username='******')
        self.user = self.user_with_sources
        self.provider = ProviderFactory.create()
        self.user_identity = IdentityFactory.create_identity(
            created_by=self.user_without_sources, provider=self.provider)
        self.user_identity = IdentityFactory.create_identity(
            created_by=self.user_with_sources, provider=self.provider)

        self.allocation_source_1 = AllocationSourceFactory.create(
            name='TG-TRA110001', compute_allowed=1000)

        self.allocation_source_2 = AllocationSourceFactory.create(
            name='TG-TRA220002', compute_allowed=2000)

        self.allocation_source_3 = AllocationSourceFactory.create(
            name='TG-TRA330003', compute_allowed=3000)

        UserAllocationSourceFactory.create(
            user=self.user_with_sources,
            allocation_source=self.allocation_source_1)
        UserAllocationSourceFactory.create(
            user=self.user_with_sources,
            allocation_source=self.allocation_source_2)
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.leadership = LeadershipFactory.create(
            user=self.user,
            group=self.group
            )
        self.staff_user = UserFactory.create(is_staff=True)

        self.provider = ProviderFactory.create()
        self.identity = IdentityFactory.create(
            provider=self.provider,
            created_by=self.user)
        self.quota = QuotaFactory.create()
        self.allocation = AllocationFactory.create()
        IdentityMembershipFactory.create(
            member=self.group,
            identity=self.identity,
            quota=self.quota
        )

        factory = APIRequestFactory()
        url = reverse('api:v2:identity-detail', args=(self.identity.id,))
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request, pk=self.identity.id)
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.leadership = LeadershipFactory.create(
            user=self.user,
            group=self.group
            )
        self.staff_user = UserFactory.create(is_staff=True)

        self.provider = ProviderFactory.create()
        self.quota = QuotaFactory.create()
        self.identity = IdentityFactory.create(
            provider=self.provider,
            quota=self.quota,
            created_by=self.user)
        self.allocation = AllocationFactory.create()
        IdentityMembershipFactory.create(
            member=self.group,
            identity=self.identity,
        )

        factory = APIRequestFactory()
        url = reverse('api:v2:identity-detail', args=(self.identity.id,))
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request, pk=self.identity.id)
Beispiel #7
0
def create_an_instance(user=None, ip_address=None):
    # This method should be replaced when the InstanceFactory can create an
    # instance w/o requiring any arguments
    import uuid
    from api.tests.factories import (UserFactory, InstanceFactory,
                                     ProviderMachineFactory, IdentityFactory,
                                     ProviderFactory)
    from django.utils import timezone

    if not user:
        user = UserFactory.create()
    staff_user = UserFactory.create(is_staff=True, is_superuser=True)
    provider = ProviderFactory.create()
    user_identity = IdentityFactory.create_identity(created_by=user,
                                                    provider=provider)
    staff_user_identity = IdentityFactory.create_identity(
        created_by=staff_user, provider=provider)
    machine = ProviderMachineFactory.create_provider_machine(
        staff_user, staff_user_identity)
    start_date = timezone.now()
    return InstanceFactory.create(name="",
                                  provider_alias=uuid.uuid4(),
                                  source=machine.instance_source,
                                  ip_address=ip_address,
                                  created_by=user,
                                  created_by_identity=user_identity,
                                  start_date=start_date)
Beispiel #8
0
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user_without_sources = UserFactory.create(
            username='******')
        self.user_with_sources = UserFactory.create(
            username='******')
        self.provider = ProviderFactory.create()
        self.user_identity = IdentityFactory.create_identity(
            created_by=self.user_without_sources, provider=self.provider)
        self.user_identity = IdentityFactory.create_identity(
            created_by=self.user_with_sources, provider=self.provider)

        self.allocation_source_1 = AllocationSourceFactory.create(
            name='TG-TRA110001', source_id='110001', compute_allowed=1000)

        self.allocation_source_2 = AllocationSourceFactory.create(
            name='TG-TRA220002', source_id='220002', compute_allowed=2000)

        self.allocation_source_3 = AllocationSourceFactory.create(
            name='TG-TRA330003', source_id='330003', compute_allowed=3000)

        UserAllocationSourceFactory.create(
            user=self.user_with_sources,
            allocation_source=self.allocation_source_1)
        UserAllocationSourceFactory.create(
            user=self.user_with_sources,
            allocation_source=self.allocation_source_2)
Beispiel #9
0
    def setUp(self):
        self.list_view = ViewSet.as_view({'get': 'list'})
        self.detailed_view = ViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.staff_user = UserFactory.create(is_staff=True)

        self.provider = ProviderFactory.create()
        self.quota = QuotaFactory.create()
        self.identity = IdentityFactory.create(provider=self.provider,
                                               quota=self.quota,
                                               created_by=self.user)
        IdentityMembershipFactory.create(
            member=self.group,
            identity=self.identity,
        )

        factory = APIRequestFactory()
        detail_url = reverse('api:v2:identity-detail',
                             args=(self.identity.id, ))
        self.detail_request = factory.get(detail_url)

        list_url = reverse('api:v2:identity-list')
        self.list_request = factory.get(list_url)
Beispiel #10
0
    def test_get_with_non_owner_returns_403_and_track_not_deleted(self):
        UserFactory.create(username='******')
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('api:delete_track', args=[1, 1]))
        assert response.status_code == 403
        self.assertTemplateUsed('403.html')

        assert self.activity.tracks.count() == 2
Beispiel #11
0
 def setUp(self):
     self.permissions = CanEditOrReadOnly()
     self.user = UserFactory.create()
     self.admin = UserFactory.create(is_staff=True)
     self.creator = UserFactory.create()
     self.anonymous_user = AnonymousUserFactory.create()
     self.obj = mock.Mock()
     self.obj.created_by = self.creator
     self.request = mock.Mock()
     self.view = mock.Mock()
 def setUp(self):
     self.permissions = CanEditOrReadOnly()
     self.user = UserFactory.create()
     self.admin = UserFactory.create(is_staff=True)
     self.creator = UserFactory.create()
     self.anonymous_user = AnonymousUserFactory.create()
     self.obj = mock.Mock()
     self.obj.created_by = self.creator
     self.request = mock.Mock()
     self.view= mock.Mock()
Beispiel #13
0
    def setUp(self):
        self.view = UserViewSet.as_view({'get': 'list'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)

        factory = APIRequestFactory()
        url = reverse('api:v2:atmosphereuser-list')
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request)
 def setUp(self):
     """
     Setup method run after each test.
     Creates a user and saves its token.
     """
     self.user = UserFactory()
     self.token = Token.objects.get(user_id=self.user.user_id)
     self.user.is_active = True
     self.user.username = '******'
     self.user.set_password('password')
     self.user.save()
Beispiel #15
0
    def test_get_with_non_owner_returns_403_and_track_not_untrimmed(self):
        UserFactory.create(username='******')
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('api:untrim_track', args=[1, 1]))
        assert response.status_code == 403
        self.assertTemplateUsed('403.html')

        track = ActivityTrack.objects.get(id=self.track.id)
        assert track.trimmed is True
        assert track.trim_start == self.next.timepoint
        assert track.trim_end == self.penultimate.timepoint
Beispiel #16
0
    def setUp(self):
        self.view = UserViewSet.as_view({'get': 'list'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)

        factory = APIRequestFactory()
        url = reverse('api:v2:atmosphereuser-list')
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request)
Beispiel #17
0
    def setUp(self):
        self.tag = TagFactory.create()
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory()
        self.staff_user = UserFactory(is_staff=True)

        factory = APIRequestFactory()
        url = reverse('api:v2:tag-detail', args=(self.tag.id,))
        self.request = factory.delete(url)

        self.view = TagViewSet.as_view({'delete': 'destroy'})
Beispiel #18
0
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.project = ProjectFactory.create(owner=self.group)

        self.not_user = UserFactory.create()
        self.not_group = GroupFactory.create(name=self.not_user.username)

        self.view = ProjectViewSet.as_view({'delete': 'destroy'})
        self.factory = APIRequestFactory()
        self.url = reverse('api:v2:project-detail', args=(self.project.id, ))
        self.request = self.factory.delete(self.url)
Beispiel #19
0
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'list'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)

        self.image = ImageFactory.create(created_by=self.user)

        factory = APIRequestFactory()
        url = reverse('api:v2:application-list')
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request)
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'list'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)

        self.image = ImageFactory.create(created_by=self.user)

        factory = APIRequestFactory()
        url = reverse('api:v2:application-list')
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request)
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.project = ProjectFactory.create(owner=self.group)

        self.not_user = UserFactory.create()
        self.not_group = GroupFactory.create(name=self.not_user.username)

        self.view = ProjectViewSet.as_view({"delete": "destroy"})
        self.factory = APIRequestFactory()
        self.url = reverse("api:v2:project-detail", args=(self.project.id,))
        self.request = self.factory.delete(self.url)
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'list'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.staff_user = UserFactory.create(is_staff=True)

        self.provider_type = ProviderTypeFactory.create()

        factory = APIRequestFactory()
        url = reverse('api:v2:providertype-list')
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request)
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'list'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.staff_user = UserFactory.create(is_staff=True)

        self.provider_type = ProviderTypeFactory.create()

        factory = APIRequestFactory()
        url = reverse('api:v2:providertype-list')
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request)
Beispiel #24
0
    def setUp(self):
        self.tag = TagFactory.build()
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)

        self.factory = APIRequestFactory()
        self.url = reverse('api:v2:tag-list')
        self.request = self.factory.post(self.url, {
            'name': self.tag.name,
            'description': self.tag.description
        })

        self.view = TagViewSet.as_view({'post': 'create'})
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.staff_user = UserFactory.create(is_staff=True)

        self.allocation = AllocationFactory.create()

        factory = APIRequestFactory()
        url = reverse('api:v2:quota-detail', args=(self.allocation.id, ))
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request, pk=self.allocation.id)
Beispiel #26
0
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.project = ProjectFactory.create(owner=self.group)

        user2 = UserFactory.create()
        group2 = GroupFactory.create(name=user2.username)
        ProjectFactory.create(owner=group2)

        self.view = ProjectViewSet.as_view({'get': 'retrieve'})
        factory = APIRequestFactory()
        url = reverse('api:v2:project-detail', args=(self.project.id, ))
        self.request = factory.get(url)
Beispiel #27
0
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.project = ProjectFactory.create(owner=self.group)

        user2 = UserFactory.create()
        group2 = GroupFactory.create(name=user2.username)
        ProjectFactory.create(owner=group2)

        self.view = ProjectViewSet.as_view({'get': 'retrieve'})
        factory = APIRequestFactory()
        url = reverse('api:v2:project-detail', args=(self.project.id,))
        self.request = factory.get(url)
Beispiel #28
0
    def setUp(self):
        self.tag = TagFactory.build()
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)

        self.factory = APIRequestFactory()
        self.url = reverse('api:v2:tag-list')
        self.request = self.factory.post(self.url, {
            'name': self.tag.name,
            'description': self.tag.description
        })

        self.view = TagViewSet.as_view({'post': 'create'})
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.project = ProjectFactory.create(owner=self.group)

        user2 = UserFactory.create()
        group2 = GroupFactory.create(name=user2.username)
        ProjectFactory.create(owner=group2)

        self.view = ProjectViewSet.as_view({"get": "list"})
        factory = APIRequestFactory()
        url = reverse("api:v2:project-list")
        self.request = factory.get(url)
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.staff_user = UserFactory.create(is_staff=True)

        self.quota = QuotaFactory.create()

        factory = APIRequestFactory()
        url = reverse('api:v2:quota-detail', args=(self.quota.id,))
        self.request = factory.get(url)
        force_authenticate(self.request, user=self.user)
        self.response = self.view(self.request, pk=self.quota.id)
Beispiel #31
0
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)

        factory = APIRequestFactory()

        self.list_view = UserViewSet.as_view({'get': 'list'})
        self.detail_view = UserViewSet.as_view({'get': 'retrieve'})

        detail_url = reverse(self.url_route + '-detail', args=(self.user.id,))
        list_url = reverse(self.url_route + '-list')

        self.detail_request = factory.get(detail_url)
        self.list_request = factory.get(list_url)
Beispiel #32
0
 def test_create_event(self):
     event_count = EventTable.objects.count()
     self.assertEqual(event_count, 0)
     user = UserFactory.create()
     alloc_src = AllocationSource.objects.create(
         name='DefaultAllocation',
         compute_allowed=1000)  # UUID assigned by default.
     UserAllocationSource.objects.create(user=user,
                                         allocation_source=alloc_src)
     event_payload = {
         'allocation_source_id': str(alloc_src.uuid),
         'compute_used':
         100.00,  # 100 hours used ( a number, not a string!)
         'global_burn_rate': 2.00,  # 2 hours used each hour
     }
     new_event = EventTable.create_event(name='allocation_source_snapshot',
                                         payload=event_payload,
                                         entity_id=str(alloc_src.uuid))
     event_count = EventTable.objects.count()
     self.assertEqual(event_count, 2)
     events = EventTable.objects.all()
     self.assertEqual(new_event, events[1])
     self.assertEqual(events[0].name, 'allocation_source_threshold_met')
     self.assertEqual(events[0].entity_id, str(alloc_src.uuid))
     self.assertEqual(
         events[0].payload, {
             'actual_value': 10,
             'allocation_source_id': str(alloc_src.uuid),
             'threshold': 10
         })
Beispiel #33
0
    def __init__(self):

        self.user = UserFactory.create()
        provider_type = ProviderType(name='Test_%s' % self.user.username)
        provider_type.save()
        platform_type = PlatformType(name='test-platform-%s' %
                                     self.user.username)
        platform_type.save()
        provider = Provider(location='BIO5',
                            type=provider_type,
                            virtualization=platform_type)
        provider.save()

        active_status = InstanceStatus.objects.filter(name='active').last()
        if not active_status:
            active_status = InstanceStatus(name='active')
            active_status.save()

        suspended_status = InstanceStatus.objects.filter(
            name='suspended').last()
        if not suspended_status:
            suspended_status = InstanceStatus(name='suspended')
            suspended_status.save()

        self.provider = provider
        self.active_status = active_status
        self.suspended_status = suspended_status
Beispiel #34
0
 def test_feedback_email(self):
     force_authenticate(self.request, user=UserFactory())
     with mock.patch(
             "api.v2.views.email.email_support") as mock_email_support:
         response = self.view(self.request)
         mock_email_support.assert_called_once()
         self.assertEquals(response.status_code, 200)
Beispiel #35
0
    def setUpHatefulComment(self):
        """
        Custom setup
        """
        self.annotators = sorted(UserFactory.create_batch(5),
                                 key=lambda x: x.username)

        label_article(self.annotators[0],
                      self.article,
                      is_interesting=True,
                      comments=[
                          ["HATE", "MUJER"],
                          [],
                          [],
                      ])

        label_article(self.annotators[1],
                      self.article,
                      is_interesting=True,
                      comments=[
                          ["HATE", "MUJER", "ASPECTO"],
                          [],
                          [],
                      ])

        label_article(self.annotators[3],
                      self.article,
                      is_interesting=True,
                      comments=[
                          [],
                          [],
                          ["HATE", "OTROS"],
                      ])
def step_impl(context):
    context.client = Client()
    user = UserFactory.create(username='******', is_staff=True, is_superuser=True)
    user.set_password('lenards')
    user.save()
    with modify_settings(AUTHENTICATION_BACKENDS={
        'prepend': 'django.contrib.auth.backends.ModelBackend',
        'remove': ['django_cyverse_auth.authBackends.MockLoginBackend']
    }):
        context.admin_user = user
        context.client.login(username='******', password='******')

    user_1 = UserFactory.create(username='******')
    context.user_1 = user_1
    user_2 = UserFactory.create(username='******')
    context.user_2 = user_2
Beispiel #37
0
    def test_image_and_instance_scripts_are_included(self):
        user = UserFactory.create()
        instance = InstanceFactory.create(created_by=user)

        # Create/add instance script
        instance_script = BootScriptRawTextFactory.create(created_by=user,
                                                          wait_for_deploy=True)
        instance.scripts.add(instance_script)

        # Create/add image script
        image_script = BootScriptRawTextFactory.create(created_by=user,
                                                       wait_for_deploy=True)
        application_version = instance.source.providermachine.application_version
        application_version.boot_scripts.add(image_script)

        # Mock out ansible_deployment to verify its called with both image and
        # instance scripts
        with mock.patch(
                'service.deploy.ansible_deployment') as ansible_deployment:
            from service.deploy import user_deploy
            user_deploy(instance.ip_address, user.username,
                        instance.provider_alias)
            kwargs = ansible_deployment.call_args[1]
            script_titles = {
                s['name']
                for s in kwargs['extra_vars']['DEPLOY_SCRIPTS']
            }
            self.assertIn(instance_script.get_title_slug(), script_titles)
            self.assertIn(image_script.get_title_slug(), script_titles)
Beispiel #38
0
    def test_upload_gpx_creates_trackpoints(self):
        with self.settings(MEDIA_ROOT=self.temp_dir):
            test_file = SimpleUploadedFile('test1.gpx', GPX_BIN)
            assert len(ActivityTrackpoint.objects.all()) == 0

            ActivityTrack.create_new(
                upfile=test_file,
                activity=Activity.objects.create(user=UserFactory.create()))
            assert len(ActivityTrackpoint.objects.all()) == 5

            first = ActivityTrackpoint.objects.first()
            last = ActivityTrackpoint.objects.last()

            assert my_round(first.lat) == 43.078
            assert my_round(first.lon) == -89.384
            assert first.sog == 0.0
            assert first.timepoint.month == 3
            assert first.timepoint.day == 16
            assert first.timepoint.hour == 17
            assert first.timepoint.second == 56

            assert my_round(last.lat) == 43.074
            assert my_round(last.lon) == -89.380
            assert my_round(last.sog) == 2.847
            assert last.timepoint.month == 3
            assert last.timepoint.day == 16
            assert last.timepoint.hour == 17
            assert last.timepoint.second == 57
    def __init__(self):

        self.user = UserFactory.create()
        provider_type = ProviderType(name='Test_%s' % self.user.username)
        provider_type.save()
        platform_type = PlatformType(
            name='test-platform-%s' % self.user.username
        )
        platform_type.save()
        provider = Provider(
            location='BIO5', type=provider_type, virtualization=platform_type
        )
        provider.save()

        active_status = InstanceStatus.objects.filter(name='active').last()
        if not active_status:
            active_status = InstanceStatus(name='active')
            active_status.save()

        suspended_status = InstanceStatus.objects.filter(name='suspended'
                                                        ).last()
        if not suspended_status:
            suspended_status = InstanceStatus(name='suspended')
            suspended_status.save()

        self.provider = provider
        self.active_status = active_status
        self.suspended_status = suspended_status
Beispiel #40
0
    def test_upload_sbn_creates_trackpoints(self):
        with self.settings(MEDIA_ROOT=self.temp_dir):
            test_file = SimpleUploadedFile('test1.sbn', SBN_BIN)
            assert 0 == len(ActivityTrackpoint.objects.all())

            ActivityTrack.create_new(
                upfile=test_file,
                activity=Activity.objects.create(user=UserFactory.create()))

            assert 4 == len(ActivityTrackpoint.objects.all())

            first = ActivityTrackpoint.objects.first()
            last = ActivityTrackpoint.objects.last()

            assert my_round(first.lat) == 43.087
            assert my_round(first.lon) == -89.389
            assert my_round(first.sog) == 3.11
            assert first.timepoint.month == 7
            assert first.timepoint.day == 15
            assert first.timepoint.hour == 22
            assert first.timepoint.second == 54
            assert my_round(last.lat) == 43.087
            assert my_round(last.lon) == -89.389
            assert my_round(last.sog) == 3.420
            assert last.timepoint.month == 7
            assert last.timepoint.day == 15
            assert last.timepoint.hour == 22
            assert last.timepoint.second == 57
Beispiel #41
0
    def test_resource_request_email(self):
        """
        Assert general expected behavior of resource_request_email
        """
        user = UserFactory(
            username="******",
            first_name="First",
            last_name="Last",
            email="*****@*****.**"
        )

        # Mock out a request
        request = mock.Mock()
        request.user = user
        request.POST = {}
        request.session = None

        with mock.patch('core.tasks.EmailMessage') as MockMessage, \
                override_settings(ATMO_SUPPORT=('Support', '*****@*****.**')):
            resource_request_email(
                request, user.username, "All the resources", "Did I stutter?"
            )
            kwargs = MockMessage.call_args[1]

            # Assert that Django's EmailMessage is called with the right
            # paramaters
            # Note: We are not testing the body of the email here
            MockMessage.assert_called_with(
                cc=None,
                to=['Support <*****@*****.**>'],
                subject='Atmosphere Resource Request - user0',
                from_email='First Last <*****@*****.**>',
                body=kwargs['body']
            )
    def test_image_and_instance_scripts_are_included(self):
        user = UserFactory.create()
        instance = InstanceFactory.create(created_by=user)

        # Create/add instance script
        instance_script = BootScriptRawTextFactory.create(
            created_by=user, wait_for_deploy=True
        )
        instance.scripts.add(instance_script)

        # Create/add image script
        image_script = BootScriptRawTextFactory.create(
            created_by=user, wait_for_deploy=True
        )
        application_version = instance.source.providermachine.application_version
        application_version.boot_scripts.add(image_script)

        # Mock out ansible_deployment to verify its called with both image and
        # instance scripts
        with mock.patch(
            'service.deploy.ansible_deployment'
        ) as ansible_deployment:
            from service.deploy import user_deploy
            user_deploy(
                instance.ip_address, user.username, instance.provider_alias
            )
            kwargs = ansible_deployment.call_args[1]
            script_titles = {
                s['name']
                for s in kwargs['extra_vars']['DEPLOY_SCRIPTS']
            }
            self.assertIn(instance_script.get_title_slug(), script_titles)
            self.assertIn(image_script.get_title_slug(), script_titles)
 def test_create_event(self):
     event_count = EventTable.objects.count()
     self.assertEqual(event_count, 0)
     user = UserFactory.create()
     alloc_src = AllocationSource.objects.create(
         name='DefaultAllocation', compute_allowed=1000
     )    # UUID assigned by default.
     UserAllocationSource.objects.create(
         user=user, allocation_source=alloc_src
     )
     event_payload = {
         'allocation_source_id': str(alloc_src.uuid),
         'compute_used':
             100.00,    # 100 hours used ( a number, not a string!)
         'global_burn_rate': 2.00,    # 2 hours used each hour
     }
     new_event = EventTable.create_event(
         name='allocation_source_snapshot',
         payload=event_payload,
         entity_id=str(alloc_src.uuid)
     )
     event_count = EventTable.objects.count()
     self.assertEqual(event_count, 2)
     events = EventTable.objects.all()
     self.assertEqual(new_event, events[1])
     self.assertEqual(events[0].name, 'allocation_source_threshold_met')
     self.assertEqual(events[0].entity_id, str(alloc_src.uuid))
     self.assertEqual(
         events[0].payload, {
             'actual_value': 10,
             'allocation_source_id': str(alloc_src.uuid),
             'threshold': 10
         }
     )
def create_admin_and_two_regular_users(context):
    context.client = Client()
    user = UserFactory.create(username='******', is_staff=True, is_superuser=True)
    user.set_password('lenards')
    user.save()
    with modify_settings(AUTHENTICATION_BACKENDS={
        'prepend': 'django.contrib.auth.backends.ModelBackend',
        'remove': ['django_cyverse_auth.authBackends.MockLoginBackend']
    }):
        context.admin_user = user
        context.client.login(username='******', password='******')

    user_1 = UserFactory.create(username='******')
    context.user_1 = user_1
    user_2 = UserFactory.create(username='******')
    context.user_2 = user_2
Beispiel #45
0
 def setUp(self):
     self.anonymous_user = AnonymousUserFactory()
     self.user = UserFactory.create(username='******')
     self.provider = ProviderFactory.create()
     self.user_identity = IdentityFactory.create_identity(
         created_by=self.user,
         provider=self.provider)
     self.group = Group.objects.get(name=self.user)
     self.project = ProjectFactory.create(owner=self.group)
     self.leadership = LeadershipFactory.create(
         user=self.user,
         group=self.group
     )
     self.machine = ProviderMachineFactory.create_provider_machine(self.user, self.user_identity)
     self.active_instance = InstanceFactory.create(name="Instance in active",
                                provider_alias=uuid.uuid4(),
                                source=self.machine.instance_source,
                                created_by=self.user,
                                created_by_identity=self.user_identity,
                                start_date=timezone.now())
     self.project_instances = ProjectInstanceFactory.create(project=self.project, instance=self.active_instance)
     self.view = ProjectInstanceViewSet.as_view({'get': 'list'})
     factory = APIRequestFactory()
     url = reverse('api:v2:projectinstance-list')
     url_proj = "?project__id=" + str(self.project.id)
     url += url_proj
     self.request = factory.get(url)
Beispiel #46
0
 def setup_method(self, method):
     """
     Setup method run after each test.
     Creates a user and saves its token.
     """
     self.user = UserFactory()
     self.token = Token.objects.get(user_id=self.user.user_id)
Beispiel #47
0
    def setUp(self):
        factory = APIRequestFactory()
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.provider = ProviderFactory.create()
        self.user_identity = IdentityFactory.create_identity(
            created_by=self.user, provider=self.provider
        )
        self.private_image = ImageFactory.create(
            created_by=self.user, private=True
        )
        self.private_version = ApplicationVersionFactory.create_version(
            self.user, self.user_identity, application=self.private_image
        )
        self.private_machine = ProviderMachineFactory.create_provider_machine(
            self.user,
            self.user_identity,
            application=self.private_image,
            version=self.private_version
        )

        self.staff_user = UserFactory.create(is_staff=True)
        self.staff_user_identity = IdentityFactory.create_identity(
            created_by=self.staff_user, provider=self.provider
        )
        self.public_image = ImageFactory.create(
            created_by=self.staff_user, private=False
        )
        self.public_version = ApplicationVersionFactory.create_version(
            self.staff_user,
            self.staff_user_identity,
            application=self.public_image
        )
        self.public_machine = ProviderMachineFactory.create_provider_machine(
            self.staff_user,
            self.staff_user_identity,
            application=self.public_image,
            version=self.public_version
        )

        self.list_view = ViewSet.as_view({'get': 'list'})
        list_url = reverse(self.url_route + '-list')
        self.list_request = factory.get(list_url)

        self.detail_view = ViewSet.as_view({'get': 'retrieve'})
        detail_url = reverse(self.url_route + '-detail', args=(self.user.id, ))
        self.detail_request = factory.get(detail_url)
 def setUp(self):
     self.anonymous_user = AnonymousUserFactory()
     self.username = "******"
     self.password = "******"
     self.user = UserFactory.create(username=self.username)
     self.user.set_password(self.password)
     self.user.save()
     self.auth_url = "/auth"
Beispiel #49
0
    def setUp(self):
        self.view = UserViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()

        factory = APIRequestFactory()
        url = reverse('api:v2:atmosphereuser-detail', args=(self.user.id,))
        self.request = factory.get(url)
Beispiel #50
0
    def setUp(self):
        self.tag = TagFactory.create()
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.staff_user = UserFactory.create(is_staff=True)
        self.updated_tag_data = {
            'name': 'new-tag-name',
            'description': 'new tag description'
        }

        self.factory = APIRequestFactory()
        self.url = reverse('api:v2:tag-detail', args=(self.tag.id,))
        self.request = self.factory.put(self.url, {
            'name': self.updated_tag_data['name'],
            'description': self.updated_tag_data['description']
        })

        self.view = TagViewSet.as_view({'put': 'update'})
Beispiel #51
0
 def test_validate_account(self, cassette):
     """Test for a valid account based on the business logic assigned by Jetstream"""
     from jetstream.plugins.auth.validation import XsedeProjectRequired
     jetstream_auth_plugin = XsedeProjectRequired()
     user = UserFactory.create(username='******')
     with freezegun.freeze_time('2016-09-15T05:00:00Z'):
         is_jetstream_valid = jetstream_auth_plugin.validate_user(user)
     self.assertTrue(is_jetstream_valid)
     assert_cassette_playback_length(cassette, 2)
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.project = ProjectFactory.build(owner=self.group)

        self.view = ProjectViewSet.as_view({"post": "create"})
        self.factory = APIRequestFactory()
        self.url = reverse("api:v2:project-list")
        self.request = self.factory.post(self.url, {"name": self.project.name, "description": self.project.description})
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.staff_user = UserFactory.create(is_staff=True)

        self.platform_type = PlatformTypeFactory.create()

        factory = APIRequestFactory()

        self.detail_view = ViewSet.as_view({'get': 'retrieve'})
        detail_url = reverse(
            self.url_route+'-detail', args=(self.platform_type.id,))
        self.detail_request = factory.get(detail_url)

        self.list_view = ViewSet.as_view({'get': 'list'})
        list_url = reverse(
            self.url_route+'-list')
        self.list_request = factory.get(list_url)
    def setUp(self):
        self.view = ViewSet.as_view({'get': 'retrieve'})
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()

        self.image = ImageFactory.create(created_by=self.user)

        factory = APIRequestFactory()
        url = reverse('api:v2:application-detail', args=(self.user.id,))
        self.request = factory.get(url)
 def setUp(self):
     self.anonymous_user = AnonymousUserFactory()
     self.user = UserFactory.create()
     self.group = GroupFactory.create(name=self.user.username)
     self.group.user_set.add(self.user)
     self.provider = ProviderFactory.create(location="mock location", type__name="mock")
     self.view = TokenUpdateViewSet.as_view({'post': 'create'})
     self.identity_view = IdentityViewSet.as_view({'get': 'retrieve'})
     self.credentials_view = CredentialViewSet.as_view({'get': 'list'})
     self.token_uuid = "test-token-1234-debug"
Beispiel #56
0
    def test_user_allocation_source_assigned(self):
        new_allocation_source = {
            'source_id': str(uuid.uuid4()),
            'name': 'TestAllocationSourceAssociateScenario',
            'compute_allowed': 50000
        }
        new_event = EventTable.create_event(name='allocation_source_created',
                                            payload=new_allocation_source,
                                            entity_id=new_allocation_source['source_id'])
        user = UserFactory.create()
        new_user_allocation_source = {
            'source_id': new_allocation_source['source_id'],
            'username': user.username
        }

        # Make sure no allocation_source_assigned event for this user and source exists
        event_count_before = EventTable.objects.filter(
            name='user_allocation_source_assigned',
            payload__username=user.username,
            payload__source_id=new_user_allocation_source['source_id']
        ).count()
        self.assertEqual(event_count_before, 0)

        # Make sure that no Allocation Source and User combination exists
        user_allocation_source_count_before = UserAllocationSource.objects.filter(
            allocation_source__source_id=new_user_allocation_source['source_id'],
            user=user).count()
        self.assertEqual(user_allocation_source_count_before, 0)

        # Add an event 'allocation_source_created' with our test source name
        new_event = EventTable.create_event(name='user_allocation_source_assigned',
                                            payload=new_user_allocation_source,
                                            entity_id=new_user_allocation_source['username'])

        # Make sure we added the event successfully
        event_count_after = EventTable.objects.filter(
            name='user_allocation_source_assigned',
            payload__username=user.username,
            payload__source_id=new_user_allocation_source['source_id']
        ).count()
        self.assertEqual(event_count_after, 1)

        # Make sure that there is now an Allocation Source with the test name
        user_allocation_source_count_after = UserAllocationSource.objects.filter(
            allocation_source__source_id=new_user_allocation_source['source_id'],
            user=user).count()
        self.assertEqual(user_allocation_source_count_after, 1)

        user_allocation_source = UserAllocationSource.objects.filter(
            allocation_source__source_id=new_user_allocation_source['source_id'],
            user=user).first()
        self.assertEqual(user_allocation_source.allocation_source.compute_allowed,
                         new_allocation_source['compute_allowed'])
        self.assertEqual(user_allocation_source.allocation_source.source_id, new_allocation_source['source_id'])
        self.assertEqual(user_allocation_source.allocation_source.name, new_allocation_source['name'])
Beispiel #57
0
def create_user_with_username(context, username):
    context.client = Client()
    user = UserFactory.create(username=username, is_staff=False, is_superuser=False)
    user.set_password(username)
    user.save()
    with modify_settings(AUTHENTICATION_BACKENDS={
        'prepend': 'django.contrib.auth.backends.ModelBackend',
        'remove': ['django_cyverse_auth.authBackends.MockLoginBackend']
    }):
        context.user = user
        context.client.login(username=username, password=username)
    def setUp(self):
        self.anonymous_user = AnonymousUserFactory()
        self.user = UserFactory.create()
        self.group = GroupFactory.create(name=self.user.username)
        self.project = ProjectFactory.create(owner=self.group)

        self.not_user = UserFactory.create()
        self.not_group = GroupFactory.create(name=self.not_user.username)
        self.not_project = ProjectFactory.create(owner=self.not_group)

        self.updated_project_data = {"name": "updated name", "description": "updated description"}

        self.factory = APIRequestFactory()
        self.url = reverse("api:v2:project-detail", args=(self.project.id,))
        self.request = self.factory.put(
            self.url,
            {"name": self.updated_project_data["name"], "description": self.updated_project_data["description"]},
        )

        self.view = ProjectViewSet.as_view({"put": "update"})