Example #1
0
    def testStageFile(self):
        client = self._get_authenticated_client()

        staging_dir = get_full_staging_path(self.username)

        from os.path import basename
        from tempfile import NamedTemporaryFile
        with NamedTemporaryFile('w', dir=staging_dir) as f:
            # Write some content
            f.write('This is just some content')
            f.flush()

            data = [ f.name ]
            content_type = 'application/json; charset=utf-8'
            response = client.post(self._get_staging_url(),
                                   data=json.dumps(data),
                                   content_type=content_type)

            # Expect 201 Created
            expect(response.status_code).to_equal(201)
            # Expect to get the email address of
            # staging user back
            # Can't test for async file staging
            emails = json.loads(response.content)
            expect(len(emails)).to_equal(1)
Example #2
0
    def testLocalFile(self):
        content = urandom(1024)
        cf = ContentFile(content, 'background_task_testfile')

        # Create new Datafile
        datafile = Dataset_File(dataset=self.dataset)
        datafile.filename = cf.name
        datafile.size = len(content)
        datafile.sha512sum = hashlib.sha512(content).hexdigest()
        datafile.save()
        replica = Replica(datafile=datafile,
                          url=write_uploaded_file_to_dataset(self.dataset, cf),
                          location=Location.get_default_location())
        replica.save()

        def get_replica(datafile):
            return Replica.objects.get(datafile=datafile)

        # undo auto-verify:
        replica.verified = False
        replica.save(update_fields=['verified'])

        # Check that it's not currently verified
        expect(get_replica(datafile).verified).to_be(False)

        # Check it verifies
        verify_files()
        expect(get_replica(datafile).verified).to_be(True)
Example #3
0
    def testRightsRequireValidOwner(self):
        # Create test owner without enough details
        username, email, password = ("testuser", "*****@*****.**", "password")
        user = User.objects.create_user(username, email, password)

        # Create test experiment and make user the owner of it
        experiment = Experiment(title="Text Experiment", institution_name="Test Uni", created_by=user)
        experiment.save()
        acl = ObjectACL(
            pluginId=django_user,
            entityId=str(user.id),
            content_object=experiment,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ObjectACL.OWNER_OWNED,
        )
        acl.save()

        # Create client and login as user
        client = Client()
        login = client.login(username=username, password=password)
        self.assertTrue(login)

        # Get "Choose Rights" page, and check that we're forbidden
        rights_url = reverse("tardis.tardis_portal.views.choose_rights", args=[str(experiment.id)])
        response = client.get(rights_url)
        expect(response.status_code).to_equal(403)

        # Fill in remaining details
        user.first_name = "Voltaire"  # Mononymous persons are just fine
        user.save()

        # Get "Choose Rights" page, and check that we're now allowed access
        response = client.get(rights_url)
        expect(response.status_code).to_equal(200)
Example #4
0
    def testIngestedDatafileFields(self):
        import hashlib
        from tardis.tardis_portal import models

        dataset = models.Dataset.objects.get(description="Bluebird")
        datafiles = dataset.dataset_file_set.all()
        self.assertTrue(len(datafiles) == 8, "there should be 8 datafiles for the given dataset")
        datafile = datafiles.get(filename="ment0003.osc")
        self.assertTrue(datafile is not None, "datafile should not be none")
        self.assertTrue(datafile.size == "18006000", "wrong file size for ment0003.osc")
        replica = datafile.get_preferred_replica()
        expect(replica.url).to_equal("file://" + path.join(self.sync_path, "Images/ment0003.osc"))

        datafileParams = models.DatafileParameter.objects.filter(parameterset__dataset_file=datafile)

        ioBgndParam = datafileParams.get(name__name="ioBgnd")
        self.assertTrue(ioBgndParam.numerical_value == 0)

        itParam = datafileParams.get(name__name="it")
        self.assertTrue(itParam.numerical_value == 288)

        positionerStrParam = datafileParams.get(name__name="positionerString")
        self.assertTrue(positionerStrParam.string_value == "UDEF1_2_PV1_2_3_4_5")

        # Check MD5 works
        self.assertTrue(
            datafile.md5sum == "deadbeef" * (hashlib.md5("").digest_size / 4), "wrong MD5 hash for ment0003.osc"
        )

        # Check SHA-512 works
        datafile = datafiles.get(filename="ment0005.osc")
        self.assertTrue(
            datafile.sha512sum == "deadbeef" * (hashlib.sha512("").digest_size / 4),
            "wrong SHA-512 hash for ment0005.osc",
        )
Example #5
0
 def testGetRecord(self):
     ns = self.ns
     _, experiment = _create_test_data()
     args = {
         'verb': 'GetRecord',
         'metadataPrefix': 'rif',
         'identifier': 'experiment/%d' % experiment.id
     }
     response = self._client_get('/apps/oaipmh/?%s' %
                                     '&'.join(['%s=%s' % (k,v)
                                               for k,v in args.items()]))
     self.assertEqual(response.status_code, 200)
     # Check the response content is good
     xml = etree.fromstring(response.content)
     print response.content
     assert xml.xpath('/o:OAI-PMH', namespaces=ns)
     assert not xml.xpath('o:error', namespaces=ns)
     assert xml.xpath('/o:OAI-PMH/o:GetRecord/o:record', namespaces=ns)
     header, metadata = xml.xpath('/o:OAI-PMH/o:GetRecord/o:record/o:*',
                                  namespaces=ns)[0:2]
     expect(header.xpath('o:identifier/text()',namespaces=ns)[0]) \
         .to_equal('experiment/1')
     # <registryObject group="MyTARDIS Default Group">
     expect(metadata.xpath('r:registryObjects/r:registryObject/@group',
                           namespaces=ns)[0]).to_equal('MyTardis Test Group')
     self._check_experiment_regobj(experiment,
                         metadata.xpath('r:registryObjects/r:registryObject',
                                        namespaces=ns)[0])
