コード例 #1
0
ファイル: test_rest.py プロジェクト: anderco/patchwork
    def setUp(self):
        super(APITestBase, self).setUp()
        self.series = Series.objects.all()[0]
        self.patch = Patch.objects.all()[2]
        self.user = TestUser(username='******')
        self.maintainer = TestUser(username='******')
        self.maintainer.add_to_maintainers(self.project)
        self.maintainer2 = TestUser(username='******')
        self.maintainer2.add_to_maintainers(self.project)

        # a second series so we can test ordering/filtering
        test_series = TestSeries(3, project=self.project)
        time.sleep(1)
        test_series.insert()
        self.series2 = Series.objects.all().order_by('submitted')[1]

        # different user so sorting by submitter is a simple list reversal
        series3_sender = 'Test Author 3 <*****@*****.**>'

        # no cover letter
        test_series = TestSeries(3, project=self.project,
                                 sender=series3_sender, has_cover_letter=False)
        time.sleep(1)
        test_series.insert()
        self.series3 = Series.objects.all().order_by('submitted')[2]

        self.n_series = Series.objects.all().count()
        self.last_inserted_series = self.series3
コード例 #2
0
ファイル: test_rest.py プロジェクト: lsandoval/patchwork
class APITestBase(test_series.Series0010):
    def setUp(self):
        super(APITestBase, self).setUp()
        self.series = Series.objects.all()[0]
        self.patch = Patch.objects.all()[2]
        self.user = TestUser(username="******")
        self.maintainer = TestUser(username="******")
        self.maintainer.add_to_maintainers(self.project)

    def check_mbox(self, api_url, filename, md5sum):
        response = self.client.get("/api/1.0" + api_url)
        s = re.search(r"filename=([\w\.\-_]+)", response["Content-Disposition"]).group(1)
        self.assertEqual(s, filename)

        # With MySQL, primary keys keep growing and so the actual patch ids
        # will depend on the previous tests run. Make sure to canonicalize
        # the mbox file so we can compare md5sums
        content = re.sub("^X-Patchwork-Id: .*$", "X-Patchwork-Id: 1", response.content, flags=re.M)
        content_hash = hashlib.md5()
        content_hash.update(content)
        self.assertEqual(content_hash.hexdigest(), md5sum)

    def get(self, url, params={}):
        return self.client.get(
            "/api/1.0"
            + url
            % {
                "project_id": self.project.pk,
                "project_linkname": self.project.linkname,
                "series_id": self.series.pk,
                "version": 1,
                "patch_id": self.patch.pk,
            },
            params,
        )

    def get_json(self, url, params={}):
        return json.loads(self.get(url, params).content)

    # user: a TestUser instance
    def post_json(self, url, data={}, user=None):
        auth_headers = {}
        if user:
            auth_headers["HTTP_AUTHORIZATION"] = user.basic_auth_header()
        response = self.client.post(
            "/api/1.0"
            + url
            % {
                "project_id": self.project.pk,
                "project_linkname": self.project.linkname,
                "series_id": self.series.pk,
                "version": 1,
                "patch_id": self.patch.pk,
            },
            content_type="application/json",
            data=json.dumps(data),
            **auth_headers
        )
        return (response, json.loads(response.content))
