Example #1
0
    def test_populate_icon_from_ohloh(self):

        project = Project()
        project.name = 'Mozilla Firefox'
        project.populate_icon_from_ohloh()

        self.assert_(project.icon_raw)
        self.assertEqual(project.icon_raw.width, 64)
        self.assertNotEqual(project.date_icon_was_fetched_from_ohloh, None)
Example #2
0
    def test_populate_icon_from_ohloh(self):

        project = Project()
        project.name = 'Mozilla Firefox'
        project.populate_icon_from_ohloh()

        self.assert_(project.icon_raw)
        self.assertEqual(project.icon_raw.width, 64)
        self.assertNotEqual(project.date_icon_was_fetched_from_ohloh, None)
Example #3
0
    def test_populate_icon_from_ohloh_uses_none_on_no_match(self):

        project = Project()
        project.name = 'lolnomatchiawergh'

        project.populate_icon_from_ohloh()

        self.assertFalse(project.icon_raw)
        # We don't know how to compare this against None,
        # but this seems to work.

        self.assertNotEqual(project.date_icon_was_fetched_from_ohloh, None)
Example #4
0
    def test_populate_icon_from_ohloh_uses_none_on_no_match(self):

        project = Project()
        project.name = 'lolnomatchiawergh'

        project.populate_icon_from_ohloh()

        self.assertFalse(project.icon_raw)
        # We don't know how to compare this against None,
        # but this seems to work.

        self.assertNotEqual(project.date_icon_was_fetched_from_ohloh, None)
Example #5
0
 def test_kde(self):
     p = Project.create_dummy(name="KDE")
     f = os.path.join(settings.MEDIA_ROOT, "sample-data", "kde-117760-2010-04-09.xml")
     xml_fd = file(f)
     bug = mysite.customs.miro.xml2bug_object(xml_fd)
     self.assertEqual(bug.submitter_username, "hasso kde org")
     self.assertEqual(bug.submitter_realname, "Hasso Tepper")
Example #6
0
    def test(self):
        # Create an answer whose author isn't specified. This replicates the
        # situation where the user isn't logged in.
        p = Project.create_dummy(name='Myproject')
        q = ProjectInvolvementQuestion.create_dummy(
            key_string='where_to_start', is_bug_style=False)

        # Do a GET on the project page to prove cookies work.
        self.client.get(p.get_url())

        # POST some text to the answer creation post handler
        POST_data = {
            'project__pk': p.pk,
            'question__pk': q.pk,
            'answer__text': ("Help produce official documentation, share "
                                 "the solution to a problem, or check, proof "
                                 "and test other documents for accuracy."),
        }
        response = self.client.post(
            reverse(mysite.project.views.create_answer_do), POST_data,
            follow=True)

        # Now, the session will know about the answer, but the answer will
        # not be published. Visit the login page, assert that the page
        # contains the text of the answer.

        response = self.client.get(reverse('oh_login'))
        self.assertContains(response, POST_data['answer__text'])
Example #7
0
 def test_kde(self):
     p = Project.create_dummy(name='KDE')
     f = os.path.join(settings.MEDIA_ROOT, 'sample-data', 'kde-117760-2010-04-09.xml')
     xml_fd = file(f)
     bug = mysite.customs.miro.xml2bug_object(xml_fd)
     self.assertEqual(bug.submitter_username, 'hasso kde org')
     self.assertEqual(bug.submitter_realname, 'Hasso Tepper')
Example #8
0
    def test(self):
        # Steps for this test
        # 1. User POSTs to the wannahelp POST handler, indicating the request
        #    came from offsite
        # 2. User is redirected to a login page that knows the request came
        #    from offsite
        project_id = Project.create_dummy(name='Myproject').id

        # At the start, no one wants to help our project.
        self.assertFalse(Project.objects.get(id=project_id)
                         .people_who_wanna_help.all())

        # Click the button saying we want to help!
        post_to = reverse(mysite.project.views.wanna_help_do)
        response = self.client.post(post_to,
                                    {u'project': unicode(project_id),
                                     u'from_offsite': u'True'}, follow=True)

        # Make sure the session knows we came from offsite. Login-related
        # templates want this knowledge.
        self.assert_(self.client.session.get('from_offsite', False))

        # FIXME: There should be a cancel button letting the user
        # destroy the session and then go back to the Referring page.

        # Make sure we are redirected to the right place
        self.assertEqual(
            response.redirect_chain,
            [('http://testserver/account/login/?'
              'next=%2Fprojects%2FMyproject%3Fwanna_help%3Dtrue', 302)])

        lucky_projects = (mysite.project.view_helpers.
                          get_wanna_help_queue_from_session(self.client.
                                                            session))
        self.assertEqual([k.name for k in lucky_projects], ['Myproject'])