Example #6
0
 def testForbiddenWithoutLogin(self):
     client = Client()
     response = client.get(self._get_staging_url())
     # Expect a redirect to login
     expect(response.status_code).to_equal(302)
     login_url = reverse("tardis.tardis_portal.views.login")
     ensure(login_url in response["Location"], True, "Redirect URL was not to login.")
Example #7
0
    def setUp(self):
        # Create test owner without enough details
        username, email, password = ("testuser", "*****@*****.**", "password")
        user = User.objects.create_user(username, email, password)
        # Need UserAuthentication
        UserAuthentication(userProfile=user.userprofile, username=username, authenticationMethod="localdb").save()
        # Create staging dir
        from os import path, makedirs

        staging_dir = path.join(settings.STAGING_PATH, username)
        if not path.exists(staging_dir):
            makedirs(staging_dir)
        # Ensure that staging dir is set up properly
        expect(get_full_staging_path(username)).to_be_truthy()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title="Text Experiment", institution_name="Test Uni", created_by=user)
        experiment.save()
        acl = ObjectACL(
            pluginId=django_user,
            entityId=str(user.id),
            content_object=experiment,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ObjectACL.OWNER_OWNED,
        )
        acl.save()

        self.dataset = Dataset(description="dataset description...")
        self.dataset.save()
        self.dataset.experiments.add(experiment)
        self.dataset.save()

        self.username, self.password = (username, password)
Example #8
0
    def testHandleSizing(self):
        client = Client()
        def get_with_size(sizearg):
            kwargs = {'datafile_id': self.datafile.id,
                      'region': 'full',
                      'size': sizearg,
                      'rotation': '0',
                      'quality': 'native',
                      'format': 'jpg' }
            response = client.get(reverse('tardis.tardis_portal.iiif.download_image',
                                          kwargs=kwargs))
            expect(response.status_code).to_equal(200)
            return response

        permutations = [
                        # Exact dimensions *without* aspect ratio preserved
                        {'arg': '16,16', 'width': 16, 'height': 16},
                        # Maximum dimensions (aspect ratio preserved)
                        {'arg': '!16,16', 'width': 16, 'height': 11},
                        {'arg': '!90,11', 'width': 17, 'height': 11},
                        {'arg': '!16,10', 'width': 15, 'height': 10},
                        ]
        for data in permutations:
            response = get_with_size(data['arg'])
            with Image(blob=response.content) as img:
                expect(img.width).to_equal(data['width'])
                expect(img.height).to_equal(data['height'])
Example #9
0
    def testHandleSizing(self):
        client = Client()

        def get_with_size(sizearg):
            kwargs = {
                "datafile_id": self.datafile.id,
                "region": "full",
                "size": sizearg,
                "rotation": "0",
                "quality": "native",
                "format": "jpg",
            }
            response = client.get(reverse("tardis.tardis_portal.iiif.download_image", kwargs=kwargs))
            expect(response.status_code).to_equal(200)
            return response

        permutations = [
            # Exact dimensions *without* aspect ratio preserved
            {"arg": "16,16", "width": 16, "height": 16},
            # Maximum dimensions (aspect ratio preserved)
            {"arg": "!16,16", "width": 16, "height": 11},
            {"arg": "!90,11", "width": 17, "height": 11},
            {"arg": "!16,10", "width": 15, "height": 10},
        ]
        for data in permutations:
            response = get_with_size(data["arg"])
            with Image(blob=response.content) as img:
                expect(img.width).to_equal(data["width"])
                expect(img.height).to_equal(data["height"])
Example #10
0
    def testHandleSizing(self):
        client = Client()
        def get_with_size(sizearg):
            kwargs = {'datafile_id': self.datafile.id,
                      'region': 'full',
                      'size': sizearg,
                      'rotation': '0',
                      'quality': 'native',
                      'format': 'jpg' }
            response = client.get(reverse('tardis.tardis_portal.iiif.download_image',
                                          kwargs=kwargs))
            expect(response.status_code).to_equal(200)
            return response

        permutations = [
                        # Width (aspect ratio preserved)
                        {'arg': '50,', 'width': 50, 'height': 33},
                        # Height (aspect ratio preserved)
                        {'arg': ',30', 'width': 46, 'height': 30},
                        # Percent size (aspect ratio preserved)
                        {'arg': 'pct:50', 'width': 35, 'height': 23},
                        ]
        for data in permutations:
            response = get_with_size(data['arg'])
            with Image(blob=response.content) as img:
                expect(img.width).to_equal(data['width'])
                expect(img.height).to_equal(data['height'])
Example #11
0
    def testStageFile(self):
        client = self._get_authenticated_client()

        staging_dir = get_full_staging_path(self.username)

        from os.path import basename
        from tempfile import NamedTemporaryFile
        with NamedTemporaryFile('w', dir=staging_dir) as f:
            # Write some content
            f.write('This is just some content')
            f.flush()

            data = [ f.name ]
            content_type = 'application/json; charset=utf-8'
            response = client.post(self._get_staging_url(),
                                   data=json.dumps(data),
                                   content_type=content_type)

            # Expect 201 Created
            expect(response.status_code).to_equal(201)
            # Expect to get a list of URLs back
            urls = json.loads(response.content)
            expect(len(urls)).to_equal(1)

            # Should have single staging file
            dataset = Dataset.objects.get(id=self.dataset.id)
            expect(dataset.dataset_file_set.count()).to_equal(1)
            datafile = dataset.dataset_file_set.all()[0]
            expect(datafile.filename).to_equal(basename(f.name))
            expect(urlparse(datafile.url).scheme).to_equal('')