コード例 #3
0
ファイル: test_xmlrpc.py プロジェクト: asdil12/patchwork
class XMLRPCTest(LiveServerTestCase):
    fixtures = ['default_states', 'default_events']

    def _insert_patch(self):
        patch = Patch(project=defaults.project,
                      submitter=defaults.patch_author_person,
                      msgid=defaults.patch_name,
                      content=defaults.patch)
        patch.save()
        return patch

    def setUp(self):
        defaults.project.save()
        defaults.patch_author_person.save()
        self.maintainer = TestUser(username='******')
        self.maintainer.add_to_maintainers(defaults.project)

        p = urlparse.urlparse(self.live_server_url)
        self.url = (p.scheme + '://' + self.maintainer.username + ':' +
                    self.maintainer.password + '@' + p.netloc + p.path +
                    reverse('patchwork.views.xmlrpc.xmlrpc'))
        self.rpc = xmlrpc_client.Server(self.url)

    def testGetRedirect(self):
        response = self.client.patch(self.url)
        self.assertRedirects(response,
                             reverse('patchwork.views.help',
                                     kwargs={'path': 'pwclient/'}))

    def testList(self):
        patch = self._insert_patch()

        patches = self.rpc.patch_list()
        self.assertEqual(len(patches), 1)
        self.assertEqual(patches[0]['id'], patch.id)

    def testSetPatchState(self):
        series = TestSeries(1, has_cover_letter=False)
        series.insert()
        patch = Patch.objects.all()[0]

        superseded = State.objects.get(name='Superseded')
        self.rpc.patch_set(patch.pk, {'state': superseded.pk})
        patch = Patch.objects.get(pk=patch.pk)
        self.assertEqual(patch.state, superseded)

        # make sure we've logged the correct user with the change event
        self.assertEqual(Patch.objects.count(), 1)
        events = EventLog.objects.filter(event_id=2)
        self.assertEqual(events.count(), 1)
        event = events[0]
        self.assertEquals(event.user, self.maintainer.user)
コード例 #4
0
ファイル: test_rest.py プロジェクト: lsandoval/patchwork
 def setUp(self):
     super(APITestBase, self).setUp()
     self.series = Series.objects.all()[0]
     self.patch = Patch.objects.all()[2]
     self.user = TestUser(username="******")
     self.maintainer = TestUser(username="******")
     self.maintainer.add_to_maintainers(self.project)
コード例 #5
0
ファイル: test_xmlrpc.py プロジェクト: anderco/patchwork
    def setUp(self):
        defaults.project.save()
        defaults.patch_author_person.save()
        self.maintainer = TestUser(username='******')
        self.maintainer.add_to_maintainers(defaults.project)

        p = urlparse.urlparse(self.live_server_url)
        self.url = (p.scheme + '://' + self.maintainer.username + ':' +
                    self.maintainer.password + '@' + p.netloc + p.path +
                    reverse('patchwork.views.xmlrpc.xmlrpc'))
        self.rpc = xmlrpc_client.Server(self.url)
コード例 #6
0
ファイル: test_rest.py プロジェクト: anderco/patchwork
class APITestBase(test_series.Series0010):

    def setUp(self):
        super(APITestBase, self).setUp()
        self.series = Series.objects.all()[0]
        self.patch = Patch.objects.all()[2]
        self.user = TestUser(username='******')
        self.maintainer = TestUser(username='******')
        self.maintainer.add_to_maintainers(self.project)
        self.maintainer2 = TestUser(username='******')
        self.maintainer2.add_to_maintainers(self.project)

        # a second series so we can test ordering/filtering
        test_series = TestSeries(3, project=self.project)
        time.sleep(1)
        test_series.insert()
        self.series2 = Series.objects.all().order_by('submitted')[1]

        # different user so sorting by submitter is a simple list reversal
        series3_sender = 'Test Author 3 <*****@*****.**>'

        # no cover letter
        test_series = TestSeries(3, project=self.project,
                                 sender=series3_sender, has_cover_letter=False)
        time.sleep(1)
        test_series.insert()
        self.series3 = Series.objects.all().order_by('submitted')[2]

        self.n_series = Series.objects.all().count()
        self.last_inserted_series = self.series3

    def check_mbox(self, api_url, filename, md5sum):
        response = self.client.get('/api/1.0' + api_url)
        s = re.search(r"filename=([\w\.\-_]+)",
                      response["Content-Disposition"]).group(1)
        self.assertEqual(s, filename)

        # With MySQL, primary keys keep growing and so the actual patch ids
        # will depend on the previous tests run. Make sure to canonicalize
        # the mbox file so we can compare md5sums
        content = re.sub('^X-Patchwork-Id: .*$', 'X-Patchwork-Id: 1',
                         response.content, flags=re.M)
        content_hash = hashlib.md5()
        content_hash.update(content)
        self.assertEqual(content_hash.hexdigest(), md5sum)

    def get(self, url, params={}):
        return self.client.get('/api/1.0' + url % {
            'project_id': self.project.pk,
            'project_linkname': self.project.linkname,
            'series_id': self.series.pk,
            'version': 1,
            'patch_id': self.patch.pk,
        }, params)

    def get_json(self, url, params={}):
        return json.loads(self.get(url, params).content)

    # user: a TestUser instance
    def _send_json(self, method, url, data={}, user=None):
        auth_headers = {}
        if user:
            auth_headers['HTTP_AUTHORIZATION'] = user.basic_auth_header()
        response = method('/api/1.0' + url % {
            'project_id': self.project.pk,
            'project_linkname': self.project.linkname,
            'series_id': self.series.pk,
            'version': 1,
            'patch_id': self.patch.pk,
        }, content_type="application/json", data=json.dumps(data),
            **auth_headers)
        return (response, json.loads(response.content))

    def post_json(self, url, data={}, user=None):
        return self._send_json(self.client.post, url, data, user)

    def patch_json(self, url, data={}, user=None):
        return self._send_json(self.client.patch, url, data, user)
