예제 #1
0
파일: tests.py 프로젝트: xueyanmu/tribe
    def testRejectInvite(self):
        """
        Test that one user rejecting elimintes the invite.

        The user objects returned should each have no relationship with each other after an
        invite + reject.
        """
        c1 = TestApiClient()
        c1.client.login(username=self.u1, password=self.p1)
        r1 = c1.post('/api/v1/user/invite',
                     format="json",
                     data={'email': self.e2})
        self.assertValidJSONResponse(r1)

        c2 = TestApiClient()
        c2.client.login(username=self.u2, password=self.p2)
        r2 = c2.post('/api/v1/user/reject',
                     format="json",
                     data={'email': self.e1})
        self.assertValidJSONResponse(r2)

        self.assertListEqual(list(get_collaborators(self.owner)), [])
        self.assertListEqual(list(get_collaborators(self.other)), [])
        self.assertListEqual(list(get_invites(self.owner)), [])
        self.assertListEqual(list(get_inviteds(self.other)), [])
예제 #2
0
    def setUp(self):
        self.api_client = TestApiClient()
        self.username = '******'
        self.password = '******'

        # create a user
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='Tian',
            last_name='Gan',
            superuser=False,
            password=self.password,
            groups=[]
        )

        # create a resource
        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'My resource'
        )

        # create a group
        self.group = hydroshare.create_group(
            'Test group',
            members=[],
            owners=[self.user1]
        )
예제 #3
0
    def setUp(self):
        super(ContactResourceTestCase, self).setUp()

        # Define new account test and create it.
        register_user(self)

        # Define variable to use requests properly
        self.client = TestApiClient()

        # Create and save new department for testing
        self.department_1 = Department.objects.create(name='department_1')

        # Create and save new employee for testing
        self.employee_1 = Employee.objects.create(first_name='John',
                                                  last_name='Cena',
                                                  birthday='1964-01-05',
                                                  email='*****@*****.**',
                                                  status=1,
                                                  department=self.department_1)

        # Create and save new contact for testing
        self.contact_1 = Contact.objects.create(name='contact_1',
                                                employee=self.employee_1)

        # Define api url for get and post method
        self.api_url = '/api/v1/contact/'

        # Define data for POST method
        self.post_data = {
            'name': 'test contact',
            'employee': '/api/v1/employee/{0}/'.format(self.employee_1.pk)
        }
예제 #4
0
 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}
    def setUp(self):
        self.user_resource = UserResource()
        self.user_resource_uri = self.user_resource.get_resource_uri()

        self.client = TestApiClient()

        super(BaseResourceTestCase, self).setUp()
예제 #6
0
 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}