Example #9
0
    def test_snapshot_project_with_icon(self, fake_icon):
        fake_icon_data = open(os.path.join(
            settings.MEDIA_ROOT, 'no-project-icon.png')).read()
        fake_icon.return_value = fake_icon_data

        fake_stdout = StringIO()
        # make fake Project
        proj = Project.create_dummy(
            name="karens-awesome-project", language="Python")
        proj.populate_icon_from_ohloh()
        proj.save()

        command = mysite.customs.management.commands.snapshot_public_data.Command(
        )
        command.handle(output=fake_stdout)

        # now delete fake Project...
        proj.delete()

        # let's see if we can reincarnate it!
        for obj in django.core.serializers.deserialize('json', fake_stdout.getvalue()):
            obj.save()

        # test: are there ANY projects?
        self.assertTrue(Project.objects.all())
        # test: is our lovely fake project there?
        mysite.search.models.Project.objects.get(name="karens-awesome-project")
Example #10
0
 def create_dummy(**kwargs):
     data = {'project': Project.create_dummy(),
             'project_description': "DESCRIPTION-----------------------------" + uuid.uuid4().hex }
     data.update(kwargs)
     ret = PortfolioEntry(**data)
     ret.save()
     return ret
Example #11
0
    def test_snapshot_project_with_icon(self, fake_icon):
        fake_icon_data = open(os.path.join(
            settings.MEDIA_ROOT, 'no-project-icon.png')).read()
        fake_icon.return_value = fake_icon_data

        fake_stdout = StringIO()
        # make fake Project
        proj = Project.create_dummy(
            name="karens-awesome-project", language="Python")
        proj.populate_icon_from_ohloh()
        proj.save()

        command = mysite.customs.management.commands.snapshot_public_data.Command(
        )
        command.handle(output=fake_stdout)

        # now delete fake Project...
        proj.delete()

        # let's see if we can reincarnate it!
        for obj in django.core.serializers.deserialize('json', fake_stdout.getvalue()):
            obj.save()

        # test: are there ANY projects?
        self.assertTrue(Project.objects.all())
        # test: is our lovely fake project there?
        mysite.search.models.Project.objects.get(name="karens-awesome-project")
Example #12
0
 def test_kde_harder_bug(self):
     p = Project.create_dummy(name='KDE')
     f = os.path.join(settings.MEDIA_ROOT, 'sample-data', 'kde-182054-2010-04-09.xml')
     xml_fd = file(f)
     bug = mysite.customs.miro.xml2bug_object(xml_fd)
     self.assertEqual(bug.submitter_username, 'jedd progsoc org')
     self.assertEqual(bug.submitter_realname, '')
Example #13
0
    def test(self):
        # Create an answer whose author isn't specified. This replicates the
        # situation where the user isn't logged in.
        p = Project.create_dummy(name='Myproject')
        q = ProjectInvolvementQuestion.create_dummy(
            key_string='where_to_start', is_bug_style=False)

        # Do a GET on the project page to prove cookies work.
        self.client.get(p.get_url())

        # POST some text to the answer creation post handler
        POST_data = {
            'project__pk':
            p.pk,
            'question__pk':
            q.pk,
            'answer__text':
            """Help produce official documentation, share the solution to a problem, or check, proof and test other documents for accuracy.""",
        }
        response = self.client.post(reverse(
            mysite.project.views.create_answer_do),
                                    POST_data,
                                    follow=True)

        # Now, the session will know about the answer, but the answer will not be published.
        # Visit the login page, assert that the page contains the text of the answer.

        response = self.client.get(reverse('oh_login'))
        self.assertContains(response, POST_data['answer__text'])
Example #14
0
    def test_project_creator_simply_redirects_to_project_if_it_exists(self, mock_populate_icon, mock_populate_language):
        # Show that it works
        project_name = "Something novel"
        Project.create_dummy(name=project_name.lower())

        # See? We have our project in the database (with slightly different case, but still)
        self.assertEqual(1, len(mysite.search.models.Project.objects.all()))

        response = self.client.post(
            reverse(mysite.project.views.create_project_page_do), {"project_name": project_name}, follow=True
        )

        # And we still have exactly that one project in the database.
        self.assertEqual(1, len(mysite.search.models.Project.objects.all()))

        #  and redirected.
        self.assertEqual(response.redirect_chain, [("http://testserver/+projects/something%20novel", 302)])