コード例 #7
0
ファイル: test_user_browser.py プロジェクト: nwnk/patchwork
 def setUp(self):
     super(LoginTestCase, self).setUp()
     self.user = TestUser()
コード例 #8
0
ファイル: test_rest.py プロジェクト: DnPlas/patchwork
class APITestBase(test_series.Series0010):

    def setUp(self):
        super(APITestBase, self).setUp()
        self.series = Series.objects.all()[0]
        self.patch = Patch.objects.all()[2]
        self.user = TestUser(username='******')
        self.maintainer = TestUser(username='******')
        self.maintainer.add_to_maintainers(self.project)
        self.maintainer2 = TestUser(username='******')
        self.maintainer2.add_to_maintainers(self.project)

        # a second series so we can test ordering/filtering
        test_series = TestSeries(3, project=self.project)
        time.sleep(1)
        test_series.insert()
        self.series2 = Series.objects.all().order_by('submitted')[1]

        # different user so sorting by submitter is a simple list reversal
        series3_sender = 'Test Author 3 <*****@*****.**>'

        # no cover letter
        test_series = TestSeries(3, project=self.project,
                                 sender=series3_sender, has_cover_letter=False)
        time.sleep(1)
        test_series.insert()
        self.series3 = Series.objects.all().order_by('submitted')[2]

        self.n_series = Series.objects.all().count()
        self.last_inserted_series = self.series3

    def check_mbox(self, api_url, filename, md5sum):
        response = self.client.get('/api/1.0' + api_url)
        s = re.search(r"filename=([\w\.\-_]+)",
                      response["Content-Disposition"]).group(1)
        self.assertEqual(s, filename)

        # With MySQL, primary keys keep growing and so the actual patch ids
        # will depend on the previous tests run. Make sure to canonicalize
        # the mbox file so we can compare md5sums
        content = re.sub('^X-Patchwork-Id: .*$', 'X-Patchwork-Id: 1',
                         response.content, flags=re.M)
        content_hash = hashlib.md5()
        content_hash.update(content)
        self.assertEqual(content_hash.hexdigest(), md5sum)

    def get(self, url, params={}):
        return self.client.get('/api/1.0' + url % {
            'project_id': self.project.pk,
            'project_linkname': self.project.linkname,
            'series_id': self.series.pk,
            'version': 1,
            'patch_id': self.patch.pk,
        }, params)

    def get_json(self, url, params={}):
        return json.loads(self.get(url, params).content)

    # user: a TestUser instance
    def _send_json(self, method, url, data={}, user=None):
        auth_headers = {}
        if user:
            auth_headers['HTTP_AUTHORIZATION'] = user.basic_auth_header()
        response = method('/api/1.0' + url % {
            'project_id': self.project.pk,
            'project_linkname': self.project.linkname,
            'series_id': self.series.pk,
            'version': 1,
            'patch_id': self.patch.pk,
        }, content_type="application/json", data=json.dumps(data),
            **auth_headers)
        return (response, json.loads(response.content))

    def post_json(self, url, data={}, user=None):
        return self._send_json(self.client.post, url, data, user)

    def patch_json(self, url, data={}, user=None):
        return self._send_json(self.client.patch, url, data, user)