Example #1
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'])
Example #2
0
    def test_award_partner_badge_as_partne(self):

        #create a partner
        partner = p2pu_user_api.create_partner('test partner')

        # create a parnter badge
        badge_values = self.badge_values.copy()
        badge_values['partner_name'] = partner['name']
        badge =badge_api.create_badge(**badge_values)
        badge_api.publish_badge(badge['uri'])

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

        # give feedback as a partner
        feedback = project_api.submit_feedback(
            project['uri'],
            self.badge_values['author_uri'],
            'Good',
            'Bad',
            'Ugly',
            )
        self.assertEquals(feedback, project_api.submit_feedback_result.NOT_AWARDED)

        # revise feedback
        revision = project_api.revise_project(project['uri'], 'Some improvement')
        self.assertEquals('Some improvement', revision['improvement'])

        # give feedback and award a badge
        feedback = project_api.submit_feedback(
            project['uri'],
            self.badge_values['author_uri'],
            'SecondGood',
            'SecondBad',
            'SecondUgly',
            award_badge=True
        )
        self.assertEquals(feedback, project_api.submit_feedback_result.AWARDED)
Example #3
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'])
Example #4
0
    def test_badge_awarded_from_nonpartner_expert(self):
        #create a partner
        partner = p2pu_user_api.create_partner('Test parnter')

        # create partner badge
        new_badge_values = self.badge_values.copy()
        new_badge_values['partner_name'] = partner['name']

        # create a parnter badge
        badge = badge_api.create_badge(**new_badge_values)
        badge_api.publish_badge(badge['uri'])

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

        # award badge as a partner
        feedback = project_api.submit_feedback(
            project['uri'],
            badge['author_uri'],
            'Good',
            'Bad',
            'Ugly',
            award_badge=True
            )
        self.assertEquals(feedback, project_api.submit_feedback_result.AWARDED)
        # award badge
        # HACK - needs well revision on how to refactor in order to test cycle properly
        if project_api.submit_feedback_result.AWARDED:
            with patch('badge.models.send_badge_awarded_notification') as mock_notification:
                badge_api.award_badge(badge['uri'], project_values['author_uri'], badge['author_uri'], 'http://project.org/url')

        self.assertIn(project_values['author_uri'], badge_api.get_badge_experts(badge['uri']))
        # submit another project for a badge
        another_project_values = {
            'badge_uri': badge['uri'],
            'author_uri': '/uri/user/anotheruser',
            'title': 'Test Second Title',
            'image_uri': '/uri/image/2',
            'work_url': 'http://project.org/url',
            'description': 'Did the test second time',
            'reflection': 'Will not do it earlier and more next time',
            'tags': ['test', 'tdd', 'bdd'],
        }
        project = project_api.create_project(**another_project_values)

        # award badge as a non partner
        feedback = project_api.submit_feedback(
            project['uri'],
            '/uri/user/testuser',
            'Good',
            'Bad',
            'Ugly',
            award_badge=True
            )
        self.assertEquals(feedback, project_api.submit_feedback_result.REQUIRES_APPROVAL)

        # award badge as partner
        feedback = project_api.submit_feedback(
            project['uri'],
            badge['author_uri'],
            'Good',
            'Bad',
            'Ugly',
            award_badge=True
        )
        self.assertEquals(feedback, project_api.submit_feedback_result.AWARDED)

        # test that feedback can not be given anymore
        with self.assertRaises(Exception):
            project_api.submit_feedback(
                project['uri'],
                badge['author_uri'],
                'Good',
                'Bad',
                'Ugly',
                award_badge=True
            )

        # test that revision can not be given any longer either
        with self.assertRaises(Exception):
            project_api.revise_project(project['uri'], 'Some improvement')