Exemplo n.º 1
0
    def test_get_users(self):
        user = user_api.save_user('testuser1', 'http://placehold.it/40x40')
        user = user_api.save_user('testuser2', 'http://placehold.it/20x20')
        user = user_api.save_user('testuser1', 'http://placehold.it/40x40')

        user_list = user_api.get_users()
        self.assertEqual(len(user_list), 2)
Exemplo n.º 2
0
 def test_create_partner_with_user(self):
     user = user_api.save_user('testuser', 'http://placehold.it/40x40', '*****@*****.**')
     partner = user_api.create_partner('testparnter', user_uri=user['uri'])
     self.assertIn('name', partner)
     self.assertEquals('testparnter', partner['name'])
     self.assertEquals(1, len(partner['user']))
     self.assertEquals(user['username'], partner['user'][0]['username'])
Exemplo n.º 3
0
def become( request, username ):
    if settings.DEBUG:
        request.session['user'] = p2pu_user_api.save_user(
            username,
            'http://placehold.it/40x40',
            '*****@*****.**' % username,
        )
    return http.HttpResponseRedirect(reverse('landing'))
Exemplo n.º 4
0
    def test_save_user(self):
        user = user_api.save_user('testuser', 'http://placehold.it/40x40')
        self.assertIn('username', user)
        self.assertIn('uri', user)
        self.assertIn('image_url', user)

        self.assertEqual(user['username'], 'testuser')
        self.assertEqual(user['uri'], '/uri/user/testuser')
        self.assertEqual(user['image_url'], 'http://placehold.it/40x40')
Exemplo n.º 5
0
    def test_project_feedback_cycle(self):
        # create badge
        badge = badge_api.create_badge(**self.badge_values)
        badge_api.publish_badge(badge['uri'])
        user = p2pu_user_api.save_user('badgemaker', 'http://placeholdit.com/40x40', '*****@*****.**')

        # create project
        project_values = self.project_values.copy()
        project_values['badge_uri'] = badge['uri']
        project = project_api.create_project(**project_values)

        # get feedback - has to be zero, there was not any feedback submitted yet
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 0)

        # test that project can be revised - it can not, there has not been feedback given yet
        self.assertFalse(project_api.can_revise_project(project['uri']))

        # test that error is raised when revision is given - it has to be, there was no feedback given yet
        with self.assertRaises(Exception):
            project_api.revise_project(project['uri'], 'All better')

        # test that project is ready for feedback
        self.assertTrue(project_api.ready_for_feedback(project['uri']))

        # submit feedback
        project_api.submit_feedback(project['uri'], '/uri/user/badgemaker', 'Ugly', 'Bad', 'Good')
        project_feedback = project_api.get_project_feedback(project['uri'])

        self.assertEqual(len(project_feedback), 1)
        self.assertIn('good', project_feedback[0])
        self.assertIn('bad', project_feedback[0])
        self.assertIn('ugly', project_feedback[0])
        self.assertIn('expert_uri', project_feedback[0])

        # test that multiple feedback cannont be submitted without a revision
        #self.assertFalse(project_api.ready_for_feedback(project['uri']))
        #with self.assertRaises(Exception):
        #    project_api.submit_feedback(project['uri'], '/uri/user/badgemaker', 'Ugly', 'Bad', 'Good')

        project_api.revise_project(project['uri'], 'everything is better now!!')
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 2)

        project_api.submit_feedback(project['uri'], '/uri/user/badgemaker', 'Ugly', 'Bad', 'Good')

        project_api.revise_project(project['uri'], 'everything is better now, promise!!', work_url='http://mywork.com/new-and-improved')
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 4)
 
        self.assertIn('improvement', project_feedback[1]) 
        self.assertIn('date_created', project_feedback[1]) 
        self.assertNotIn('work_url', project_feedback[1])

        self.assertIn('improvement', project_feedback[3]) 
        self.assertIn('work_url', project_feedback[3])
Exemplo n.º 6
0
def load_test_data(data_file):
    df = open(data_file, 'r')
    root = os.path.dirname(os.path.abspath(data_file))
    test_data = simplejson.load(df)
    for badge in test_data['badges']:
        p2pu_user_api.save_user(
            p2pu_user_api.uri2username(badge['author_uri']), 
            'http://placehold.it/150x150',
            '*****@*****.**' % p2pu_user_api.uri2username(badge['author_uri']),
        )
        with open(os.path.join(root, badge['image']), 'rb') as image_file:
            image = media_api.upload_image(
                File(image_file),
                badge['author_uri'],
                media_root=settings.MEDIA_ROOT,
                delete_original=False)

        badge['image_uri'] = image['uri']
        del badge['image']
        badge = badge_api.create_badge(**badge)
        badge_api.publish_badge(badge['uri'])
        print(badge)
    df.close()
