コード例 #1
0
ファイル: fresh_eyes.py プロジェクト: clickwork/clickwork
 def tag_project(self):
     ## Each user should tag two tasks.
     for i in range(2):
         for user in (self.bob, self.carol, self.dave):
             self.login_as(user.username)
             next_task_target = WebTarget("GET", main.views.base.next_task,
                                          final_views=(main.views.task.task_view,))
             next_task_expectation = ViewExpectation(Conditions.null(),
                                                     next_task_target)
             output_context = next_task_expectation.check(self)
             question = output_context["question"]
             answer_input_context = {"answer": self.quiz[question][user],
                                     "comment": "generated in testing"}
             answer_target = WebTarget("POST", main.views.task.task_view,
                                       (output_context["task"]["id"],),
                                       final_views=(main.views.task.task_view,
                                                    main.views.base.home))
             answer_expectation = ViewExpectation(Conditions.null(), answer_target)
             answer_expectation.check(self, answer_input_context)
             print >>sys.stderr, "User", user.username, "answered", question
             ## At this point the user is holding a WIP for the third task,
             ## but we want that WIP to be released.
             abandon_target = WebTarget("POST", main.views.base.abandon_wip,
                                        statuses=(302, 200))
             abandon_expectation = ViewExpectation(Conditions.null(), abandon_target)
             abandon_expectation.check(self)
コード例 #2
0
ファイル: fresh_eyes.py プロジェクト: 1e0ng/clickwork
 def set_up_users(self):
     superuser = User.objects.create_user("superuser", "*****@*****.**",
                                          "superuser")
     superuser.is_superuser = True
     superuser.is_staff = True
     superuser.save()
     self.login_as("superuser")
     new_user_target = WebTarget("POST", user_management.views.new_user)
     expectation = ViewExpectation(Conditions.null(), new_user_target)
     for name in ("alice", "bob", "carol", "dave"):
         ## Test creation of the account.
         input_context = {
             "username": name,
             "first_name": name.capitalize(),
             "last_name": "Example",
             "email": "*****@*****.**" % name,
         }
         expectation.check(self, input_context)
         ## Park the corresponding User object as an attribute, and
         ## reset its (randomly-generated) password,
         ## so that other test code can simulate logins over the client.
         u = User.objects.get(username=name)
         self.__dict__[name] = u
         u.set_password(name)
         u.save()
     g = Group.objects.create(name="taggers_and_mergers")
     for member in (self.bob, self.carol, self.dave):
         g.user_set.add(member)
     g.save()
     self.taggers_and_mergers = g
コード例 #3
0
ファイル: tests.py プロジェクト: 1e0ng/clickwork
 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)
コード例 #4
0
ファイル: fresh_eyes.py プロジェクト: clickwork/clickwork
 def set_up_users(self):
     superuser = User.objects.create_user("superuser",
                                          "*****@*****.**",
                                          "superuser")
     superuser.is_superuser = True
     superuser.is_staff = True
     superuser.save()
     self.login_as("superuser")
     new_user_target = WebTarget("POST", user_management.views.new_user)
     expectation = ViewExpectation(Conditions.null(), new_user_target)
     for name in ("alice", "bob", "carol", "dave"):
         ## Test creation of the account.
         input_context = {"username": name,
                          "first_name": name.capitalize(),
                          "last_name": "Example",
                          "email": "*****@*****.**" % name}
         expectation.check(self, input_context)
         ## Park the corresponding User object as an attribute, and
         ## reset its (randomly-generated) password,
         ## so that other test code can simulate logins over the client.
         u = User.objects.get(username=name)
         self.__dict__[name] = u
         u.set_password(name)
         u.save()
     g = Group.objects.create(name="taggers_and_mergers")
     for member in (self.bob, self.carol, self.dave):
         g.user_set.add(member)
     g.save()
     self.taggers_and_mergers = g
コード例 #5
0
ファイル: tests.py プロジェクト: 1e0ng/clickwork
 def test_home_post(self):
     """
     You can't post to /; it's @get only.
     """
     self.test_login()
     target = WebTarget("POST", main.views.base.home, statuses=(405, ))
     expectation = ViewExpectation(Conditions.null(), target)
     expectation.check(self)
