• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python test.TestApiClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tastypie.test.TestApiClient的典型用法代码示例。如果您正苦于以下问题:Python TestApiClient类的具体用法?Python TestApiClient怎么用?Python TestApiClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TestApiClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: CheckTokenTest

class CheckTokenTest(ResourceTestCase):
    def setUp(self):
        super(CheckTokenTest, self).setUp()

        self.client = TestApiClient()

        self.endpoint = '/api/v1/token/'
        self.format = 'json'

        # Create one user
        self.user = User(username="testuser")
        self.user.save()

        # Create on token
        self.token = UserToken(user=self.user)
        self.token.save()

    # check for the token ttl
    def test_check_token(self):
        url = "%s?token=%s" % (self.endpoint, self.token.token)
        request = self.client.get(url, self.format)
        self.assertValidJSONResponse(request)

    # check for the WRONG token ttl
    def test_check_wrong_token(self):
        url = "%s?token=%s" % (self.endpoint, "not-a-valid-token")
        self.assertHttpUnauthorized(self.client.get(url, self.format))

    # check for the NO token ttl
    def test_check_no_token(self):
        self.assertHttpUnauthorized(self.client.get(self.endpoint, self.format))
开发者ID:ncc-unesp,项目名称:goo-server,代码行数:31,代码来源:tests.py


示例2: HandleBounces

class HandleBounces(ResourceTestCase):
    def setUp(self):
        super(HandleBounces, self).setUp()
        call_command('loaddata', 'example_data', verbosity=0)
        self.api_client = TestApiClient()
        self.user = User.objects.all()[0]
        self.outbound_message = OutboundMessage.objects.all()[0]
        self.identifier = OutboundMessageIdentifier.objects.get(outbound_message=self.outbound_message)

    def get_credentials(self):
        credentials = self.create_apikey(username=self.user.username, api_key=self.user.api_key.key)
        return credentials

    def test_handle_bounces_endpoint(self):
        url = '/api/v1/handle_bounce/'
        bounce_data = {
        'key':self.identifier.key
        }
        resp = self.api_client.post(url, data=bounce_data, authentication=self.get_credentials())
        self.assertHttpCreated(resp)

    def test_handle_bounces_sets_the_contact_to_bounced(self):
        url = '/api/v1/handle_bounce/'
        bounce_data = {
        'key':self.identifier.key
        }
        resp = self.api_client.post(url, data=bounce_data, authentication=self.get_credentials())


        self.assertTrue(self.outbound_message.contact.is_bounced)
开发者ID:Hutspace,项目名称:write-it,代码行数:30,代码来源:handle_bounces_test.py


示例3: CreateOrListGroupsTest

class CreateOrListGroupsTest(ResourceTestCase):
    serializer = Serializer()
    def setUp(self):

        self.api_client = TestApiClient()

        self.user = hydroshare.create_account(   
            '[email protected]',
            username='user0',
            first_name='User0_FirstName',
            last_name='User0_LastName',
            superuser=True,
            password='foobar'
        )

        g0=hydroshare.create_group(name="group0")
        g1=hydroshare.create_group(name="group1")
        g2=hydroshare.create_group(name="group2")
        self.user.groups.add(g0,g1,g2)
        self.g_ids=[g0.id,g1.id,g2.id]
            
        self.groups_url_base = '/hsapi/groups/'
        self.api_client.client.login(username=self.user.username, password=self.user.password)

    def tearDown(self):
        Group.objects.all().delete()
        User.objects.all().delete()

    def test_create_group(self):
        post_data = {'name': 'newgroup'}

        resp = self.api_client.post(self.groups_url_base, data=post_data)

        self.assertHttpCreated(resp)
        
        grouplist = Group.objects.all() 
        num_of_groups=len(grouplist)
        
        self.assertTrue(any(Group.objects.filter(name='newgroup')))
        self.assertEqual(num_of_groups, 4)

    def test_list_groups(self):

        query = self.serialize({'user': self.user.id})  

        get_data = {'query': query}

        resp = self.api_client.get(self.groups_url_base, data=get_data)
        print resp
        self.assertEqual(resp.status_code, 200)

        groups = self.deserialize(resp)
        
        new_ids = []
        for num in range(len(groups)):
            new_ids.append(groups[num]['id'])
            self.assertTrue(Group.objects.filter(user='user{0}'.format(num)).exists())
            self.assertEqual(str(groups[num]['name']), 'group{0}'.format(num))c

        self.assertEqual(sorted(self.g_ids), sorted(new_ids))
