diff --git a/tests/cypress/e2e/public_programs/programs_page.cy.js b/tests/cypress/e2e/public_programs/programs_page.cy.js index ba53635d5d1..10461f94fd4 100644 --- a/tests/cypress/e2e/public_programs/programs_page.cy.js +++ b/tests/cypress/e2e/public_programs/programs_page.cy.js @@ -9,7 +9,7 @@ describe("General tests for my programs page (with both custom teacher and built const adventure = 'story' beforeEach(() => { loginForTeacher(); - }) + }) it("create adventure, run its code, and see it in my programs", () => { createAdventure(programName); @@ -31,7 +31,7 @@ describe("General tests for my programs page (with both custom teacher and built // make sure to navigate to the wanted program tab. cy.get(`[data-cy="${adventure}"]`) .click(); - // Paste example code + // Paste example code cy.get(`[data-cy="paste-example-code-${adventure}"]`).click(); cy.get('#runit').click(); cy.wait(500); diff --git a/tests/cypress/e2e/tools/profile/profile.js b/tests/cypress/e2e/tools/profile/profile.js index ad08b6afe27..9fff3b0d5cf 100644 --- a/tests/cypress/e2e/tools/profile/profile.js +++ b/tests/cypress/e2e/tools/profile/profile.js @@ -4,6 +4,6 @@ export function makeProfilePublic() { goToProfilePage(); cy.get('#public_profile_button').click(); cy.get('#personal_text').type('updating profile to be public'); - cy.get('#agree_terms').click(); + cy.get('#agree_terms').check(); // May start out checked, in which case 'click()' would undo the check! cy.get('#submit_public_profile').click(); } \ No newline at end of file diff --git a/website/database.py b/website/database.py index 4281be9bac7..4339dadc04e 100644 --- a/website/database.py +++ b/website/database.py @@ -899,8 +899,7 @@ def set_favourite_program(self, username, program_id, set_favourite): # We can only set a favourite program is there is already a public profile data = PUBLIC_PROFILES.get({"username": username}) if data: - data["favourite_program"] = program_id if set_favourite else '' - self.update_public_profile(username, data) + self.update_public_profile(username, {"favourite_program": program_id if set_favourite else ''}) return True return False diff --git a/website/dynamo.py b/website/dynamo.py index 3452b603418..09c971e1b7f 100644 --- a/website/dynamo.py +++ b/website/dynamo.py @@ -369,6 +369,13 @@ def update(self, key, updates): self._validate_indexable_fields(updates, True) self._validate_key(key) + updating_keys = set(updates.keys()) & set(self.key_schema.key_names) + if updating_keys: + raise RuntimeError(' '.join([ + 'update() may not include a key field in the \'updates\' field', + f'({updating_keys} may not be part of {updates};', + 'did you accidentally pass an entire record to update()?)'])) + return self.storage.update(self.table_name, key, updates) @querylog.timed_as("db_del") diff --git a/website/programs.py b/website/programs.py index ecdb46ddb76..c0a70cac11a 100644 --- a/website/programs.py +++ b/website/programs.py @@ -77,6 +77,7 @@ def store_user_program(self, updates['public'] = 1 if set_public else 0 if program_id: + # Updates an existing program # FIXME: This should turn into a conditional update current_prog = self.db.program_by_id(program_id) if not current_prog: @@ -86,6 +87,7 @@ def store_user_program(self, program = self.db.update_program(program_id, updates) else: + # Creates a new program updates['id'] = uuid.uuid4().hex program = self.db.store_program(updates) @@ -101,8 +103,7 @@ def store_user_program(self, # and if it was already modified and now is so again, count should not increase. if is_modified and not program.get('is_modified'): self.db.increase_user_program_count(user["username"]) - program['is_modified'] = is_modified - program = self.db.update_program(program['id'], program) + program = self.db.update_program(program['id'], {'is_modified': True}) querylog.log_value(program_id=program['id'], adventure_name=adventure_name, error=error, code_lines=len(code.split('\n')))