Example #15
0
    def test(self):

        # Create a project.
        project = Project.create_dummy()

        # Create two profiles, each with a PortfolioEntry linking it to the
        # project, each with descriptions.
        def create_pfe_with_description(username):
            return PortfolioEntry.create_dummy(project=project,
                                               person=Person.get_by_username(
                                                   username),
                                               is_published=True)
        pfes = {'uncheck_me': create_pfe_with_description('paulproteus'),
                'keep_me_checked': create_pfe_with_description('barry')}

        # Get a list of PortfolioEntries that we use to get a random project
        # description for the project page.
        descriptions = project.get_pfentries_with_usable_descriptions()

        # Observe that the list contains both PortfolioEntries.
        for entry in pfes.values():
            self.assert_(entry in descriptions)

        # Log in as paulproteus
        username = '******'
        self.login_with_client()

        # Go to the project page.
        url = urlparse.urljoin(
            "http://openhatch.org", project.get_edit_page_url())
        edit_page = self.app.get(url, user=username)

        # In preparation for the next set of assertions, make sure that the
        # entries don't have the same description.
        self.assertNotEqual(
            pfes['uncheck_me'].project_description,
            pfes['keep_me_checked'].project_description)

        # See a list of project descriptions on the page, which equals the
        # list of descriptions in the DB.
        # for entry in pfes.values():
            # tc.find(entry.project_description)

        # Uncheck one of the checkboxes and submit the form
        name_of_checkbox_to_uncheck = "%s-use_my_description" % pfes[
            'uncheck_me'].pk
        # We have to know that the correct form is the 2nd item
        edit_form = edit_page.forms[1]
        edit_form[name_of_checkbox_to_uncheck] = False
        edit_form.submit()

        # Get a list of the PortfolioEntries that we use to get a random
        # project description for the project page.
        good_pfentries = project.get_pfentries_with_usable_descriptions()

        # Observe that the list contains only the checked PortfolioEntry.
        self.assert_(pfes['uncheck_me'] not in good_pfentries)
        self.assert_(pfes['keep_me_checked'] in good_pfentries)
Example #16
0
    def test_mark_as_helper_anonymously(self):
        # Steps for this test
        # 1. User fills in the form anonymously
        # 2. We test that the Answer is not yet saved
        # 3. User logs in
        # 4. We test that the Answer is saved

        project_id = Project.create_dummy(name='Myproject').id

        # At the start, no one wants to help our project.
        self.assertFalse(Project.objects.get(id=project_id)
                         .people_who_wanna_help.all())

        # Click the button saying we want to help!
        post_to = reverse(mysite.project.views.wanna_help_do)
        response = self.client.post(
            post_to, {u'project': unicode(project_id)}, follow=True)

        # Make sure we are redirected to the right place
        self.assertEqual(response.redirect_chain,
                         [('http://testserver/account/login/?next=%2Fprojects%2FMyproject%3Fwanna_help%3Dtrue', 302)])

        # check that the session can detect that we want to help Ubuntu out
        self.assertEqual(self.client.session['projects_we_want_to_help_out'],
                         [project_id])

        # According to the database, no one wants to help our project.
        self.assertFalse(Project.objects.get(id=project_id)
                         .people_who_wanna_help.all())

        # But when the user is logged in and *then* visits the project page
        login_worked = self.client.login(username='******',
                                         password="******")
        self.assert_(login_worked)

        # Visit the project page...
        self.client.get(Project.objects.get(id=project_id).get_url())

        # After the GET, we've removed our note in the session
        self.assertFalse(
            self.client.session.get('projects_we_want_to_help_out', None))

        # then the DB knows the user wants to help out!
        self.assertEqual(
            list(Project.objects.get(id=project_id)
                 .people_who_wanna_help.all()),
            [Person.objects.get(user__username='******')])
        self.assert_(mysite.search.models.WannaHelperNote.objects.all())

        # Say we're not interested anymore.
        post_to = reverse(mysite.project.views.unlist_self_from_wanna_help_do)
        response = self.client.post(
            post_to, {u'project': unicode(project_id)}, follow=True)

        # And now the DB shows we have removed ourselves.
        self.assertFalse(Project.objects.get(id=project_id)
                         .people_who_wanna_help.all())
        self.assertFalse(mysite.search.models.WannaHelperNote.objects.all())
Example #17
0
    def test_project_creator_simply_redirects_to_project_if_it_exists(
        self, mock_populate_icon, mock_populate_language):
        # Show that it works
        project_name = 'Something novel'
        Project.create_dummy(name=project_name.lower())

        # See? We have our project in the database (with slightly different case, but still)
        self.assertEqual(1, len(mysite.search.models.Project.objects.all()))

        response = self.client.post(reverse(mysite.project.views.create_project_page_do),
                                    {'project_name': project_name}, follow=True)

        # And we still have exactly that one project in the database.
        self.assertEqual(1, len(mysite.search.models.Project.objects.all()))

        #  and redirected.
        self.assertEqual(response.redirect_chain,
                         [('http://testserver/projects/something%20novel', 302)])