开发者ID:hydroshare,项目名称:hs_core,代码行数:60,代码来源:test_create_or_list_groups.py


示例4: ApplicationTest

class ApplicationTest(ResourceTestCase):
    def setUp(self):
        super(ApplicationTest, self).setUp()

        self.client = TestApiClient()

        self.endpoint = '/api/v1/apps/'
        self.format = 'json'

        # Create one user
        self.user = User(username="testuser")
        self.user.save()

        # Create on token
        self.token = UserToken(user=self.user)
        self.token.save()

    # list apps
    def test_get_apps(self):
        url = "%s?token=%s" % (self.endpoint, self.token.token)
        request = self.client.get(url, self.format)
        self.assertValidJSONResponse(request)

    # list apps details
    def test_get_apps_details(self):
        app_id = Application.objects.all()[0].id
        url = "%s%d/?token=%s" % (self.endpoint, app_id, self.token.token)
        request = self.client.get(url, self.format)
        self.assertValidJSONResponse(request)
开发者ID:ncc-unesp,项目名称:goo-server,代码行数:29,代码来源:tests.py


示例5: PersonResourceTestCase

class PersonResourceTestCase(ResourceTestCase):
    def setUp(self):
        super(PersonResourceTestCase, self).setUp()
        call_command('loaddata', 'example_data', verbosity=0)
        self.user = User.objects.get(id=1)
        self.writeitinstance = WriteItInstance.objects.create(name=u"a test", slug=u"a-test", owner=self.user)
        self.api_client = TestApiClient()

        self.data = {'format': 'json', 'username': self.user.username, 'api_key': self.user.api_key.key}

    def get_credentials(self):
        credentials = self.create_apikey(username=self.user.username, api_key=self.user.api_key.key)
        return credentials

    def test_get_list_of_messages(self):
        url = '/api/v1/person/'
        response = self.api_client.get(url, authentication=self.get_credentials())

        self.assertValidJSONResponse(response)

        persons = self.deserialize(response)['objects']
        self.assertEqual(len(persons), Person.objects.count())  # All the instances

    def test_unauthorized_list_of_persons(self):
        url = '/api/v1/person/'
        response = self.api_client.get(url)

        self.assertHttpUnauthorized(response)

    def test_the_remote_url_of_the_person_points_to_its_popit_instance(self):
        url = '/api/v1/person/'
        response = self.api_client.get(url, authentication=self.get_credentials())
        persons = self.deserialize(response)['objects']
        self.assertEquals(persons[0]['popit_url'], persons[0]['resource_uri'])
开发者ID:KohoVolit,项目名称:write-it,代码行数:34,代码来源:person_resource_test.py


示例6: setUp

    def setUp(self):
        #Tastypie stuff
        super(TestDeploymentResource, self).setUp()

        self.bob_api_client = TestApiClient()
        self.bill_api_client = TestApiClient()
        self.anon_api_client = TestApiClient()

        # Create a user bob.
        self.user_bob_username = 'bob'
        self.user_bob_password = 'bob'
        self.user_bob = User.objects.create_user(self.user_bob_username,
                                                 '[email protected]',
                                                 self.user_bob_password)

        # Create a user bob.
        self.user_bill_username = 'bill'
        self.user_bill_password = 'bill'
        self.user_bill = User.objects.create_user(self.user_bill_username,
                                                  '[email protected]',
                                                  self.user_bill_password)

        self.bob_api_client.client.login(username='bob', password='bob')
        self.bill_api_client.client.login(username='bill', password='bill')

        #assign users to the Public group
        public_group, created = Group.objects.get_or_create(name='Public')
        self.user_bob.groups.add(public_group)
        self.user_bill.groups.add(public_group)
        guardian.utils.get_anonymous_user().groups.add(public_group)

        #make a couple of campaigns and save
        self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1)
        self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2)

        #make a deployments
        self.deployment_bobs = mommy.make_recipe('catamidb.Deployment1',
                                                 id=1,
                                                 campaign=self.campaign_bobs)
        self.deployment_bills = mommy.make_recipe('catamidb.Deployment2',
                                                  id=2,
                                                  campaign=self.campaign_bills)

        #assign this one to bob
        authorization.apply_campaign_permissions(
            self.user_bob, self.campaign_bobs)

        #assign this one to bill
        authorization.apply_campaign_permissions(self.user_bill,
                                                 self.campaign_bills)

        #the API url for deployments
        self.deployment_url = '/api/dev/deployment/'

        #some post data for testing deployment creation
        self.post_data = {
            'type': 'AUV',
            'operator': 'XXX',
        }
