def test_multiline_input(): emojifier = emoji_it() expected = ["And if you sing", "though as angels"] input_lines = ['ππΆπ€£ ππΉ ππ₯ͺπ« π·ππΆπ΅', 'π§£ππ₯ͺπ«π΅π ππ· ππΆπ΅ππ₯π·'] for i in range(len(expected)): assert emojifier.decrypt(input_lines[i]) == expected[i]
def encrypt(): form = EncryptForm() if form.validate_on_submit(): #received message from form message = form.message.data multiplier = form.multiplier.data # choice = form.key.data # options = {u'U+1F680' : ':rocket:', u'U+1F4DC' : ':scroll:')} key = form.key.data #instantiate class emoji_encrypt_class = emoji_it() #rewrite message with encrypted message emoji_encrypt_class.emoji_key = key emoji_encrypt_class.multiplier = multiplier message = emoji_encrypt_class.encrypt(message) flash('Successfully encrypted!') return render_template('encrypt.html', form=form, message=message) return render_template('encrypt.html', form=form)
def test_cipher_duplicate(): cipher = emoji_it() cipher.multiplier = 26 #create cipher dictionary cipher_dict = cipher.define_cipher() for value in cipher_dict.values(): counter = 0 for value2 in cipher_dict.values(): if value == value2: counter += 1 assert counter == 1 #value should only match value2 once per iteration
def game(): json_url = os.path.join(os.path.realpath(os.path.dirname(__file__)), "static", "puzzles.json") puzzles = json.load(open(json_url)) puzzle_index = random.randint(0, len(puzzles) - 1) puzzle = puzzles[puzzle_index] #hot swap the 'encrypted' message. message = puzzle['decrypted'] multiplier = random.randint(1, 100) emoji_encrypt_class = emoji_it() emoji_encrypt_class.multiplier = multiplier message = emoji_encrypt_class.encrypt(message) puzzle['encrypted'] = message return render_template('game.html', puzzle=puzzle)
def test_decryption_2(): emojifier = emoji_it() assert emojifier.decrypt('π«β΅ ! ?') == "um ! ?"
def test_encryption_2(): emojifier = emoji_it() assert emojifier.encrypt("um ! ?") == 'π«β΅ ! ?'
def test_default_sanity(): cipher = emoji_it() assert cipher.emoji_key == ':rocket:' assert cipher.multiplier == 1
def test_encryption_1(): emojifier = emoji_it() assert emojifier.encrypt("hello") == 'πππ₯π₯π₯ͺ'
def test_multiline_input(): emojifier = emoji_it() input = "You work that you may keep pace\nwith the earth\nand the soul of the earth." expected_output = "ππ₯ͺπ« βπ₯ͺπ¦π π§£ππ𧣠ππ₯ͺπ« β΅ππ ππππ° π°ππ’π\nβππ§£π π§£ππ πππ¦π§£π\nππΆπ€£ π§£ππ π·π₯ͺπ«π₯ π₯ͺπΉ π§£ππ πππ¦π§£π." assert emojifier.encrypt(input) == expected_output
def test_numbers(): emojifier = emoji_it() assert emojifier.encrypt("806-672-3455") == 'β·π€π‘-π‘ππ€π»-π€πΎπ€πΌπ€π½π€π½'
def test_empty_input(): emojifier = emoji_it() assert emojifier.encrypt('') == ''
def test_chinese_korean(): emojifier = emoji_it() assert emojifier.encrypt("ζΌ’εγ², γΈ, γ , γ , γ ") == 'ζΌ’εγ², γΈ, γ , γ , γ '
def test_de_nonAlphabet_or_numbers(): emojifier = emoji_it() assert emojifier.decrypt( "!!!, @, #, $, % ^ & * () _ + - ` ; ' . , / ? | [ ] { } " ) == "!!!, @, #, $, % ^ & * () _ + - ` ; ' . , / ? | [ ] { } "
def test_decryption_1(): emojifier = emoji_it() assert emojifier.decrypt('πππ₯π₯π₯ͺ') == 'hello'
def test_de_numbers(): emojifier = emoji_it() assert emojifier.decrypt('β·π€π‘-π‘ππ€π»-π€πΎπ€πΌπ€π½π€π½') == "806-672-3455"