Example #18
0
    def test_scrape_bug_status_and_mark_as_closed(self):
        roundup_project = Project.create_dummy()
        tracker = mysite.customs.models.RoundupBugTracker(
                project=roundup_project,
                roundup_root_url="http://example.org")
        tracker.save()

        bug = tracker.create_bug_object_for_remote_bug_id(1)
        self.assert_(bug.looks_closed)
Example #19
0
    def test(self):

        # Create a project.
        project = Project.create_dummy()

        # Create two profiles, each with a PortfolioEntry linking it to the
        # project, each with descriptions.
        def create_pfe_with_description(username):
            return PortfolioEntry.create_dummy(
                project=project, person=Person.get_by_username(username), is_published=True
            )

        pfes = {
            "uncheck_me": create_pfe_with_description("paulproteus"),
            "keep_me_checked": create_pfe_with_description("barry"),
        }

        # Get a list of the PortfolioEntries that we use to get a random project
        # description for the project page.
        descriptions = project.get_pfentries_with_usable_descriptions()

        # Observe that the list contains both PortfolioEntries.
        for entry in pfes.values():
            self.assert_(entry in descriptions)

        self.login_with_twill()

        # Go to the project page.
        url = urlparse.urljoin("http://openhatch.org", project.get_edit_page_url())
        tc.go(better_make_twill_url(url))

        # In preparation for the next set of assertions, make sure that the
        # entries don't have the same description.
        self.assertNotEqual(pfes["uncheck_me"].project_description, pfes["keep_me_checked"].project_description)

        # See a list of project descriptions on the page, which equals the list of
        # descriptions in the DB.
        for entry in pfes.values():
            tc.find(entry.project_description)

        # Uncheck one of the checkboxes and submit the form
        name_of_checkbox_to_uncheck = "%s-use_my_description" % pfes["uncheck_me"].pk
        tc.fv("2", name_of_checkbox_to_uncheck, False)
        tc.submit()

        # Get a list of the PortfolioEntries that we use to get a random project
        # description for the project page.
        good_pfentries = project.get_pfentries_with_usable_descriptions()

        # Observe that the list contains only the checked PortfolioEntry.
        self.assert_(pfes["uncheck_me"] not in good_pfentries)
        self.assert_(pfes["keep_me_checked"] in good_pfentries)
Example #20
0
    def test_unmark_as_wanna_help(self):
        # We're in there...
        person = Person.objects.get(user__username='******')
        p_before = Project.create_dummy()
        p_before.people_who_wanna_help.add(person)
        p_before.save()
        mysite.search.models.WannaHelperNote.add_person_project(person, p_before)

        # Submit that project to unlist_self_from_wanna_help_do
        client = self.login_with_client()
        post_to = reverse(mysite.project.views.unlist_self_from_wanna_help_do)
        client.post(post_to, {u'project': unicode(p_before.pk)})

        # Are we gone yet?
        p_after = Project.objects.get(pk=p_before.pk)

        self.assertFalse(p_after.people_who_wanna_help.all())
Example #21
0
    def test_mark_as_wanna_help(self):
        person = Person.objects.get(user__username="******")
        p_before = Project.create_dummy()
        self.assertFalse(mysite.search.models.WannaHelperNote.objects.all())

        self.assertFalse(p_before.people_who_wanna_help.all())

        client = self.login_with_client()
        post_to = reverse(mysite.project.views.wanna_help_do)
        client.post(post_to, {u"project": unicode(p_before.pk)})

        p_after = Project.objects.get(pk=p_before.pk)

        self.assertEqual(list(p_after.people_who_wanna_help.all()), [person])

        note = mysite.search.models.WannaHelperNote.objects.get()
        self.assertEqual(note.person, person)
        self.assertEqual(note.project, p_after)
Example #22
0
    def test_mark_as_contacted(self):
        person = Person.objects.get(user__username='******')
        p_before = Project.create_dummy()
        p_before.people_who_wanna_help.add(person)
        p_before.save()
        mysite.search.models.WannaHelperNote.add_person_project(person, p_before)

        client = self.login_with_client()
        post_to = reverse(mysite.project.views.mark_contacted_do)
        vars = {u'mark_contact-project': unicode(p_before.pk),
                u'helper-%s-checked' % (person.pk,) : unicode('on'),
                u'helper-%s-person_id' % (person.pk) : unicode(person.pk),
                u'helper-%s-project_id' % (person.pk) : unicode(p_before.pk)}
        client.post(post_to, vars)

        whn_after = mysite.search.models.WannaHelperNote.objects.get(person=person, project=p_before)
        self.assertTrue(whn_after.contacted_on)
        self.assertTrue(whn_after.contacted_by, datetime.date.today())