开发者ID:catami,项目名称:catami,代码行数:59,代码来源:tests.py


示例7: setUp

    def setUp(self):
        #Tastypie stuff
        super(TestCampaignResource, self).setUp()

        self.bob_api_client = TestApiClient()
        self.bill_api_client = TestApiClient()
        self.anon_api_client = TestApiClient()

        # Create a user bob.
        self.user_bob_username = 'bob'
        self.user_bob_password = 'bob'
        self.user_bob = User.objects.create_user(self.user_bob_username,
                                                 '[email protected]',
                                                 self.user_bob_password)

        # Create a user bob.
        self.user_bill_username = 'bill'
        self.user_bill_password = 'bill'
        self.user_bill = User.objects.create_user(self.user_bill_username,
                                                  '[email protected]',
                                                  self.user_bill_password)

        self.bob_api_client.client.login(username='bob', password='bob')
        self.bill_api_client.client.login(username='bill', password='bill')

        #assign users to the Public group
        public_group, created = Group.objects.get_or_create(name='Public')
        self.user_bob.groups.add(public_group)
        self.user_bill.groups.add(public_group)
        guardian.utils.get_anonymous_user().groups.add(public_group)

        #make a couple of campaigns and save
        self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1)
        self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2)

        #assign this one to bob
        authorization.apply_campaign_permissions(
            self.user_bob, self.campaign_bobs)

        #assign this one to bill
        authorization.apply_campaign_permissions(
            self.user_bill, self.campaign_bills)

        #the API url for campaigns
        self.campaign_url = '/api/dev/campaign/'

        #some post data for testing campaign creation
        self.post_data = {
            'short_name': 'Blah',
            'description': 'Blah',
            'associated_researchers': 'Blah',
            'associated_publications': 'Blah',
            'associated_research_grant': 'Blah',
            'date_start': '2012-05-01',
            'date_end': '2012-05-01',
            'contact_person': 'Blah',
        }
开发者ID:acfrmarine,项目名称:squidle,代码行数:57,代码来源:tests.py


示例8: setUp

    def setUp(self):
        # Tastypie stuff
        super(TestCameraResource, self).setUp()

        self.bob_api_client = TestApiClient()
        self.bill_api_client = TestApiClient()
        self.anon_api_client = TestApiClient()

        # Create a user bob.
        self.user_bob_username = "bob"
        self.user_bob_password = "bob"
        self.user_bob = User.objects.create_user(self.user_bob_username, "[email protected]", self.user_bob_password)

        # Create a user bob.
        self.user_bill_username = "bill"
        self.user_bill_password = "bill"
        self.user_bill = User.objects.create_user(
            self.user_bill_username, "[email protected]", self.user_bill_password
        )

        self.bob_api_client.client.login(username="bob", password="bob")
        self.bill_api_client.client.login(username="bill", password="bill")

        # assign users to the Public group
        public_group, created = Group.objects.get_or_create(name="Public")
        self.user_bob.groups.add(public_group)
        self.user_bill.groups.add(public_group)
        guardian.utils.get_anonymous_user().groups.add(public_group)

        # make a couple of campaigns and save
        self.campaign_bobs = mommy.make_one("catamidb.Campaign", id=1)
        self.campaign_bills = mommy.make_one("catamidb.Campaign", id=2)

        # make a deployments
        self.deployment_bobs = mommy.make_recipe("catamidb.Deployment1", id=1, campaign=self.campaign_bobs)
        self.deployment_bills = mommy.make_recipe("catamidb.Deployment2", id=2, campaign=self.campaign_bills)

        # make images
        self.image_bobs = mommy.make_recipe("catamidb.Image1", id=1, deployment=self.deployment_bobs)

        self.image_bills = mommy.make_recipe("catamidb.Image2", id=2, deployment=self.deployment_bills)

        # make cameras
        self.camera_bobs = mommy.make_one("catamidb.Camera", id=1, image=self.image_bobs)
        self.camera_bills = mommy.make_one("catamidb.Camera", id=2, image=self.image_bills)

        # assign this one to bob
        authorization.apply_campaign_permissions(self.user_bob, self.campaign_bobs)

        # assign this one to bill
        authorization.apply_campaign_permissions(self.user_bill, self.campaign_bills)

        # the API url for deployments
        self.camera_url = "/api/dev/camera/"

        # some post data for testing camera creation
        self.post_data = []
