예제 #1
0
파일: tests.py 프로젝트: 1e0ng/clickwork
    def get_next_task_view(self):
        self.client.login(username="******", password="******")
        ## get the next task
        self.task_expectation.check(self)
        ## tweak the database to put a response and a review in
        response = Response(task=self.t,
                            user=self.user,
                            start_time=timezone.now())
        response.full_clean()
        response.save()
        review = Review(response=response,
                        comment="I have reviewed this task.")
        review.full_clean()
        review.save()
        ## check to see if next_task now redirects to review
        ## if we actually execute the view code, we will get an error,
        ## because the task associated with the review has no result;
        ## therefore the code below is a bit hackish
        review_target = WebTarget("GET",
                                  main.views.base.next_task,
                                  statuses=(301, 302))

        def redirects_to_review(input_context, output_context):
            return "/review/next/" in output_context["__redirected_to__"]

        review_expectation = ViewExpectation(
            Conditions.post(redirects_to_review), review_target)
        review_expectation.check(self)
        ## tweak the database to complete the review
        review.complete = True
        review.full_clean()
        review.save()
        ## try getting the next task again
        self.task_expectation.check(self)
예제 #2
0
    def get_next_task_view(self):
        self.client.login(username="******", password="******")
        ## get the next task
        self.task_expectation.check(self)
        ## tweak the database to put a response and a review in
        response = Response(task=self.t, user=self.user, start_time=datetime.datetime.now())
        response.full_clean()
        response.save()
        review = Review(response=response, comment="I have reviewed this task.")
        review.full_clean()
        review.save()
        ## check to see if next_task now redirects to review
        ## if we actually execute the view code, we will get an error,
        ## because the task associated with the review has no result;
        ## therefore the code below is a bit hackish
        review_target = WebTarget("GET", main.views.base.next_task, statuses=(301, 302))

        def redirects_to_review(input_context, output_context):
            return "/review/next/" in output_context["__redirected_to__"]

        review_expectation = ViewExpectation(Conditions.post(redirects_to_review), review_target)
        review_expectation.check(self)
        ## tweak the database to complete the review
        review.complete = True
        review.full_clean()
        review.save()
        ## try getting the next task again
        self.task_expectation.check(self)
예제 #3
0
    def task_expectation(self):
        next_task_target = WebTarget("GET", main.views.base.next_task, final_views=(main.views.task.task_view,))

        def task_id_expected(input_context, output_context):
            return output_context["task"]["id"] == self.t.id

        return ViewExpectation(Conditions.post(task_id_expected), next_task_target)
예제 #4
0
파일: tests.py 프로젝트: 1e0ng/clickwork
    def task_expectation(self):
        next_task_target = WebTarget("GET",
                                     main.views.base.next_task,
                                     final_views=(main.views.task.task_view, ))

        def task_id_expected(input_context, output_context):
            return output_context["task"]["id"] == self.t.id

        return ViewExpectation(Conditions.post(task_id_expected),
                               next_task_target)
예제 #5
0
파일: tests.py 프로젝트: 1e0ng/clickwork
    def export_project_simple(self):
        def export_attrs(input_context, output_context):
            zipped_64 = output_context["contents_in_base64"]
            zipped = ZipFile(StringIO(b64decode(zipped_64)), "r", ZIP_DEFLATED)
            permissions_are_right = [
                zi.external_attr == settings.CLICKWORK_EXPORT_FILE_PERMISSIONS
                << 16 for zi in zipped.infolist()
            ]
            return all(permissions_are_right)

        self.client.login(username="******", password="******")
        target = WebTarget("GET",
                           main.views.project.project_export,
                           args=(self.p.id, ))
        expectation = ViewExpectation(Conditions.post(export_attrs), target)
        output_context = expectation.check(self)
예제 #6
0
        self.t = t
        self.user = u
        self.p = p

    def export_project_simple(self):
        def export_attrs(input_context, output_context):
            zipped_64 = output_context["contents_in_base64"]
            zipped = ZipFile(StringIO(b64decode(zipped_64)), "r", ZIP_DEFLATED)
            permissions_are_right = [
                zi.external_attr == settings.CLICKWORK_EXPORT_FILE_PERMISSIONS << 16L for zi in zipped.infolist()
            ]
            return all(permissions_are_right)

        self.client.login(username="******", password="******")
        target = WebTarget("GET", main.views.project.project_export, args=(self.p.id,))
        expectation = ViewExpectation(Conditions.post(export_attrs), target)
        output_context = expectation.check(self)

    def export_project_dict(self):
        self.client.login(username="******", password="******")
        target = WebTarget("GET", main.views.project.project_export, args=(self.p.id,))
        expectation = ViewExpectation(Conditions.null(), target)
        expectation.check(self)


class GetNextTask(TestCase):
    def setUp(self):
        u = User.objects.create_user("testuser_getnexttask", "*****@*****.**", "abc")
        u.full_clean()
        u.save()
        g = Group(name="test group")