コード例 #6
0
ファイル: tests.py プロジェクト: clickwork/clickwork
 def test_home_post(self):
     """
     You can't post to /; it's @get only.
     """
     self.test_login()
     target = WebTarget("POST", main.views.base.home, statuses=(405,))
     expectation = ViewExpectation(Conditions.null(), target)
     expectation.check(self)
コード例 #7
0
ファイル: fresh_eyes.py プロジェクト: clickwork/clickwork
 def populate_project(self):
     f = SimpleUploadedFile("questions", "\n".join(self.quiz.keys()))
     f.open("rb")
     context = {"action": "Upload", "upload": f}
     target = WebTarget("POST", main.views.project.project_upload,
                        args=(self.project.id,))
     expectation = ViewExpectation(Conditions.null(), target)
     expectation.check(self, context)
コード例 #8
0
ファイル: fresh_eyes.py プロジェクト: 1e0ng/clickwork
 def populate_project(self):
     f = SimpleUploadedFile("questions", "\n".join(list(self.quiz.keys())))
     f.open("rb")
     context = {"action": "Upload", "upload": f}
     target = WebTarget("POST",
                        main.views.project.project_upload,
                        args=(self.project.id, ))
     expectation = ViewExpectation(Conditions.null(), target)
     expectation.check(self, context)
コード例 #9
0
ファイル: tests.py プロジェクト: clickwork/clickwork
 def get_next_task_should_fail(self):
     """Try to get a task with the wrong user's authentication."""
     other_user = User.objects.create_user("nobody_special", "*****@*****.**", "abc")
     ## this should work...
     self.client.login(username="******", password="******")
     self.task_expectation.check(self)
     ## ...and this shouldn't
     self.client.login(username="******", password="******")
     forbidden_task_target = WebTarget("GET", main.views.task.task_view, args=(self.t.id,), statuses=(403,))
     forbidden_expectation = ViewExpectation(Conditions.null(), forbidden_task_target)
     forbidden_expectation.check(self)
コード例 #10
0
ファイル: fresh_eyes.py プロジェクト: 1e0ng/clickwork
 def tag_project(self):
     ## Each user should tag two tasks.
     for i in range(2):
         for user in (self.bob, self.carol, self.dave):
             self.login_as(user.username)
             next_task_target = WebTarget(
                 "GET",
                 main.views.base.next_task,
                 final_views=(main.views.task.task_view, ),
             )
             next_task_expectation = ViewExpectation(
                 Conditions.null(), next_task_target)
             output_context = next_task_expectation.check(self)
             question = output_context["question"]
             answer_input_context = {
                 "answer": self.quiz[question][user],
                 "comment": "generated in testing",
             }
             answer_target = WebTarget(
                 "POST",
                 main.views.task.task_view,
                 (output_context["task"]["id"], ),
                 final_views=(main.views.task.task_view,
                              main.views.base.home),
             )
             answer_expectation = ViewExpectation(Conditions.null(),
                                                  answer_target)
             answer_expectation.check(self, answer_input_context)
             print("User",
                   user.username,
                   "answered",
                   question,
                   file=sys.stderr)
             ## At this point the user is holding a WIP for the third task,
             ## but we want that WIP to be released.
             abandon_target = WebTarget("POST",
                                        main.views.base.abandon_wip,
                                        statuses=(302, 200))
             abandon_expectation = ViewExpectation(Conditions.null(),
                                                   abandon_target)
             abandon_expectation.check(self)
コード例 #11
0
ファイル: tests.py プロジェクト: 1e0ng/clickwork
 def get_next_task_should_fail(self):
     """Try to get a task with the wrong user's authentication."""
     other_user = User.objects.create_user("nobody_special",
                                           "*****@*****.**", "abc")
     ## this should work...
     self.client.login(username="******", password="******")
     self.task_expectation.check(self)
     ## ...and this shouldn't
     self.client.login(username="******", password="******")
     forbidden_task_target = WebTarget("GET",
                                       main.views.task.task_view,
                                       args=(self.t.id, ),
                                       statuses=(403, ))
     forbidden_expectation = ViewExpectation(Conditions.null(),
                                             forbidden_task_target)
     forbidden_expectation.check(self)
コード例 #12
0
ファイル: tests.py プロジェクト: clickwork/clickwork
 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)