开发者ID:stevenvandervalk,项目名称:benthobox,代码行数:57,代码来源:tests.py


示例9: RefTSGetSites

class RefTSGetSites(ResourceTestCase):

    def setUp(self):
        self.serializer = Serializer()
        self.logger = logging.getLogger(__name__)

        self.api_client = TestApiClient()

        self.client = Client()

        self.username = 'creator'
        self.password = 'mybadpassword'

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        # create a user to be used for creating the resource
        self.user_creator = hydroshare.create_account(
            '[email protected]',
            username=self.username,
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            password=self.password,
            groups=[self.group]
        )

        self.wsdl_url_swe = "http://hydroportal.cuahsi.org/SwedishMonitoringData/webapp/cuahsi_1_1.asmx?WSDL"
        self.wsdl_url_wwo = "http://worldwater.byu.edu/app/index.php/default/services/cuahsi_1_1.asmx?WSDL"
        self.rest_url = "http://worldwater.byu.edu/interactive/sandbox/services/index.php/cuahsi_1_1.asmx/GetValues?location=WWO:S-PRHD&variable=WWO:JSWL&startDate=&endDate="
        self.site_code_swe = "wq2371"
        self.site_code_wwo = "S-PRHD"

        self.post_data = {
            'title': 'My REST API-created resource',
            'resource_type': 'GenericResource'
        }

    def tearDown(self):
        User.objects.all().delete()
        GenericResource.objects.all().delete()

    #TODO: This throws an encoding error...
    # def test_get_sites_wwo(self):
    #     resp = self.api_client.get("/hsapi/_internal/search-sites/?wsdl_url="+self.wsdl_url_wwo)
    #     self.assertEqual(resp.status_code, 200)

    def test_get_sites_swedish(self):
        resp = self.api_client.get("/hsapi/_internal/search-sites/?url="+self.wsdl_url_swe)
        self.assertEqual(resp.status_code, 200)

    def test_get_variables_wwo(self):
        resp = self.api_client.get("/hsapi/_internal/search-variables/?url="+self.wsdl_url_wwo+"&site="+self.site_code_wwo)
        self.assertEqual(resp.status_code, 200)
        self.assertTrue('Water level' in resp.content)
开发者ID:kob-aha,项目名称:hydroshare,代码行数:54,代码来源:test_ref_ts_views.py


示例10: RefTSSnotel

