def test_stare_at_victim(): """Stare at a victim adds victim to statue collection.""" anna = Medusa('Anna') pete = Person('Pete') assert pete.is_stoned() is False anna.stare_at(pete) assert pete.is_stoned() is True assert anna.statue_count() == 1
def test_caesar(self): text = 'hello world' processor = Medusa(algo='caesar', params=dict(shift=1)) encoded = processor.encode(text) assert encoded == 'ifmmp!xpsme' decoded = processor.decode(encoded) assert decoded == text
def test_rsa(self): text = 'hello world' processor = Medusa(algo='rsa', params={}) encoded = processor.encode(text) ctx = processor.get_context() decoded = processor.decode(encoded, n=ctx['n'], e=ctx['e'], d=ctx['d']) assert decoded == text assert encoded != text
def test_aes(self): text = 'hello world' processor = Medusa(algo='aes', params=dict(password='******')) encoded = processor.encode(text) ctx = processor.get_context() decoded = processor.decode(encoded, iv=ctx['iv'], salt=ctx['salt']) assert decoded == text assert encoded != text
def test_vigenere(self): text = 'hello world' processor = Medusa(algo='vigenere', params=dict(key='key', complement_key='complement_key')) encoded = processor.encode(text) assert encoded == 'ÓÐ×ÑèÜèÝ×Ý' decoded = processor.decode(encoded) assert decoded == text
def test_basic(self, params): processor = Medusa(algo='caesar', params=dict(shift=1)) input_path = os.path.join(INPUT_DIR, params['input']) output_path = os.path.join(OUTPUT_DIR, params['output']) reencode_path = os.path.join(OUTPUT_DIR, params['reencode']) processor.encode_dir(input_path, output_path) assert os.path.exists(output_path) processor.decode_dir(output_path, reencode_path) assert os.path.exists(reencode_path) for f in os.listdir(input_path): assert os.path.exists(os.path.join(output_path, f)) with open(os.path.join(input_path, f), 'r') as FILE: input_content = FILE.read() with open(os.path.join(output_path, f), 'r') as FILE: output_content = FILE.read() with open(os.path.join(reencode_path, f), 'r') as FILE: reencode_content = FILE.read() assert input_content == reencode_content assert input_content != output_content
def createCharacter(self, teamNum): print("Pick Team %s Character by selecting from below: \n" % teamNum) print("1) Vampire\n") print("2) Barbarian\n") print("3) BlueMen\n") print("4) Medusa\n") print("5) HarryPotter\n\n") choice = 0 while choice !=1 and choice != 2 and choice != 3 and choice != 4 and choice != 5: try: choice = int(input("Input the character number that you select: ")) except: choice = 0 characterName = input("Enter character name: ") if choice is 1: character = Vampire(characterName) return character elif choice is 2: character = Barbarian(characterName) return character elif choice is 3: character = BlueMen(characterName) return character elif choice is 4: character = Medusa(characterName) return character elif choice is 5: character = HarryPotter(characterName) return character
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ============================================================================== # [Medusa] Mini Encoding/Decoding Utility with Simple Algorithms # Example script: basic Medusa object instantiation. # ------------------------------------------------------------------------------ from medusa import Medusa if __name__ == '__main__': processor = Medusa(algo='vigenere', params=dict(key='key', complement_key='complement_key')) # ENCODING # encode a string directly encoded = processor.encode('hello world') # encode some file processor.encode_file('../utests/data/input.txt', '../utests/data/output.txt') # encode some directory processor.encode_dir('../utests/data/input_dir', '../utests/data/output_dir') # DECODING # decode a string directly
def test_missing_param(self): with pytest.raises(MedusaError): _ = Medusa(algo='caesar', params={}, exit_on_error=False)
def test_unknown_algo(self): with pytest.raises(MedusaError): _ = Medusa(algo='gloubi', params={}, exit_on_error=False)
def test_unsecure_param(self): with pytest.raises(MedusaError): _ = Medusa(algo='caesar', params=dict(shift=0), exit_on_error=False)
def test_it_exists(): """Ensure barb is a medusa object.""" barb = Medusa('Barb') assert type(barb) == Medusa
def test_max_three_victims(): """Medusa can have 3 victims at a time and then they become unstoned.""" rachel = Medusa('Rachel') max = Person('Max') agatha = Person('Agatha') jim = Person('Fishin Jim') lana = Person('Lana') rachel.stare_at(jim) rachel.stare_at(agatha) rachel.stare_at(max) assert jim.is_stoned() is True assert agatha.is_stoned() is True assert max.is_stoned() is True assert rachel.statue_count() == 3 rachel.stare_at(lana) assert lana.is_stoned() is True assert rachel.statue_count() == 3 assert jim.is_stoned() is False
def test_it_has_a_name_and_no_statues_when_new(): """New medusas have a name and no statues.""" jane = Medusa('Jane') assert jane.get_name() == 'Jane' assert jane.statue_count() == 0