Exemplo n.º 7
0
def redirect( request ):
    # get token
    # get username
    # redirect to final destination

    current_site = Site.objects.get_current()
    params = {
        'code': request.GET['code'],
        'grant_type': 'authorization_code',
        'client_id': settings.OAUTH_CLIENT_KEY,
        'client_secret': settings.OAUTH_CLIENT_SECRET,
        'redirect_uri': "http://{0}{1}".format(current_site.domain, reverse('oauth_redirect')),
    }

    response = requests.post(settings.OAUTH_TOKEN_URL, data=params)
    if response.status_code != 200:
        messages.error(request, _('There was a problem while trying to log in! Please try again.'))
        log.error(u'Could not authenticate with oauth provider: {0}.'.format(response.text))
        return http.HttpResponseRedirect(reverse('landing'))
    data = response.json()
    access_token = data['access_token']
    refresh_token = data['refresh_token']

    params = {
        'bearer_token': access_token,
    }

    response = requests.get(settings.OAUTH_ID_URL, params=params)
    if response.status_code != 200:
        messages.error(request, _('There was a problem while trying to log in! Please try again.'))
        log.error(u'Could not get identity from oauth provider: {0}'.format(response.text))
        return http.HttpResponseRedirect(reverse('landing'))

    username = response.json()['user']
    email = response.json()['email']
    #TODO user_url = response.json()['url']
    image_url = response.json()['image_url']

    user = p2pu_user_api.save_user(username, image_url, email)

    request.session['user'] = user

    if request.session.get('next_url'):
        next_url = request.session.get('next_url')
        del request.session['next_url']
        return http.HttpResponseRedirect(next_url)

    return http.HttpResponseRedirect(reverse('landing'))
Exemplo n.º 8
0
    def test_expert_feedback_and_creator_revision(self):
        badge = badge_api.create_badge(**self.badge_values)
        badge_api.publish_badge(badge['uri'])
        user = p2pu_user_api.save_user('badgemaker', 'http://placeholdit.com/40x40', '*****@*****.**')

        project_values = self.project_values.copy()
        project_values['badge_uri'] = badge['uri']
        project = project_api.create_project(**project_values)

        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 0)
        
        with self.assertRaises(Exception):
            project_api.submit_feedback(project['uri'], '/uri/user/not_an_expert', 'Ugly', 'Bad', 'Good')

        project_api.submit_feedback(project['uri'], badge['author_uri'], 'Ugly', 'Bad', 'Good')
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 1)
Exemplo n.º 9
0
    def test_final_feedback(self):
        badge = badge_api.create_badge(**self.badge_values)
        badge_api.publish_badge(badge['uri'])
        user = p2pu_user_api.save_user('badgemaker', 'http://placeholdit.com/40x40', '*****@*****.**')

        project_values = self.project_values.copy()
        project_values['badge_uri'] = badge['uri']
        project = project_api.create_project(**project_values)

        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 0)
        
        self.assertTrue(project_api.ready_for_feedback(project['uri']))
        project_api.submit_feedback(project['uri'], badge['author_uri'], 'Ugly', 'Bad', 'Good', True)
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 1)

        self.assertFalse(project_api.ready_for_feedback(project['uri']))
        self.assertFalse(project_api.can_revise_project(project['uri']))
Exemplo n.º 10
0
def redirect( request ):
    # get token
    # get username
    # redirect to final destination

    params = {
        'code': request.GET['code'],
        'grant_type': 'authorization_code',
        'client_id': settings.OAUTH_CLIENT_KEY,
        'client_secret': settings.OAUTH_CLIENT_SECRET,
        'redirect_uri': "http://localhost:8000{0}".format(reverse('oauth_redirect')),
    }

    response = requests.post(settings.OAUTH_TOKEN_URL, data=params)
    if response.status_code != 200:
        raise Exception('Could not authenticate with oauth provider')
    data = response.json()
    access_token = data['access_token']
    refresh_token = data['refresh_token']

    params = {
        'bearer_token': access_token,
    }

    response = requests.get(settings.OAUTH_ID_URL, params=params)
    if response.status_code != 200:
        raise Exception('Could not get identity from oauth provider')

    username = response.json()['user']
    #TODO user_url = response.json()['url']
    user_image_url = response.json()['image_url']

    request.session['user'] = p2pu_user_api.save_user(username, image_url)

    if request.session.get('next_url'):
        next_url = request.session.get('next_url')
        del request.session['next_url']
        return http.HttpResponseRedirect(next_url)

    return http.HttpResponseRedirect(reverse('landing'))
Exemplo n.º 11
0
 def test_get_user(self):
     user = user_api.save_user('testuser', '/media/images/test.png')
     user2 = user_api.get_user(user['uri'])
     self.assertEqual(user, user2)
Exemplo n.º 12
0
 def setUp(self):
     self.user = save_user('testuser', 'http://placehold.it', '*****@*****.**')
Exemplo n.º 13
0
 def test_create_partner_without_user(self):
     user = user_api.save_user('testuser', 'http://placehold.it/40x40', '*****@*****.**')
     partner = user_api.create_partner('testparnter')
     self.assertIn('name', partner)
     self.assertEquals('testparnter', partner['name'])
     self.assertEquals([], partner['user'])
Exemplo n.º 14
0
 def _create_user(self, username):
     user = save_user(username=username, image_url=self._get_image(),
                      email='*****@*****.**')
     return user