def set_up_data(classmates_data_viewable=False): email, password = signup_teacher_directly() clas, class_name, access_code = create_class_directly(email) if classmates_data_viewable: clas.classmates_data_viewable = True clas.save() _, _, student = create_school_student_directly(access_code) _, _, student2 = create_school_student_directly(access_code) create_random_school_data() return clas, student, student2
def test_scoreboard_loads(self): email, password = signup_teacher_directly() create_organisation_directly(email) klass, name, access_code = create_class_directly(email) create_school_student_directly(access_code) url = reverse("scoreboard") c = Client() c.login(username=email, password=password) response = c.get(url) self.assertEqual(200, response.status_code)
def login_once(self): if not BaseGameTest.already_logged_on: email, password = signup_teacher_directly() create_organisation_directly(email) klass, name, access_code = create_class_directly(email) create_school_student_directly(access_code) login_page = self.go_to_homepage().go_to_teacher_login_page() login_page.login(email, password) email = email BaseGameTest.user_profile = UserProfile.objects.get(user__email=email) BaseGameTest.already_logged_on = True return BaseGameTest.user_profile
def test_get_avatar_id_for_two_users(self): # Set up the first avatar first_user = self.user models.Avatar(owner=first_user, code=self.CODE, game=self.game).save() client_one = self.login() # Set up the second avatar _, _, second_user = create_school_student_directly( self.klass.access_code) models.Avatar(owner=second_user.new_user, code=self.CODE, game=self.game).save() client_two = Client() client_two.login(username="******", password="******") first_avatar_id, first_response = get_avatar_id(first_user, 1) second_avatar_id, second_response = get_avatar_id( second_user.new_user, 1) # Status code starts with 2, success response can be different than 200. assert str(first_response.status_code)[0] == "2" assert str(second_response.status_code)[0] == "2" assert first_avatar_id == 1 assert second_avatar_id == 2
def test_anonymous_level_saving_school_student(self): email, password = signup_teacher_directly() create_organisation_directly(email) _, class_name, access_code = create_class_directly(email) student_name, student_password, _ = create_school_student_directly( access_code) self.student_login(student_name, access_code, student_password) url = reverse("save_level_for_editor") data1 = { u"origin": u'{"coordinate":[3,5],"direction":"S"}', u"pythonEnabled": False, u"decor": [], u"blocklyEnabled": True, u"blocks": [ { u"type": u"move_forwards" }, { u"type": u"turn_left" }, { u"type": u"turn_right" }, ], u"max_fuel": u"50", u"pythonViewEnabled": False, u"character": u"3", u"name": u"abc", u"theme": 1, u"anonymous": True, u"cows": u"[]", u"path": u'[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],' u'"connectedNodes":[0]}]', u"traffic_lights": u"[]", u"destinations": u"[[3,4]]", } response = self.client.post(url, {"data": json.dumps(data1)}) assert_that(response.status_code, equal_to(200)) sharing_info1 = json.loads( self.get_sharing_information(json.loads( response.content)["id"]).getvalue()) assert_that(sharing_info1["teacher"]["shared"], equal_to(True)) assert_that(len(mail.outbox), equal_to(0))
def test_moderation_another_class(self): email, password = signup_teacher_directly() email2, _ = signup_teacher_directly() klass2, _, access_code = create_class_directly(email2) student_name, _, student = create_school_student_directly(access_code) self.login(email, password) response = self.students_of_class(klass2) assert_that(response.status_code, equal_to(404)) assert_that(response.content, empty)
def test_moderation_teachers_class(self): email, password = signup_teacher_directly() klass, name, access_code = create_class_directly(email) student_name, _, student = create_school_student_directly(access_code) self.login(email, password) response = self.students_of_class(klass) assert_that(response.status_code, equal_to(200)) assert_that( response.content.decode(), equal_to('{"%s": "%s"}' % (student.id, student_name)), )
def test_delete_games(self): # Create a new teacher with a game to make sure it's not affected new_user: User = User.objects.create_user("test2", "*****@*****.**", "password") new_user.is_staff = True new_user.save() new_user_profile: UserProfile = UserProfile(user=new_user) new_user_profile.save() new_teacher: Teacher = Teacher.objects.create(user=new_user_profile, new_user=new_user) new_teacher.save() new_klass, _, _ = create_class_directly(new_user.email) new_user.save() new_game = models.Game(name="test2", game_class=new_klass, worksheet=self.worksheet) new_game.save() # Create a game for the second class game2 = models.Game(name="test", game_class=self.klass2, worksheet=self.worksheet) game2.save() data = {"game_ids": [self.game.id, game2.id, new_game.id]} # Try to login as a student and delete games - they shouldn't have access _, student_password, student = create_school_student_directly( self.klass.access_code) client = self.login(username=student.new_user.username, password=student_password) response = client.post(reverse("game-delete-games"), data) assert response.status_code == 403 assert Game.objects.count() == 3 # Login as initial teacher and delete games - only his games should be deleted client = self.login() response = client.post(reverse("game-delete-games"), data) assert response.status_code == 204 assert Game.objects.count() == 1 assert Game.objects.get(pk=new_game.id)
def student_row(self, class_name=None): email, password = signup_teacher_directly() _, class_name, access_code = create_class_directly(email, class_name) _, _, student = create_school_student_directly(access_code) total_time = timedelta(0, 30) scores = [x for x in range(20)] total_score = sum(scores) progress = (0, 0, 0) all_scores = scores + [""] * 89 row = StudentRow( student=student, total_time=total_time, total_score=total_score, start_time=datetime.fromtimestamp(1435305072, tz=utc), finish_time=datetime.fromtimestamp(1438305072, tz=utc), progress=progress, scores=all_scores, class_field=Class(name="MyClass"), ) return row
def test_update_game_worksheet_updates_avatar_codes( self, mock_game_manager): # Set up the first avatar first_user = self.user models.Avatar(owner=first_user, code=self.CODE, game=self.game).save() client1 = self.login() # Set up the second avatar _, _, second_user = create_school_student_directly( self.klass.access_code) models.Avatar(owner=second_user.new_user, code=self.CODE, game=self.game).save() client2 = Client() client2.login(username="******", password="******") data = json.dumps({"worksheet_id": self.worksheet2.id}) response = client1.put( reverse("game-detail", kwargs={"pk": self.game.id}), data, content_type="application/json", ) # GameManager is called when a game is edited. assert mock_game_manager.called assert response.status_code == 200 game = models.Game.objects.get(id=1) avatar1 = models.Avatar.objects.get(id=1) avatar2 = models.Avatar.objects.get(id=2) assert game.worksheet == self.worksheet2 assert avatar1.code == self.worksheet2.starter_code assert avatar2.code == self.worksheet2.starter_code
def create_random_school_data(): email, password = signup_teacher_directly() clas, class_name, access_code = create_class_directly(email) create_school_student_directly(access_code) create_school_student_directly(access_code)