예제 #7
0
 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', '*****@*****.**',
                                          'secret')
     self.user.is_staff = True  #someone has to be responsible
     self.user.save()
     self.usertwo = User.objects.create_user('yoko', '*****@*****.**',
                                             'secret')
     self.userthree = User.objects.create_user('ringo',
                                               '*****@*****.**',
                                               '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
예제 #8
0
파일: tests.py 프로젝트: xueyanmu/tribe
    def testLoggingOutViaAPI(self):
        """
        Check logging out via API method. Check both the user object and
        genesets.
        """
        client = TestApiClient()

        # Log in
        client.post('/api/v1/user/login',
                    format="json",
                    data={
                        'username': self.username,
                        'password': self.password
                    })

        # Now, log out
        client.post('/api/v1/user/logout', format="json", data={})

        # Check for access to that user object
        resp = client.get('/api/v1/user', format="json")
        self.assertValidJSONResponse(resp)
        self.assertEqual(self.deserialize(resp)['objects'], [])

        # Also check access that there is no access to user geneset
        r2 = client.get('/api/v1/geneset', format="json")
        self.assertValidJSONResponse(r2)
        self.assertEqual(self.deserialize(r2)['objects'], [])
예제 #9
0
    def setUp(self):
        self.api_client = TestApiClient()
        self.username = '******'
        self.password = '******'
        self.user = UserFactory(username=self.username, password=self.password)

        self.get_credentials()

        # Setup Mara
        self.co_master = SMVETreeCOMaseterFactory()
        timestamp = datetime(2014, 1, 1, 12, 30, 0)
        self.event = self.co_master.dis[0].events.create(timestamp=timestamp,
                                                         q=0,
                                                         value=0)
        self.detail_url = reverse('api_dispatch_detail',
                                  kwargs={
                                      'pk': self.event.pk,
                                      'resource_name': 'event',
                                      'api_name': 'v1'
                                  })

        self.list_url = reverse('api_dispatch_list',
                                kwargs={
                                    'api_name': 'v1',
                                    'resource_name': 'event'
                                })
예제 #10
0
 def setUp(self):
     super(LocationResourceTest, self).setUp()
     self.ap_client = TestApiClient()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(self.username, '*****@*****.**',
                                          self.password)
     self.user2 = User.objects.create_user("test2", "*****@*****.**",
                                           "test2")
     self.story = create_story(title="Test Story",
                               summary="Test Summary",
                               byline="Test Byline",
                               status="published",
                               language="en",
                               author=self.user)
     self.location_attrs = [{
         "name": "The Piton Foundation",
         "address": "370 17th St",
         "address2": "#5300",
         "city": "Denver",
         "state": "CO",
         "postcode": "80202",
     }, {
         'name': "The Hull House",
         'address': "800 S. Halsted St.",
         "city": "Chicago",
         "state": "IL",
         "postcode": "60607",
     }, {
         'name': "Bucktown-Wicker Park Library",
         'address': "1701 North Milwaukee Ave.",
         'city': "Chicago",
         'state': "IL",
         'postcode': "60647",
     }]
예제 #11
0
 def setUp(self):
     self.api_client = TestApiClient()
     self.post_id = 1
     self.post_data = {'post': {'pk': self.post_id, 'text': 'New comment'}}
     self.detail_url = '/api/v1/comment/{0}/'.format(self.post_id)
     self.list_url = '/api/v1/comment/'
     self.serializer = Serializer()
예제 #12
0
    def setUp(self):
        super(EmployeeResourceTestCase, self).setUp()

        # Define new account test and create it.
        register_user(self)

        # Define variable to use requests properly
        self.client = TestApiClient()

        # Create and save new department for testing
        self.department_1 = Department.objects.create(name='department_1')

        # Create and save new employee for testing
        self.employee_1 = Employee.objects.create(first_name='John', last_name='Cena', birthday='1964-01-05', email='*****@*****.**', status=1, department=self.department_1)

        # Define api url for get and post method
        self.api_url = '/api/v1/employee/'
        self.api_url_custom = '/api/v1/custom_employee/'

        # Define data for POST method
        self.post_data = {
            'first_name': 'Cori',
            'last_name': 'Lanyon',
            'birthday': '6/28/1909',
            'email': '*****@*****.**',
            'status': 1,
            'department': '/api/v1/department/{0}/'.format(self.department_1.pk)
        }
예제 #13
0
    def setUp(self):
        # Generic
        self.api_client = TestApiClient()
        self.serializer = Serializer()

        # API List data
        self.list_url = '/api/v1/post/'

        # API requests data
        self.project_part_id = 1
        self.post_id = 1
        self.detail_url = '/api/v1/post/{0}/'.format(self.post_id)
        self.project_part_query = '='.join(
            ['?project_part', str(self.project_part_id)])
        self.post_data = {
            'content': 'My post',
            'project_part': {
                'pk': self.project_part_id
            }
        }

        # Open API request data
        self.open_project_part_id = 2
        self.open_post_id = 2
        self.open_detail_url = '/api/v1/post/{0}/'.format(self.open_post_id)
        self.open_project_part_query = '='.join(
            ['?project_part', str(self.open_project_part_id)])
        self.open_post_data = {
            'content': 'My post',
            'project_part': {
                'pk': self.open_project_part_id
            }
        }
예제 #14
0
 def setUp(self):
     super(HandleBounces, self).setUp()
     call_command('loaddata', 'example_data', verbosity=0)
     self.api_client = TestApiClient()
     self.user = User.objects.get(id=1)
     self.outbound_message = OutboundMessage.objects.get(id=1)
     self.identifier = OutboundMessageIdentifier.objects.get(outbound_message=self.outbound_message)
예제 #15
0
파일: tests.py 프로젝트: xueyanmu/tribe
    def testCreatingGenesetNotLoggedIn(self):
        """
        Test that this fails and returns an Unauthorized response
        """

        client = TestApiClient()

        post_geneset_data = {
            # Does not need user info because the API automatically gathers that from the request
            'title': 'TestGeneset2',
            'organism': '/api/v1/organism/h**o-sapiens',
            'abstract': 'Second test geneset created by user.',
            'public': False,
            'annotations': {
                55982: [20671152, 19583951],
                18091: [8887666],
                67087: [],
                22410: []
            },
            'xrdb': 'Entrez',
            'description': 'First version.',
        }

        # Try to create a geneset without being logged in, check for Unauthorized response
        r1 = client.post('/api/v1/geneset',
                         format="json",
                         data=post_geneset_data)
        self.assertHttpUnauthorized(r1)
예제 #16
0
    def setUp(self):
        super(Partner_v1__PhotoResourceTest, self).setUp()
        # we need a custom serializer for multipart uploads
        self.api_client = TestApiClient(serializer=MultipartSerializer())
        self.api_key = 'key123_partner'
        self.api_secret = 'sec123_partner'

        self.api_account_1 = ApiAccount.objects.all()[0]
        self.events = Event.objects.filter(
            account__api_account=self.api_account_1)
        self.photos = Photo.objects.filter(
            event__account__api_account=self.api_account_1)
        self.photo_1 = self.photos[0]

        # The data we'll send on POST requests
        filename = 'trashcat.jpg'
        filepath = os.path.join(settings.PROJECT_PATH, 'api', 'assets',
                                filename)
        f = open(filepath, 'rb')

        self.post_data = {
            'event': '/partner_v1/event/{0}/'.format(self.events[0].pk),
            'caption': 'My super awesome caption!',
            'image': {
                'filename': filename,
                'data': f.read(),
            }
        }
예제 #17
0
    def test_delete_queue_item(self):
        """ Performs DELETE request to queue id 2"""
        client = TestApiClient()

        response = client.delete('/api/queue/2/', data={'format': 'json'})

        # 204 == Action Performed -> No Data
        self.assertEqual(response.status_code, 204)
예제 #18
0
    def test_put_queue(self):
        """ Performs PUT request for queue id=2"""
        client = TestApiClient()

        response = client.put('/api/queue/2/', data={'place': 990})

        # 204 == Action Performed -> No Data
        self.assertEqual(response.status_code, 204)
예제 #19
0
    def setUp(self):
        super(ApiTestCase, self).setUp()
        self.user = User.objects.create_user(username='******',
                                                password='******',
                                                email='*****@*****.**')
        Election.objects.filter(owner=self.user).delete()
        self.not_user = User.objects.create_user(username='******',
                                                password='******',
                                                email='*****@*****.**')
        self.election, created = Election.objects.get_or_create(name='BarBaz',
                                                            owner=self.user,
                                                            slug='barbaz',
                                                            published=True)
        self.election.category_set.all().delete()
        self.election.personaldata_set.all().delete()
        self.personal_data1 = PersonalData.objects.create(label=u"Age", election=self.election)
        self.personal_data2 = PersonalData.objects.create(label=u"Profession", election=self.election)

        self.category1 = Category.objects.create(name=u"Pets and phisicians", election=self.election, slug="pets")
        self.category2 = Category.objects.create(name=u"language problemas ", election=self.election, slug="language")
        self.question1 = Question.objects.create(category=self.category1, question=u"¿Cuál es el nombre de la ferocidad?")
        self.answer1 = Answer.objects.create(caption=u"Fiera", question=self.question1)
        self.answer2 = Answer.objects.create(caption=u"Ratón inteligente pero barza", question=self.question1)
        self.question2 = Question.objects.create(category=self.category1, question=u"¿Which one is your favourite colour?")
        self.answer3 = Answer.objects.create(caption=u"apple", question=self.question2)
        self.answer4 = Answer.objects.create(caption=u"orange", question=self.question2)
        self.question3 = Question.objects.create(category=self.category2, question=u"¿!¿Why don't you speak proper english?!?")
        self.answer5 = Answer.objects.create(caption=u"Hablo inglés perfectamente", question=self.question3)
        self.answer6 = Answer.objects.create(caption=u"I don't speak any english", question=self.question3)

        self.election2, created = Election.objects.get_or_create(name='BarBaz2',
                                                            owner=self.not_user,
                                                            slug='barbaz2',
                                                            published=True)
        self.candidate = Candidate.objects.create(
                                                            name='Bar Baz',
                                                            election=self.election)
        self.candidate.associate_answer(self.answer2)

        self.age1 = PersonalDataCandidate.objects.create(personal_data=self.personal_data1, candidate=self.candidate, value=u"2")
        self.profession1 = PersonalDataCandidate.objects.create(personal_data=self.personal_data2, candidate=self.candidate, value=u"Perro")
        self.candidate2 = Candidate.objects.create(
                                                            name='Fieri',
                                                            election=self.election)
        self.candidate3  = Candidate.objects.create(
                                                            name='Ratón 1',
                                                            election=self.election2)
        self.candidate3.personal_data.all().delete()
        self.election3, created = Election.objects.get_or_create(name='BarBaz3',
                                                            owner=self.user,
                                                            slug='barbaz3',
                                                            published=True)
        self.ferocious_link, created = Link.objects.get_or_create(
                                                    name='@fiera',
                                                    url='http://www.twitter.com/fiera',
                                                    candidate=self.candidate2)
        self.api_client = TestApiClient()
        self.data = {'format': 'json', 'username': self.user.username, 'api_key':self.user.api_key.key}
 def setUp(self):
     self.api_client = TestApiClient()
     self.user = hydroshare.create_account(
         '*****@*****.**',
         username='******',
         first_name='User_FirstName',
         last_name='User_LastName',
     )
     self.url_base = '/hsapi/capabilities/'
 def setUp(self):
     self.api_client = TestApiClient()
     user = hydroshare.create_account(
         '*****@*****.**',
         username='******',
         first_name='User0_FirstName',
         last_name='User0_LastName',
     )
     self.res = hydroshare.create_resource('GenericResource', user, 'myres')
예제 #22
0
 def setUp(self):
     super(HelpResourceTest, self).setUp()
     # TODO: If we end up supporting the PATCH method, use our
     # FixedTestApiClient instead of the default
     self.api_client = TestApiClient()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(self.username, '*****@*****.**',
                                          self.password)
예제 #23
0
    def test_put_vars(self):
        """ Performs PUT request for vars id=1"""

        client = TestApiClient()

        response = client.put('/api/variables/1/', data={'values_used': 150})

        # 204 == Action Performed -> No Data
        self.assertEqual(response.status_code, 204)
예제 #24
0
    def test_put_vars_for_current(self):
        """ Performs PUT request for mag-current value """

        client = TestApiClient()

        response = client.put('/api/variables/2/', data={'values_used': 215})

        # 204 == Action Performed -> No Data
        self.assertEqual(response.status_code, 204)
예제 #25
0
def test_api(username, password):
    api_client = TestApiClient()
    result = api_client.client.login(username=username, password=password)
    #print(api_client.get('http://localhost:8000/sensorimotordb/api/v1/visuomotor_classification_analysis_results/?analysis__experiment=73', format='json'))
    start = time.time()
    #print(api_client.get('http://localhost:8000/sensorimotordb/api/v1/full_recording_trial/?condition__in=432,433,437,438,442,443,434,439,444,430,435,440,431,436,441&limit=0', format='json'))
    #print(api_client.get('http://localhost:8000/sensorimotordb/api/v1/full_recording_trial/?unit_recordings__unit=518&limit=0', format='json'))
    print(api_client.get('http://localhost:8000/sensorimotordb/api/v1/event/?trial__condition__experiment=108', format='json'))
    end = time.time()
    print(end - start)
예제 #26
0
    def testGETInvite(self):
        """
        Test GET invite with a logged in user.

        Only POST is allowed, so this should return 405.
        """
        client = TestApiClient()
        client.client.login(username=self.u1, password=self.p1)
        resp = client.get('/api/v1/user/invite', format="json", data={'email': self.e2})
        self.assertHttpMethodNotAllowed(resp)
예제 #27
0
 def setUp(self):
     super(PublicMessagesInAPI, 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.writeitinstance.config.moderation_needed_in_all_messages = True
     self.writeitinstance.config.save()
     self.person1 = Person.objects.get(id=1)
     self.api_client = TestApiClient()
     self.data = {'format': 'json', 'username': self.user.username, 'api_key': self.user.api_key.key}
    def __init__(self, *args, **kwargs):

        connections.all = lambda: []

        super(DjangularTestCase, self).__init__(*args, **kwargs)

        self._api_client = TestApiClient()

        # Show complete difference on assertEqual failure.
        self.maxDiff = None
예제 #29
0
파일: tests.py 프로젝트: xueyanmu/tribe
    def testCheckAuthorizationNotLoggedIn(self):
        """
        Check that a user has access to NO user objects if they are not logged
        in.
        """
        client = TestApiClient()
        resp = client.get('/api/v1/user', format="json")

        self.assertValidJSONResponse(resp)
        self.assertEqual(self.deserialize(resp)['objects'], [])
예제 #30
0
파일: tests.py 프로젝트: xueyanmu/tribe
    def testInviteNoContent(self):
        """
        Test invite with a logged in user but no content.

        The user object should be returned without any invites.
        """
        client = TestApiClient()
        client.client.login(username=self.u1, password=self.p1)
        resp = client.post('/api/v1/user/invite', format="json")
        self.assertValidJSONResponse(resp)
        self.assertEqual(self.deserialize(resp)['invites'], [])