Example #23
0
    def test_mark_as_wanna_help(self):
        person = Person.objects.get(user__username='******')
        p_before = Project.create_dummy()
        self.assertFalse(mysite.search.models.WannaHelperNote.objects.all())

        self.assertFalse(p_before.people_who_wanna_help.all())

        client = self.login_with_client()
        post_to = reverse(mysite.project.views.wanna_help_do)
        client.post(post_to, {u'project': unicode(p_before.pk)})

        p_after = Project.objects.get(pk=p_before.pk)

        self.assertEqual(list(p_after.people_who_wanna_help.all()), [person])

        note = mysite.search.models.WannaHelperNote.objects.get()
        self.assertEqual(note.person, person)
        self.assertEqual(note.project, p_after)
Example #24
0
    def test_scrape_bug_status_and_mark_as_closed(
        self, mock_urlopen, project_name="Mercurial", should_do_something=True, should_use_urlopen=True
    ):
        if Project.objects.filter(name=project_name):
            roundup_project = Project.objects.get(name=project_name)
        else:
            roundup_project = Project.create_dummy(name=project_name)

        mock_urlopen.return_value = open(MercurialRoundupGrab.closed_bug_filename)

        tracker = mysite.customs.bugtrackers.roundup_general.MercurialTracker()
        did_create = tracker.create_bug_object_for_remote_bug_id_if_necessary(1)
        self.assertEqual(did_create, should_do_something)

        bug = Bug.all_bugs.get()
        self.assert_(bug.looks_closed)

        if should_use_urlopen:
            self.assert_(mock_urlopen.called)
Example #25
0
    def test_snapshot_project(self,fake_icon):
        fake_stdout = StringIO()
        # make fake Project
        proj = Project.create_dummy_no_icon(name="karens-awesome-project",language="Python")

        command = mysite.customs.management.commands.snapshot_public_data.Command()
        command.handle(output=fake_stdout)

        # now delete fake Project...
        proj.delete()

        # let's see if we can reincarnate it!
        for obj in django.core.serializers.deserialize('json', fake_stdout.getvalue()):
            obj.save()

        # test: are there ANY projects?
        self.assertTrue(Project.objects.all())
        # test: is our lovely fake project there?
        mysite.search.models.Project.objects.get(name="karens-awesome-project")
Example #26
0
    def test_snapshot_project(self, fake_icon):
        fake_stdout = StringIO()
        # make fake Project
        proj = Project.create_dummy_no_icon(
            name="karens-awesome-project", language="Python")

        command = mysite.customs.management.commands.snapshot_public_data.Command(
        )
        command.handle(output=fake_stdout)

        # now delete fake Project...
        proj.delete()

        # let's see if we can reincarnate it!
        for obj in django.core.serializers.deserialize('json', fake_stdout.getvalue()):
            obj.save()

        # test: are there ANY projects?
        self.assertTrue(Project.objects.all())
        # test: is our lovely fake project there?
        mysite.search.models.Project.objects.get(name="karens-awesome-project")
Example #27
0
    def test_mark_as_wanna_help(self, mock_reindex_person_method):
        person = Person.objects.get(user__username='******')
        p_before = Project.create_dummy()
        self.assertFalse(mysite.search.models.WannaHelperNote.objects.all())
        
        self.assertFalse(p_before.people_who_wanna_help.all())

        client = self.login_with_client()
        post_to = reverse(mysite.project.views.wanna_help_do)
        response = client.post(post_to, {u'project': unicode(p_before.pk)})
        self.assert_(mock_reindex_person_method.called)

        p_after = Project.objects.get(pk=p_before.pk)

        self.assertEqual(
            list(p_after.people_who_wanna_help.all()),
            [person])

        note = mysite.search.models.WannaHelperNote.objects.get()
        self.assertEqual(note.person, person)
        self.assertEqual(note.project, p_after)
Example #28
0
 def create_dummy_with_project(**kwargs):
     data = {'project': Project.create_dummy()}
     data.update(kwargs)
     return PortfolioEntry.create_dummy(**data)
Example #29
0
 def create_dummy_with_project(**kwargs):
     data = {'project': Project.create_dummy()}
     data.update(kwargs)
     return PortfolioEntry.create_dummy(**data)