class RefTSSnotel(ResourceTestCase):

    def setUp(self):
        self.serializer = Serializer()
        self.logger = logging.getLogger(__name__)

        self.api_client = TestApiClient()

        self.client = Client()

        self.username = 'creator'
        self.password = 'mybadpassword'

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        # create a user to be used for creating the resource
        self.user_creator = hydroshare.create_account(
            '[email protected]',
            username=self.username,
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            password=self.password,
            groups=[self.group]
        )

        self.wsdl_url = "http://worldwater.byu.edu/interactive/snotel/services/index.php/cuahsi_1_1.asmx?WSDL"
        self.rest_url = "http://worldwater.byu.edu/interactive/snotel/services/index.php/cuahsi_1_1.asmx/GetValuesObject?location=SNOTEL:1039&variable=SNOTEL:WTEQ&startDate=2014-10-01&endDate=2015-03-19"
        self.time_series_base_rest = "/hsapi/_internal/time-series-from-service/?ref_type=rest&service_url="
        self.time_series_base_soap = "/hsapi/_internal/time-series-from-service/?ref_type=soap&service_url="
        self.site_code_swe = "wq2371"
        self.site_code_wwo = "S-PRHD"

        self.post_data = {
            'title': 'My REST API-created resource',
            'resource_type': 'GenericResource'
        }

    def tearDown(self):
        User.objects.all().delete()
        GenericResource.objects.all().delete()

    def test_time_series_from_service_rest(self):
        url = urllib.quote(self.rest_url)
        resp = self.api_client.get(self.time_series_base_rest+url)
        self.assertEqual(resp.status_code, 200)
        self.assertTrue('visualization' in resp.content)

    def test_time_series_from_service_soap(self):
        url = urllib.quote(self.wsdl_url)
        resp = self.api_client.get(self.time_series_base_soap+url+"&site=823&variable=WTEQ")
        self.assertEqual(resp.status_code, 200)
        self.assertTrue('visualization' in resp.content)
开发者ID:kob-aha,项目名称:hydroshare,代码行数:53,代码来源:test_ref_ts_views.py


示例11: JobTest

class JobTest(ResourceTestCase):
    def setUp(self):
        super(JobTest, self).setUp()

        self.client = TestApiClient()

        self.endpoint = '/api/v1/jobs/'
        self.format = 'json'

        # Create one user
        self.user = User(username="testuser")
        self.user.save()

        # Create on token
        self.token = UserToken(user=self.user)
        self.token.save()

        # create a job
        self.job = Job(user=self.user, application=Application.objects.all()[0])
        self.job.save()

    def test_get_job_list(self):
        url = "%s?token=%s" % (self.endpoint, self.token.token)
        request = self.client.get(url, self.format)
        self.assertValidJSONResponse(request)

    def test_get_job_detail(self):
        url = "%s%d/?token=%s" % (self.endpoint, self.job.id, self.token.token)
        request = self.client.get(url, self.format)
        self.assertValidJSONResponse(request)

    def test_post_job(self):
        data = {"application" : "/api/v1/apps/1/"}
        url = "%s?token=%s" % (self.endpoint, self.token.token)
        self.assertHttpCreated(self.client.post(url, self.format, data=data))

    def test_patch_job(self):
        job = Job(user=self.user, application=Application.objects.all()[0])
        job.save()
        data = {"progress":"50"}
        url = "%s%d/?token=%s" % (self.endpoint, job.id, self.token.token)
        resp = self.client.patch(url, self.format, data=data)
        self.assertHttpAccepted(resp)

    def test_delete_job(self):
        job = Job(user=self.user, application=Application.objects.all()[0])
        job.save()
        url = "%s%d/?token=%s" % (self.endpoint, job.id, self.token.token)
        self.assertHttpAccepted(self.client.delete(url, self.format))
开发者ID:ncc-unesp,项目名称:goo-server,代码行数:49,代码来源:tests.py


示例12: setUp

    def setUp(self):
        self.serializer = Serializer()
        self.logger = logging.getLogger(__name__)

        self.api_client = TestApiClient()

        self.client = Client()

        self.username = 'creator'
        self.password = 'mybadpassword'

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        # create a user to be used for creating the resource
        self.user_creator = hydroshare.create_account(
            '[email protected]',
            username=self.username,
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            password=self.password,
            groups=[self.group]
        )

        self.wsdl_url_swe = "http://hydroportal.cuahsi.org/SwedishMonitoringData/webapp/cuahsi_1_1.asmx?WSDL"
        self.wsdl_url_wwo = "http://worldwater.byu.edu/app/index.php/default/services/cuahsi_1_1.asmx?WSDL"
        self.rest_url = "http://worldwater.byu.edu/interactive/sandbox/services/index.php/cuahsi_1_1.asmx/GetValues?location=WWO:S-PRHD&variable=WWO:JSWL&startDate=&endDate="
        self.site_code_swe = "wq2371"
        self.site_code_wwo = "S-PRHD"

        self.post_data = {
            'title': 'My REST API-created resource',
            'resource_type': 'GenericResource'
        }
