diff --git a/_images/bdd-behave.png b/_images/bdd-behave.png new file mode 100644 index 0000000..2becbdc Binary files /dev/null and b/_images/bdd-behave.png differ diff --git a/_images/bdd-robot.png b/_images/bdd-robot.png new file mode 100644 index 0000000..897f834 Binary files /dev/null and b/_images/bdd-robot.png differ diff --git a/_images/bdd.jpg b/_images/bdd.jpg new file mode 100644 index 0000000..82601cc Binary files /dev/null and b/_images/bdd.jpg differ diff --git a/_sources/unclephil-flinkpipelinereal.dot b/_sources/mr-banks/unclephil-flinkpipelinereal.dot similarity index 100% rename from _sources/unclephil-flinkpipelinereal.dot rename to _sources/mr-banks/unclephil-flinkpipelinereal.dot diff --git a/_sources/unclephil-steps-drawio.xml b/_sources/mr-banks/unclephil-steps-drawio.xml similarity index 100% rename from _sources/unclephil-steps-drawio.xml rename to _sources/mr-banks/unclephil-steps-drawio.xml diff --git a/_sources/python-bdd/mainsource.py b/_sources/python-bdd/mainsource.py new file mode 100644 index 0000000..0e6b257 --- /dev/null +++ b/_sources/python-bdd/mainsource.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +"""This is a sample code that simulates a user being created.""" + +from __future__ import print_function + +import argparse +import json + +from collections import Counter +from unicodedata import category + +LOWERCASE_CHARS = "Ll" +UPCASE_CHARS = "Lu" +NUMBERS = "Nd" + + +class UserCreationError(Exception): + """Base class for all exceptions in this module.""" + pass + + +class PasswordIsNotStrongEnough(UserCreationError): + """The password used is not strong enough.""" + pass + + +class UserAlreadyExists(UserCreationError): + """The user already exists in the database.""" + pass + + +def password_is_strong(password): + """Check if the password have enough strength.""" + number_of = Counter(category(ch) for ch in password) + return (number_of[LOWERCASE_CHARS] >= 1 and + number_of[UPCASE_CHARS] >= 2 and + number_of[NUMBERS] >= 1 and + len(password) >= 12) + + +def get_users(): + """Retrieve the list of users in the system.""" + data = {} + try: + with open('users.json') as origin: + data = json.load(origin) + except IOError: + # File does not exist, so we just assume it's empty + pass + return data + + +def save_users(user_list): + """Save the user list back to the 'database'.""" + with open('users.json', 'w') as target: + json.dump(user_list, target) + return + + +def create_user(user, password): + """'Create' and user.""" + if not password_is_strong(password.decode('utf-8')): + raise PasswordIsNotStrongEnough + + users = get_users() + if user in users: + raise UserAlreadyExists + + users[user] = password + save_users(users) + return + + +def main(): + """Expose the functions back in command line options.""" + parser = argparse.ArgumentParser() + parser.add_argument('-u', '--user', + dest='user', + help='Username to be created', + required=True) + parser.add_argument('-p', '--password', + dest='password', + help='Password for the user', + required=True) + args = parser.parse_args() + try: + create_user(args.user, args.password) + except PasswordIsNotStrongEnough: + print("That password is not strong enough") + except UserAlreadyExists: + print("Username already used") + else: + print("User created") + return + + +if __name__ == "__main__": + main() diff --git a/_sources/python-bdd/users.json b/_sources/python-bdd/users.json new file mode 100644 index 0000000..42098a2 --- /dev/null +++ b/_sources/python-bdd/users.json @@ -0,0 +1 @@ +{"test": "Test123Test123"} \ No newline at end of file diff --git a/python-bdd.html b/python-bdd.html new file mode 100644 index 0000000..e99fbe4 --- /dev/null +++ b/python-bdd.html @@ -0,0 +1,282 @@ + + +
+ + +