Example #12
0
    def testHandleSizing(self):
        client = Client()

        def get_with_size(sizearg):
            kwargs = {
                "datafile_id": self.datafile.id,
                "region": "full",
                "size": sizearg,
                "rotation": "0",
                "quality": "native",
                "format": "jpg",
            }
            response = client.get(reverse("tardis.tardis_portal.iiif.download_image", kwargs=kwargs))
            expect(response.status_code).to_equal(200)
            return response

        permutations = [
            # Width (aspect ratio preserved)
            {"arg": "50,", "width": 50, "height": 33},
            # Height (aspect ratio preserved)
            {"arg": ",30", "width": 46, "height": 30},
            # Percent size (aspect ratio preserved)
            {"arg": "pct:50", "width": 35, "height": 23},
        ]
        for data in permutations:
            response = get_with_size(data["arg"])
            with Image(blob=response.content) as img:
                expect(img.width).to_equal(data["width"])
                expect(img.height).to_equal(data["height"])
Example #13
0
    def testRemoteFile(self):
            content = urandom(1024)
            with NamedTemporaryFile() as f:
                # Create new Datafile
                datafile = Dataset_File(dataset=self.dataset)
                datafile.filename = 'background_task_testfile'
                datafile.size = len(content)
                datafile.sha512sum = hashlib.sha512(content).hexdigest()
                datafile.url = 'file://' + path.abspath(f.name)
                datafile.save()

                def get_datafile(datafile):
                    return Dataset_File.objects.get(id=datafile.id)

                # Check that it won't verify as it stands
                expect(get_datafile(datafile).verified).to_be(False)
                verify_files()
                expect(get_datafile(datafile).verified).to_be(False)
                expect(get_datafile(datafile).is_local()).to_be(False)


                # Fill in the content
                f.write(content)
                f.flush()

                # Check it now verifies
                verify_files()
                expect(get_datafile(datafile).verified).to_be(True)
                expect(get_datafile(datafile).is_local()).to_be(True)
Example #14
0
    def testManageAccount(self):
        # Create test owner without enough details
        username, email, password = ("testuser", "*****@*****.**", "password")
        user = User.objects.create_user(username, email, password)
        expect(user.userprofile.isValidPublicContact()).to_be(False)

        manage_url = reverse("tardis.tardis_portal.views.manage_user_account")

        # Create client and go to account management URL
        client = Client()
        response = client.get(manage_url)
        # Expect redirect to login
        expect(response.status_code).to_equal(302)

        # Login as user
        login = client.login(username=username, password=password)
        self.assertTrue(login)

        response = client.get(manage_url)
        # Expect 200 OK and a form
        expect(response.status_code).to_equal(200)
        response.content.index('name="first_name"')
        response.content.index('name="last_name"')
        response.content.index('name="email"')
        response.content.index('value="*****@*****.**"')

        # Update account details
        response = client.post(manage_url, {"first_name": "Tommy", "email": "*****@*****.**"})
        # Expect 303 See Also redirect on update
        expect(response.status_code).to_equal(303)

        user = User.objects.get(id=user.id)
        expect(user.userprofile.isValidPublicContact()).to_be(True)
Example #15
0
 def testCanDelete(self):
     response = self.client.delete(
         reverse('tardis.apps.related_info.views.' +
                 'get_or_update_or_delete_related_info',
                 args=[self.experiment.id,
                       self._create_initial_entry()['id']]))
     expect(response.status_code).to_equal(200)
     obj = json.loads(response.content)
     expect(obj.keys()).to_be_greater_than(1)
Example #16
0
 def testInfoHasEtags(self):
     client = Client()
     for format_ in ("json", "xml"):
         kwargs = {"datafile_id": self.datafile.id, "format": format_}
         url = reverse("tardis.tardis_portal.iiif.download_info", kwargs=kwargs)
         response = client.get(url)
         expect(response.status_code).to_equal(200)
         # Check etag exists
         ensure("Etag" in response, True, "Info should have an etag")
Example #17
0
 def testMustHaveWrite(self):
     related_info_id = self._create_initial_entry()['id']
     self.acl.canWrite = False
     self.acl.save()
     response = self.client.delete(
         reverse('tardis.apps.related_info.views.' +
                 'get_or_update_or_delete_related_info',
                 args=[self.experiment.id, related_info_id]))
     expect(response.status_code).to_equal(403)
    def test_tz_naive_date_handling(self):
        """
        Ensure that dates are handling in a timezone-aware way.
        """
        psm = ParameterSetManager(parameterset=self.datafileparameterset)

        psm.new_param("parameter3", str(datetime(1970, 01, 01, 10, 0, 0)))

        expect(psm.get_param("parameter3", True))\
            .to_equal(datetime(1970, 01, 01, 0, 0, 0, tzinfo=pytz.utc))
Example #19
0
 def testGetRecord(self):
     header, metadata, about = self._getProvider().getRecord('oai_dc', \
                                                             'experiment/1')
     expect(header.identifier()).to_contain(str(self._experiment.id))
     expect(header.datestamp().replace(tzinfo=pytz.utc))\
         .to_equal(get_local_time(self._experiment.update_time))
     expect(metadata.getField('title'))\
         .to_equal([str(self._experiment.title)])
     expect(metadata.getField('description'))\
         .to_equal([str(self._experiment.description)])
     expect(about).to_equal(None)
    def test_tz_aware_date_handling(self):
        '''
        Ensure that dates are handling in a timezone-aware way.
        '''
        psm = ParameterSetManager(parameterset=self.datafileparameterset)

        psm.new_param("parameter3",
                      iso8601.parse_date('1970-01-01T08:00:00+08:00'))

        expect(psm.get_param("parameter3", True))\
            .to_equal(datetime(1970,01,01,0,0,0,tzinfo=pytz.utc))
Example #21
0
 def get_with_size(sizearg):
     kwargs = {'datafile_id': self.datafile.id,
               'region': 'full',
               'size': sizearg,
               'rotation': '0',
               'quality': 'native',
               'format': 'jpg' }
     response = client.get(reverse('tardis.tardis_portal.iiif.download_image',
                                   kwargs=kwargs))
     expect(response.status_code).to_equal(200)
     return response
Example #22
0
 def testInfoHasEtags(self):
     client = Client()
     for format_ in ('json', 'xml'):
         kwargs = {'datafile_id': self.datafile.id,
                   'format': format_ }
         url = reverse('tardis.tardis_portal.iiif.download_info',
                       kwargs=kwargs)
         response = client.get(url)
         expect(response.status_code).to_equal(200)
         # Check etag exists
         ensure('Etag' in response, True, "Info should have an etag")
Example #23
0
 def _create_initial_entry(self):
     params = {'type': 'website',
               'identifier': 'https://www.google.com/',
               'title': 'Google',
               'notes': 'This is a note.'}
     response = self.client.post(reverse('tardis.apps.related_info.views.' +
                                         'list_or_create_related_info',
                                         args=[self.experiment.id]),
                                 data=json.dumps(params),
                                 content_type='application/json')
     expect(response.status_code).to_equal(201)
     return json.loads(response.content)
Example #24
0
 def get_with_size(sizearg):
     kwargs = {
         "datafile_id": self.datafile.id,
         "region": "full",
         "size": sizearg,
         "rotation": "0",
         "quality": "native",
         "format": "jpg",
     }
     response = client.get(reverse("tardis.tardis_portal.iiif.download_image", kwargs=kwargs))
     expect(response.status_code).to_equal(200)
     return response
Example #25
0
 def testImageHasEtags(self):
     client = Client()
     kwargs = {'datafile_id': self.datafile.id,
               'region': 'full',
               'size': 'full',
               'rotation': '0',
               'quality': 'native' }
     url = reverse('tardis.tardis_portal.iiif.download_image', kwargs=kwargs)
     response = client.get(url)
     expect(response.status_code).to_equal(200)
     # Check etag exists
     ensure('Etag' in response, True, "Image should have an etag")
Example #26
0
    def test_urls_with_some_content(self):
        # Things that might tend to be in a real live system
        user = '******'
        pwd = User.objects.make_random_password()
        user = User.objects.create(username=user, email='*****@*****.**',
                                   first_name="Test", last_name="User")
        user.set_password(pwd)
        user.save()
        UserProfile(user=user).save()
        experiment = Experiment.objects.create(title="Test Experiment",
                                               created_by=user,
                                               public_access= \
                                                 Experiment.PUBLIC_ACCESS_FULL)
        experiment.save()
        acl = ExperimentACL(pluginId=django_user,
                            entityId=str(user.id),
                            experiment=experiment,
                            canRead=True,
                            canWrite=True,
                            canDelete=True,
                            isOwner=True)
        acl.save()
        dataset = Dataset(description="test dataset")
        dataset.save()
        dataset.experiments.add(experiment)
        dataset.save()


        # Test everything works
        c = Client()
        c.login(username=user, password=pwd)
        urls = [ '/about/', '/stats/']
        urls += [ '/experiment/list/%s' % part
                    for part in ('mine', 'shared', 'public')]
        urls += [ '/experiment/%s/' % part \
                    for part in ('register', 'search') ]
        urls += [ '/experiment/view/%d/' % experiment.id ]
        urls += [ '/ajax/experiment/%d/%s' % (experiment.id, tabpane) \
                    for tabpane in ('description', 'datasets', 'rights') ]
        urls += [ '/ajax/datafile_list/%d/' % dataset.id ]
        urls += [ '/ajax/dataset_metadata/%d/' % dataset.id ]

        for u in urls:
            response = c.get(u)
            ensure(response.status_code, 200,
                   "%s should have returned 200 but returned %d"\
                   % (u, response.status_code))

        redirect_urls = [ '/experiment/list', '/experiment/view/' ]

        for u in redirect_urls:
            response = c.get(u)
            expect(response.status_code).to_equal(302)
Example #27
0
 def _check_zip_file(self, content, rootdir, datafiles, 
                     simpleNames=False, noTxt=False):
     with NamedTemporaryFile('w') as tempfile:
         tempfile.write(content)
         tempfile.flush()
         # It should be a zip file
         expect(is_zipfile(tempfile.name)).to_be_truthy()
         try:
             zf = ZipFile(tempfile.name, 'r')
             self._check_names(datafiles, zf.namelist(), 
                               rootdir, simpleNames, noTxt)
         finally:
             zf.close()
Example #28
0
 def testMustHaveWrite(self):
     related_info_id = self._create_initial_entry()['id']
     self.acl.canWrite = False
     self.acl.save()
     params = {'type': 'website',
               'identifier': 'https://www.google.com/'}
     response = self.client.put(
         reverse('tardis.apps.related_info.views.' +
                 'get_or_update_or_delete_related_info',
                 args=[self.experiment.id, related_info_id]),
         data=json.dumps(params),
         content_type='application/json')
     expect(response.status_code).to_equal(403)