开发者ID:kob-aha,项目名称:hydroshare,代码行数:34,代码来源:test_ref_ts_views.py


示例13: setUp

 def setUp(self):
     super(PagePaginationTestCase, self).setUp()
     call_command('loaddata', 'example_data', verbosity=0)
     self.user = User.objects.get(id=1)
     # self.writeitinstance = WriteItInstance.objects.create(name="a test", slug="a-test", owner=self.user)
     self.api_client = TestApiClient()
     self.data = {'format': 'json', 'username': self.user.username, 'api_key': self.user.api_key.key}
开发者ID:ciudadanointeligente,项目名称:write-it,代码行数:7,代码来源:page_paginator_test.py


示例14: setUp

 def setUp(self):
     super(MessageResourceTestCase,self).setUp()
     call_command('loaddata', 'example_data', verbosity=0)
     self.user = User.objects.all()[0]
     self.writeitinstance = WriteItInstance.objects.create(name=u"a test", slug=u"a-test", owner=self.user)
     self.api_client = TestApiClient()
     self.data = {'format': 'json', 'username': self.user.username, 'api_key':self.user.api_key.key}
开发者ID:garethrees,项目名称:write-it,代码行数:7,代码来源:message_resource_test.py


示例15: setUp

    def setUp(self):
        self.logger = logging.getLogger(__name__)

        self.api_client = TestApiClient()

        self.username = "creator"
        self.password = "mybadpassword"

        # create a user to be used for creating the resource
        self.user_creator = hydroshare.create_account(
            "[email protected]",
            username=self.username,
            first_name="Creator_FirstName",
            last_name="Creator_LastName",
            superuser=False,
            password=self.password,
            groups=[],
        )
        self.user_url = "/hsapi/accounts/{0}/".format(self.user_creator.username)

        self.api_client.client.login(username=self.username, password=self.password)

        # create a resource
        self.resource = hydroshare.create_resource(
            resource_type="GenericResource",
            title="My resource",
            owner=self.user_creator,
            last_changed_by=self.user_creator,
        )
        self.resource_url_base = "/hsapi/resource/"
        self.resource_url = "{0}{1}/".format(self.resource_url_base, self.resource.short_id)

        self.post_data = {"title": "My REST API-created resource", "resource_type": "GenericResource"}
开发者ID:hydroshare,项目名称:hs_core,代码行数:33,代码来源:test_resource.py


示例16: setUp

 def setUp(self):
     load_states()
     load_statutes()
     settings.DEBUG = True
     self.api_client = TestApiClient()
     self.get_credentials()
     #user creates all the groups and requests initially, user should always have edit perms unless another user takes that away
     self.user = User.objects.create_user('john', '[email protected]', 'secret')
     self.user.is_staff = True#someone has to be responsible
     self.user.save()
     self.usertwo = User.objects.create_user('yoko', '[email protected]', 'secret')
     self.userthree = User.objects.create_user('ringo', '[email protected]', 'secret')
     self.post_data = {
         'name': 'A TEST GROUP'
     }
     self.up, created = UserProfile.objects.get_or_create(user=self.user)
     self.uptwo, created = UserProfile.objects.get_or_create(user=self.usertwo)
     self.upthree, created = UserProfile.objects.get_or_create(user=self.userthree)
     self.groupJSON = None
     self.group = None
     self.request = None
     self.agency = None
     self.agencyJSON = None
     self.contact = None
     self.contactJSON = None
     self.government = None
     self.governmentJSON = None
开发者ID:cirlabs,项目名称:foiamachine,代码行数:27,代码来源:user_test_base.py


