Esempio n. 1
0
    def test_login(self):
        """
        Unit test for login function
        """
        config_file = '../config.json'
        config = client.Config(config_file)
        database = client.Userdb(config)

        menu = client.Menu()

        valid_login = False
        auth = True
        not_auth = False

        login_option = menu.login_option()
        if login_option == 1:  # when login with email
            email = menu.get_login_detail(True)
            valid_login = database.login(email, True)
        elif login_option == 2:  # when login with username
            username = menu.get_login_detail(False)
            valid_login = database.login(username, False)
        elif login_option == 3:  # when login with facial recognize
            copy2('./facialrecognition/encodings.pickle', '.')
            recognize = Recognise()
            name = recognize.getuser()
            if name != "Unknown":
                valid_login = True
        elif login_option == 4:  # when choose not to login
            valid_login = False

        if valid_login:
            self.assertEqual(auth, valid_login)
        else:
            self.assertEqual(not_auth, valid_login)
Esempio n. 2
0
 def test_db_connection(self):
     """
     Unit test for local database connection on reception pi
     """
     config_file = '../config.json'
     config = client.Config(config_file)
     database = client.Userdb(config)
     self.assertIsNotNone(database)
Esempio n. 3
0
    def setUpClass(cls):
        cls.testdir = tempfile.mkdtemp()
        cls.builddir = os.path.abspath("../../build")
        cls.toolsdir = os.path.join(cls.builddir, "tools")
        cls.serverbin = os.path.join(cls.builddir,
                                      "bftengine/tests/simpleTest/server")
        os.chdir(cls.testdir)
        cls.generateKeys()
        cls.config = client.Config(4, 1, 0, 4096, 1000, 50)
        cls.replicas = [
                client.Replica(i, "127.0.0.1", 3710 + 2*i) for i in range(0,4)]

        print("Running tests in {}".format(cls.testdir))
Esempio n. 4
0
def upload(bot_path):
    """
    Uploads the bot placed under bot_path. May only be called once Config is properly initialized.
    :param bot_path: The path wherein the bot is located
    :return: Nothing
    """
    _zip_file_integrity_check(bot_path)
    config = client.Config()
    if not bot_path or not os.path.isfile(bot_path):
        raise ValueError("Bot path is not valid or does not exist. Try again.")
    print("Uploading bot...")
    result = _upload_bot(config.user_id, config.api_key, bot_path)
    if result.status_code != client.SUCCESS:
        raise IOError("Unable to upload bot: {}".format(result.text))
    print("Successfully uploaded bot")
Esempio n. 5
0
def upload(bot_path, dry_run, include_extensions):
    """
    Uploads the bot placed under bot_path. May only be called once Config is properly initialized.
    :param bot_path: The path wherein the bot is located
    :return: Nothing
    """

    bot_file = None

    # If the bot looks like a MyBot.* file, then try and create the
    # archive for the user.
    # We only support this for Python bots (for now), though.
    bot_filename = os.path.basename(bot_path)
    if os.path.exists(bot_path) and bot_filename.startswith(
            _BOT_FILE_NAME_PREPEND):
        bot_file = _create_bot_upload(bot_path, dry_run, include_extensions)
        if not bot_file:
            # Dry run
            return
    else:
        _zip_file_integrity_check(bot_path)
        if not bot_path or not os.path.isfile(bot_path):
            raise ValueError(
                "Bot path is not valid or does not exist. Try again.")

    if dry_run:
        output.output("Dry run, not continuing.")
        return

    config = client.Config()
    with (bot_file if bot_file else open(bot_path, 'rb')) as bot_file:
        output.output("Uploading bot...")
        result = _upload_bot(config.user_id, config.api_key, bot_file)
        if result.status_code != client.SUCCESS:
            raise IOError("Unable to upload bot: {}".format(result.text))
        output.output("Successfully uploaded bot with version {}".format(
            _get_bot_version(config.user_id)))
Esempio n. 6
0
def download(bot_path):
    """
    Downloads the bot to the file bot_path. May only be called once Config is properly initialized.
    :param bot_path: The path the bot should be written
    :return: Nothing
    """
    config = client.Config()
    bot_path = pathlib.Path(bot_path)

    if bot_path.exists():
        # Confirm overwriting
        if not util.confirm("{} already exists. Overwrite?".format(bot_path)):
            output.output("Aborting download.")
            return

    # Make the directories
    bot_path.parent.mkdir(parents=True, exist_ok=True)

    output.output("Downloading bot...")
    result = _download_bot(config.user_id, config.api_key, bot_path)
    if result.status_code != client.SUCCESS:
        raise IOError("Unable to download bot: {}".format(result.text))
    output.output("Successfully downloaded bot with version {}".format(
        _get_bot_version(config.user_id)))