Example #29
0
 def _check_names(self, datafiles, names, rootdir, simpleNames, noTxt):
     # SimpleNames says if we expect basenames or pathnames
     # NoTxt says if we expect '.txt' files to be filtered out
     if not noTxt:
         expect(len(names)).to_equal(len(datafiles))
     for df in datafiles:
         if simpleNames:
             filename = df.filename
         else:
             filename = join(rootdir, str(df.dataset.id), 
                             df.filename)
         expect(filename in names).to_be(
             not (noTxt and filename.endswith('.txt')))
Example #30
0
    def testPostOnlyMethodAllowed(self):
        client = self._get_authenticated_client()

        for method in (x.lower() for x in ['GET', 'HEAD', 'PUT', 'OPTIONS']):
            response = getattr(client, method)(self._get_staging_url())
            # Expect a 405 Method Not Allowed
            expect(response.status_code).to_equal(405)
            # Expect valid "Allow" header
            response['Allow'] = 'POST'

        response = client.post(self._get_staging_url())
        # Expect something other than a 405
        self.assertFalse(response.status_code == 405)
Example #31
0
 def check_item(item):
     ensure('id' in item, True, "Missing dataset ID")
     dataset = datasets[item['id']]
     # Check attributes
     expect(item['description']).to_equal(dataset.description)
     expect(item['immutable']).to_equal(dataset.immutable)
     # todo - put ye test back
     # Check experiment list is the same
     expect(frozenset(item['experiments']))\
         .to_equal(frozenset(dataset.experiments
                             .values_list('id', flat=True)))
Example #32
0
 def testCanGetJpegFormat(self):
     client = Client()
     kwargs = {
         'datafile_id': self.datafile.id,
         'region': 'full',
         'size': 'full',
         'rotation': '0',
         'quality': 'native',
         'format': 'jpg'
     }
     response = client.get(
         reverse('tardis.tardis_portal.iiif.download_image', kwargs=kwargs))
     expect(response.status_code).to_equal(200)
     with Image(blob=response.content) as img:
         expect(img.format).to_equal('JPEG')
         expect(img.width).to_equal(self.width)
         expect(img.height).to_equal(self.height)
     # Check compliance level
     _check_compliance_level(response)
Example #33
0
def step_impl(context, type):
    code = None

    for key, name in context.clients.items():
        if name == context.name:
            code = key

    if type == 'null':
        expect(code).to_be_none()
    elif type == 'valid':
        expect(code).to_be_truthy()
    else:
        expect(True).to_equal(False)
Example #34
0
    def test_bind_two_layers(self):
        bound_before = Bound(unbound=Bound(unbound=4,
                                           annotation=ErrorType.none),
                             annotation=ErrorType.none)
        result = BindArgs(bound=8,
                          deltas=[
                              'higher deltas',
                              WrappedDelta(type=DeltaType.default, delta=True),
                              WrappedDelta(type=DeltaType.default, delta=True)
                          ])

        after = bind(bind(get_echo(result)))(BindArgs(bound=bound_before,
                                                      deltas=['higher deltas'
                                                              ]))
        outer_bound, deltas = after
        inner_bound, outer_annotation = outer_bound
        value, inner_annotation = inner_bound
        expect(outer_annotation).to_equal(ErrorType.none)
        expect(inner_annotation).to_equal(ErrorType.none)
        expect(value).to_equal(8)
        expect(deltas[0]).to_equal('higher deltas')
Example #35
0
 def testCanGetRequiredFormats(self):
     client = Client()
     # not testing jp2, as this does not work on all platforms
     for ext, format in [('jpg', 'JPEG'), ('png', 'PNG')]:
         kwargs = {
             'datafile_id': self.datafile.id,
             'region': 'full',
             'size': 'full',
             'rotation': '0',
             'quality': 'native',
             'format': ext
         }
         response = client.get(
             reverse('tardis.tardis_portal.iiif.' + 'download_image',
                     kwargs=kwargs))
         expect(response.status_code).to_equal(200)
         with Image(blob=response.content) as img:
             expect(img.format).to_equal(format)
             expect(img.width).to_equal(self.width)
             expect(img.height).to_equal(self.height)
         # Check compliance level
         _check_compliance_level(response)
Example #36
0
    def testHandlesSingleEntry(self):
        from ..views import SCHEMA_URI
        psm = ParameterSetManager(parentObject=self.experiment,
                                  schema=SCHEMA_URI)
        params = {'type': 'website',
                  'identifier': 'https://www.google.com/',
                  'title': 'Google',
                  'notes': 'This is a note.'}
        for k, v in params.items():
            psm.set_param(k, v)

        response = self.client.get(
            reverse('tardis.apps.related_info.views.' +
                    'list_or_create_related_info',
                    args=[self.experiment.id]))
        expect(response.status_code).to_equal(200)
        expect(response['Content-Type'])\
            .to_equal('application/json; charset=utf-8')

        objs = json.loads(response.content)
        expect(len(objs)).to_be(1)
        for k, v in params.items():
            expect(objs[0][k]).to_equal(v)
Example #37
0
 def testListIdentifiers(self):
     headers = self._getProvider() \
                   .listIdentifiers(self._getProviderMetadataPrefix())
     # Iterate through headers
     for header in headers:
         if header.identifier().startswith('experiment'):
             expect(header.identifier()).to_contain(str(
                 self._experiment.id))
             expect(header.datestamp().replace(tzinfo=pytz.utc))\
                 .to_equal(get_local_time(self._experiment.update_time))
     # Remove public flag
     self._experiment.public_access = Experiment.PUBLIC_ACCESS_NONE
     self._experiment.save()
     headers = self._getProvider() \
         .listIdentifiers(self._getProviderMetadataPrefix())
     # Not public, so should not appear
     expect(len(headers)).to_equal(0)
Example #38
0
def step_impl(context):
    """ Delete all shopcarts and load new ones """
    headers = {'Content-Type': 'application/json'}
    # list all of the shopcarts and delete them one by one
    context.resp = requests.get(context.base_url + '/api/shopcarts')
    expect(context.resp.status_code).to_equal(200)
    for shopcart in context.resp.json():
        context.resp = requests.delete(context.base_url + '/api/shopcarts/' +
                                       str(shopcart["id"]),
                                       headers=headers)
        expect(context.resp.status_code).to_equal(204)

    # load the database with new shopcarts
    create_url = context.base_url + '/api/shopcarts'
    for row in context.table:
        data = {"user_id": row['user']}
        payload = json.dumps(data)
        context.resp = requests.post(create_url, data=payload, headers=headers)
        expect(context.resp.status_code).to_equal(201)
Example #39
0
 def testDetectsBadInput(self):
     def do_post(params):
         return self.client.post(
             reverse('tardis.apps.related_info.views.'
                     + 'list_or_create_related_info',
                     args=[self.experiment.id]),
             data=json.dumps(params),
             content_type='application/json')
     # We need an identifier
     params = {'type': 'website'}
     response = do_post(params)
     expect(response.status_code).to_equal(400)
     # We need a type
     params = {'identifier': 'http://www.google.com/'}
     response = do_post(params)
     expect(response.status_code).to_equal(400)
     # We need an identifier and URL
     params = {'type': 'website', 'identifier': 'http://www.google.com/'}
     response = do_post(params)
     expect(response.status_code).to_equal(201)
Example #40
0
    def testImageCacheControl(self):
        client = Client()
        kwargs = {
            'datafile_id': self.datafile.id,
            'region': 'full',
            'size': 'full',
            'rotation': '0',
            'quality': 'native'
        }
        url = reverse('tardis.tardis_portal.iiif.download_image',
                      kwargs=kwargs)
        response = client.get(url)
        expect(response.status_code).to_equal(200)
        # Check etag exists
        ensure('Cache-Control' in response, True,
               "Image should have a Cache-Control header")
        ensure('max-age' in response['Cache-Control'], True,
               "Image should have a Cache-Control header")
        # By default the image is public, so
        ensure('public' in response['Cache-Control'], True,
               "Image should have a Cache-Control header")

        is_logged_in = client.login(username='******', password='******')
        expect(is_logged_in).to_be_truthy()

        experiment = self.datafile.dataset.get_first_experiment()
        experiment.public_access = Experiment.PUBLIC_ACCESS_NONE
        experiment.save()

        url = reverse('tardis.tardis_portal.iiif.download_image',
                      kwargs=kwargs)
        response = client.get(url)
        expect(response.status_code).to_equal(200)
        # Check etag exists
        ensure('Cache-Control' in response, True,
               "Image should have a Cache-Control header")
        ensure('max-age' in response['Cache-Control'], True,
               "Image should have a Cache-Control header")
        # By default the image is now private, so
        ensure('private' in response['Cache-Control'], True,
               "Image should have a Cache-Control header")
Example #41
0
    def testRequiresJSON(self):
        client = Client()

        # Login as user
        login = client.login(username=self.username, password=self.password)
        self.assertTrue(login)

        response = client.post(self._get_staging_url())
        # Expect 400 Bad Request because we didn't have a payload
        expect(response.status_code).to_equal(400)

        response = client.post(self._get_staging_url(),
                               data={'files': ['foo', 'bar']})
        # Expect 400 Bad Request because we didn't have a JSON payload
        expect(response.status_code).to_equal(400)

        response = client.post(self._get_staging_url(),
                               data=json.dumps({'files': ['foo', 'bar']}),
                               content_type='application/octet-stream')
        # Expect 400 Bad Request because we didn't have a JSON Content-Type
        expect(response.status_code).to_equal(400)
Example #42
0
    def testFlexstationSimple(self):
        """
        Simple test running the filter and making sure the Softmax version number was saved
        """
        filter = FlexstationFilter("Flexstation Test Schema",
                                   "http://rmit.edu.au/flexstation_test")
        filter.__call__(None, instance=self.datafiles[0])
        # Check a parameter set was created for the datafile
        datafile = Dataset_File.objects.get(id=self.datafiles[0].id)
        expect(datafile.getParameterSets().count()).to_equal(1)

        # Check that at least the verion number was extracted
        psm = ParameterSetManager(datafile.getParameterSets()[0])
        expect(psm.get_param('softmax_version', True)).to_equal('5.42.1.0')

        # Check we won't create a duplicate datafile
        filter = FlexstationFilter("Flexstation Test Schema",
                                   "http://rmit.edu.au/flexstation_test")
        filter.__call__(None, instance=self.datafiles[0])
        datafile = Dataset_File.objects.get(id=self.datafiles[0].id)
        expect(datafile.getParameterSets().count()).to_equal(1)
def step_impl(context):
    """ Delete all promotions and load new ones """
    headers = {"Content-Type": "application/json"}
    # Deleting the existing promotions
    context.resp = requests.get(context.base_url + "/promotions",
                                headers=headers)
    expect(context.resp.status_code).to_equal(200)
    for promo in context.resp.json():
        context.resp = requests.delete(context.base_url + "/promotions/" +
                                       str(promo["id"]),
                                       headers=headers)
        expect(context.resp.status_code).to_equal(204)

    # load the new promotions as per the Background
    create_url = context.base_url + "/promotions"
    for row in context.table:
        data = {
            "title":
            row['title'],
            "description":
            row['description'],
            "promo_code":
            row['promo_code'],
            "promo_type":
            row['promo_type'],
            "amount":
            row['amount'],
            "start_date":
            row['start_date'],
            "end_date":
            row['end_date'],
            "is_site_wide":
            row['is_site_wide'] in ['True', 'true', '1'],
            "products":
            "" if row['products'] == "" else row['products'].split(","),
        }
        payload = json.dumps(data)
        context.resp = requests.post(create_url, data=payload, headers=headers)
        expect(context.resp.status_code).to_equal(201)
    logging.info(f'Wait Seconds: {WAIT_SECONDS}')
Example #44
0
def step_impl(context):
    """ Delete all Pets and load new ones """
    headers = {'Content-Type': 'application/json'}
    # list all of the pets and delete them one by one
    context.resp = requests.get(context.base_url + '/pets', headers=headers)
    expect(context.resp.status_code).to_equal(200)
    for pet in context.resp.json():
        context.resp = requests.delete(context.base_url + '/pets/' +
                                       str(pet["_id"]),
                                       headers=headers)
        expect(context.resp.status_code).to_equal(204)

    # load the database with new pets
    create_url = context.base_url + '/pets'
    for row in context.table:
        data = {
            "name": row['name'],
            "category": row['category'],
            "available": row['available'] in ['True', 'true', '1']
        }
        payload = json.dumps(data)
        context.resp = requests.post(create_url, data=payload, headers=headers)
        expect(context.resp.status_code).to_equal(201)
Example #45
0
 def testCanCreate(self):
     params = {'type': 'website',
               'identifier': 'https://www.google.com/',
               'title': 'Google',
               'notes': 'This is a note.'}
     response = self.client.post(
         reverse('tardis.apps.related_info.views.'
                 + 'list_or_create_related_info',
                 args=[self.experiment.id]),
         data=json.dumps(params),
         content_type='application/json')
     # Check that content reports as created, returns the created object
     expect(response.status_code).to_equal(201)
     obj = json.loads(response.content)
     ensure(isinstance(obj['id'], int), True,
            message='Created object should have an ID.')
     for k, v in params.items():
         expect(obj[k]).to_equal(v)
     # Check that creation really did persist
     response = self.client.get(
         reverse('tardis.apps.related_info.views.'
                 + 'get_or_update_or_delete_related_info',
                 args=[self.experiment.id, obj['id']]))
     expect(response.status_code).to_equal(200)
Example #46
0
def step_impl(context):
    """ Delete all Products and load new ones """
    headers = {'Content-Type': 'application/json'}
    # list all of the products and delete them one by one
    context.resp = requests.get(context.base_url + '/api/products')
    expect(context.resp.status_code).to_equal(200)
    for product in context.resp.json():
        context.resp = requests.delete(context.base_url + '/api/products/' +
                                       str(product["id"]),
                                       headers=headers)
        expect(context.resp.status_code).to_equal(204)

    # load the database with new products
    create_url = context.base_url + '/api/products'
    for row in context.table:
        data = {
            "name": row['name'],
            "category": row['category'],
            "description": row['description'],
            "price": row['price'],
        }
        payload = json.dumps(data)
        context.resp = requests.post(create_url, data=payload, headers=headers)
        expect(context.resp.status_code).to_equal(201)
def step_impl(context, element_name):
    element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
    element = context.driver.find_element_by_id(element_id)
    expect(element.get_attribute('value')).to_be(u'')
def step_impl(context, message):
    """ Check the document title for a message """
    expect(context.driver.title).to_contain(message)
def step_impl(context, text, element_name):
    element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
    element = Select(context.driver.find_element_by_id(element_id))
    expect(element.first_selected_option.text).to_equal(text)
Example #50
0
def step_impl(context, text, element_name):
    element_id = 'product_' + element_name.lower()
    element = Select(context.driver.find_element_by_id(element_id))
    expect(element.first_selected_option.text).to_equal(text)
Example #51
0
def step_impl(context, element_name):
    element_id = 'product_' + element_name.lower()
    element = context.driver.find_element_by_id(element_id)
    expect(element.get_attribute('value')).to_be(u'')
Example #52
0
def step_impl(context, is_found_literal):
    is_found = (is_found_literal.lower() == 'true')
    expect(context.is_customer_found).to_equal(is_found)
Example #53
0
 def _check_experiment_regobj(self, experiment, registryObject):
     ns = self.ns
     # <key>keydomain.test.example/experiment/1</key>
     expect(registryObject.xpath('r:key/text()', namespaces=ns)[0])\
         .to_equal('keydomain.test.example/experiment/%d' % experiment.id)
     # <originatingSource>http://keydomain.test.example/</originatingSource>
     expect(registryObject.xpath('r:originatingSource/text()',
                                 namespaces=ns)[0]) \
                                 .to_equal('http://example.com/')
     # <collection type="dataset">
     expect(registryObject.xpath('r:collection/@type',
                                 namespaces=ns)[0]).to_equal('dataset')
     collection = registryObject.xpath('r:collection', namespaces=ns)[0]
     # <name type="primary">
     #     <namePart>Test</namePart>
     # </name>
     expect(collection.xpath('r:name[@type="primary"]/r:namePart/text()',
                             namespaces=ns)[0]).to_equal(experiment.title)
     # <description type="brief">Test experiment description.</description>
     expect(collection.xpath('r:description[@type="brief"]/text()',
                             namespaces=ns)[0]) \
                             .to_equal(experiment.description)
     # <location>
     #   <address>
     #     <electronic type="url">
     #       <value>http://keydomain.test.example/experiment/view/1/</value>
     #     </electronic>
     #   </address>
     # </location>
     loc_xpath = 'r:location/r:address/r:electronic[@type="url"]'\
                 +'/r:value/text()'
     expect(collection.xpath(loc_xpath, namespaces=ns)[0]) \
             .to_equal('http://example.com/experiment/view/%d/' %
                       experiment.id)
     # <rights>
     #     <accessRights>
     #         All data is publicly available online.
     #     </accessRights>
     #     <licence rightsUri="http://creativecommons.org/licenses/by-nd/2.5/au/">
     #         Creative Commons Attribution-NoDerivs 2.5 Australia
     #     </licence>
     # </location>
     expect(collection.xpath('r:rights/r:accessRights/text()',
         namespaces=ns)) \
         .to_equal(['All data is publicly available online.'])
     expect(collection.xpath('r:rights/r:licence/@rightsUri',
         namespaces=ns)) \
         .to_equal(['http://creativecommons.org/licenses/by-nd/2.5/au/'])
     expect(collection.xpath('r:rights/r:licence/text()',
         namespaces=ns)) \
         .to_equal(['Creative Commons Attribution-NoDerivs 2.5 Australia'])
     # <relatedObject>
     #     <key>user/1</key>
     #     <relation type="isManagedBy"/>
     # </relatedObjexperimentect>
     expect(collection.xpath('r:relatedObject/r:key/text()',
         namespaces=ns)) \
         .to_equal(['keydomain.test.example/user/1'])
def step_impl(context, client_name):
    expect(client_name).to.equal(context.dictionary)
Example #55
0
 def _check_user_regobj(self, user, registryObject):
     ns = self.ns
     # <key>keydomain.test.example/experiment/1</key>
     expect(registryObject.xpath('r:key/text()', namespaces=ns)[0])\
         .to_equal('keydomain.test.example/user/%d' % user.id)
     # <originatingSource>http://keydomain.test.example/</originatingSource>
     expect(registryObject.xpath('r:originatingSource/text()',
                                 namespaces=ns)[0]) \
                                 .to_equal('http://example.com/')
     # <collection type="dataset">
     expect(registryObject.xpath('r:party/@type',
                                 namespaces=ns)[0]).to_equal('person')
     collection = registryObject.xpath('r:party', namespaces=ns)[0]
     # <name type="primary">
     #     <namePart type="given">Thomas</namePart>
     #     <namePart type="family">Atkins</namePart>
     # </name>
     expect(collection.xpath('r:name[@type="primary"]/'+
                             'r:namePart[@type="given"]/text()',
                             namespaces=ns)[0]).to_equal(user.first_name)
     expect(collection.xpath('r:name[@type="primary"]/'+
                             'r:namePart[@type="family"]/text()',
                             namespaces=ns)[0]).to_equal(user.last_name)
     # <location>
     #     <address>
     #         <electronic type="email">[email protected]</electronic>
     #     </address>
     # </location>
     loc_xpath = 'r:location/r:address/r:electronic[@type="email"]'\
                 +'/r:value/text()'
     expect(collection.xpath(loc_xpath, namespaces=ns)[0]) \
             .to_equal(user.email)
     # <relatedObject>
     #     <key>user/1</key>
     #     <relation type="isManagedBy"/>
     # </relatedObjexperimentect>
     expect(collection.xpath('r:relatedObject/r:key/text()',
         namespaces=ns)) \
         .to_equal(['keydomain.test.example/experiment/1'])
def step_impl(context, price):
    expect(price).to.equal(context.price)
def step_impl(context):
    client_name = clients_list.list.get(context.id)
    expect(client_name).to_equal(context.price)
    context.dictionary = client_name
    context.price = price_list.get(context.id)
Example #58
0
    def testHandlesMultipleEntries(self):
        from ..views import SCHEMA_URI
        param_list = ({'type': 'website',
                       'identifier': 'https://www.example.test/%d' % i,
                       'title': 'Title #%d' % i,
                       'notes': 'This is note #%d.' % i} for i in range(10))
        for params in param_list:
            psm = ParameterSetManager(parentObject=self.experiment,
                                      schema=SCHEMA_URI)
            for k, v in params.items():
                psm.set_param(k, v)

        response = self.client.get(
            reverse('tardis.apps.related_info.views.'
                    + 'list_or_create_related_info',
                    args=[self.experiment.id]))
        expect(response.status_code).to_equal(200)
        expect(response['Content-Type'])\
            .to_equal('application/json; charset=utf-8')

        objs = json.loads(response.content)
        expect(len(objs)).to_be(10)

        for obj in objs:
            expect(obj['type']).to_equal('website')
            expect(obj['identifier']).to_match(r'www.example.test/\d+$')
            expect(obj['title']).to_match(r'^Title #\d+$')
            expect(obj['notes']).to_match(r'note #\d+\.$')
Example #59
0
 def testAccessWithReadPerms(self):
     response = self.client.get(
         reverse('tardis.apps.related_info.views.index',
                 args=[self.experiment.id]))
     expect(response.status_code).to_equal(200)
Example #60
0
 def testHandlesNotFound(self):
     response = self.client.get(
         reverse('tardis.apps.related_info.views.' +
                 'get_or_update_or_delete_related_info',
                 args=[self.experiment.id, 0]))
     expect(response.status_code).to_equal(404)