示例17: setUp

    def setUp(self):
        super(MessagesPerInstanceTestCase,self).setUp()
        call_command('loaddata', 'example_data', verbosity=0)
        self.user = User.objects.all()[0]
        self.writeitinstance = WriteItInstance.objects.create(name=u"a test", slug=u"a-test", owner=self.user)
        self.api_client = TestApiClient()
        self.data = {'format': 'json', 'username': self.user.username, 'api_key':self.user.api_key.key}

        #creating messages
        self.pedro = Person.objects.all()[0]
        self.message1 = Message.objects.create(content = 'Content 1', 
            author_name='Felipe', 
            author_email="[email protected]", 
            subject='Fiera es una perra feroz', 
            writeitinstance= self.writeitinstance, 
            persons = [self.pedro])

        #Confirmating
        Confirmation.objects.create(message=self.message1)
        self.message1.recently_confirmated()
        #Confirmating

        self.marcel = Person.objects.all()[1]
        self.message2 = Message.objects.create(content = 'Content 1', 
            author_name='Felipe', 
            author_email="[email protected]", 
            subject='Fiera es una perra feroz', 
            writeitinstance= self.writeitinstance, 
            persons = [self.marcel])
        #Confirmating message 2
        Confirmation.objects.create(message=self.message2)
        self.message2.recently_confirmated()
开发者ID:garethrees,项目名称:write-it,代码行数:32,代码来源:instance_resource_test.py


示例18: GetCapabilities

class GetCapabilities(ResourceTestCase):
    serializer = Serializer()

    def setUp(self):
        self.api_client = TestApiClient()
        self.user = hydroshare.create_account(
            "[email protected]", username="user", first_name="User_FirstName", last_name="User_LastName"
        )
        self.url_base = "/hsapi/capabilities/"

    def tearDown(self):
        User.objects.all().delete()

    def test_generic(self):
        res = hydroshare.create_resource("GenericResource", self.user, "res1")
        url = "{0}{1}/".format(self.url_base, res.short_id)
        resp = self.api_client.get(url)

        self.assertValidJSONResponse(resp)

        capabilities = self.deserialize(resp)

        self.assertEqual(capabilities, None)

    def test_other_types(self):
        pass
开发者ID:hydroshare,项目名称:hs_core,代码行数:26,代码来源:test_get_capabilitites_as_view.py


示例19: setUp

 def setUp(self):
     super(AnswersResourceTestCase, self).setUp()
     call_command('loaddata', 'example_data', verbosity=0)
     self.writeitinstance = WriteItInstance.objects.get(id=1)
     self.user = User.objects.get(id=1)
     self.api_client = TestApiClient()
     self.data = {'format': 'json', 'username': self.user.username, 'api_key': self.user.api_key.key}
开发者ID:mysociety,项目名称:write-it,代码行数:7,代码来源:answer_resource_test.py


示例20: PublicMessagesInAPI

class PublicMessagesInAPI(ResourceTestCase):
    def setUp(self):
        super(PublicMessagesInAPI,self).setUp()
        call_command('loaddata', 'example_data', verbosity=0)
        self.user = User.objects.all()[0]
        self.writeitinstance = WriteItInstance.objects.create(name="a test", slug="a-test", owner=self.user)
        self.writeitinstance.moderation_needed_in_all_messages = True
        self.writeitinstance.save()
        self.person1 = Person.objects.all()[0]
        self.api_client = TestApiClient()
        self.data = {'format': 'json', 'username': self.user.username, 'api_key':self.user.api_key.key}

    def test_non_confirmated_message_not_showing_in_api(self):
        """Non confirmated message is not in the API"""

        message = Message.objects.create(content = 'Content 1', 
            author_name='Felipe', 
            author_email="[email protected]", 
            subject='public non confirmated message', 
            writeitinstance= self.writeitinstance, 
            persons = [self.person1])

        #OK this is just to show that this message is not confirmed
        self.assertFalse(message.confirmated)
        self.assertNotIn(message, Message.public_objects.all())
        #I've tested this in messages_test.py 

        url = '/api/v1/instance/{0}/messages/'.format(self.writeitinstance.id)
        response = self.api_client.get(url,data = self.data)
        self.assertValidJSONResponse(response)
        messages = self.deserialize(response)['objects']
        self.assertFalse(messages)
开发者ID:garethrees,项目名称:write-it,代码行数:32,代码来源:public_messages_test.py



注:本文中的tastypie.test.TestApiClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.dict_strip_unicode_keys函数代码示例发布时间:2022-05-27
下一篇:
Python serializers.Serializer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap