Exemplo n.º 1
0
    def testUpdateRegistrantStatus(self):
        """ Tests if update of registrant status works properly
        """
        storage = getAvatarConferenceStorage()

        registrant1 = Registrant()
        registrant1.setAvatar(self._avatar1)
        registrant1.setEmail("*****@*****.**")
        self._conf1.addRegistrant(registrant1, self._avatar1)
        self.assertEqual(len(storage), 1)
        self.assertEqual(len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(storage[self._avatar1.getId() + '_' + self._conf1.getId()][0]["eventType"], "added")

        registrant2 = Registrant()
        registrant2.setAvatar(self._avatar2)
        registrant2.setEmail("*****@*****.**")
        self._conf1.addRegistrant(registrant2, self._avatar2)
        self.assertEqual(len(storage), 2)
        self.assertEqual(len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(len(storage[self._avatar2.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(storage[self._avatar2.getId() + '_' + self._conf1.getId()][0]["eventType"], "added")

        self._conf1.removeRegistrant(registrant2.getId())
        self.assertEqual(len(storage), 2)
        self.assertEqual(len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(len(storage[self._avatar2.getId() + '_' + self._conf1.getId()]), 2)
        self.assertEqual(storage[self._avatar2.getId() + '_' + self._conf1.getId()][1]["eventType"], "removed")

        self._conf1.removeRegistrant(registrant1.getId())
        self.assertEqual(len(storage), 2)
        self.assertEqual(len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 2)
        self.assertEqual(len(storage[self._avatar2.getId() + '_' + self._conf1.getId()]), 2)
        self.assertEqual(storage[self._avatar1.getId() + '_' + self._conf1.getId()][1]["eventType"], "removed")
Exemplo n.º 2
0
    def testUpdateRegistrantStatus(self):
        """ Tests if update of registrant status works properly
        """
        storage = getAvatarConferenceStorage()

        registrant1 = Registrant()
        registrant1.setAvatar(self._avatar1)
        registrant1.setEmail("*****@*****.**")
        self._conf1.addRegistrant(registrant1, self._avatar1)
        self.assertEqual(len(storage), 1)
        self.assertEqual(
            len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(
            storage[self._avatar1.getId() + '_' +
                    self._conf1.getId()][0]["eventType"], "added")

        registrant2 = Registrant()
        registrant2.setAvatar(self._avatar2)
        registrant2.setEmail("*****@*****.**")
        self._conf1.addRegistrant(registrant2, self._avatar2)
        self.assertEqual(len(storage), 2)
        self.assertEqual(
            len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(
            len(storage[self._avatar2.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(
            storage[self._avatar2.getId() + '_' +
                    self._conf1.getId()][0]["eventType"], "added")

        self._conf1.removeRegistrant(registrant2.getId())
        self.assertEqual(len(storage), 2)
        self.assertEqual(
            len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 1)
        self.assertEqual(
            len(storage[self._avatar2.getId() + '_' + self._conf1.getId()]), 2)
        self.assertEqual(
            storage[self._avatar2.getId() + '_' +
                    self._conf1.getId()][1]["eventType"], "removed")

        self._conf1.removeRegistrant(registrant1.getId())
        self.assertEqual(len(storage), 2)
        self.assertEqual(
            len(storage[self._avatar1.getId() + '_' + self._conf1.getId()]), 2)
        self.assertEqual(
            len(storage[self._avatar2.getId() + '_' + self._conf1.getId()]), 2)
        self.assertEqual(
            storage[self._avatar1.getId() + '_' +
                    self._conf1.getId()][1]["eventType"], "removed")
Exemplo n.º 3
0
def _import(self, file):
    # check Registration period
    import datetime
    import pytz
    utc = pytz.UTC
    startDate = self._conf.getRegistrationForm().getStartRegistrationDate()
    endDate = self._conf.getRegistrationForm().getEndRegistrationDate()
    current = datetime.datetime.now()
    current = utc.localize(current)

    if (current < startDate or current > endDate):
        raise NoReportError("Import registrants not authorized, outside registration period.")

    reader = csv.DictReader(file)
    i = 1
    errors = []

    successfuls = []
    unsuccessfuls = []

    for row in reader:
        try:
            # row['Email'] = row['Email'].lower()
            self._processImportData(row)
            matchedUsers = AvatarHolder().match({"email": row['Email']}, exact=1)
            if matchedUsers:
                user = matchedUsers[0]
            elif ('Account Creation' in row) and row['Account Creation'].lower() == 'yes':  # account creation
                avData = self._mapAvatar(row)
                user = Avatar(avData)
                user.activateAccount()
                login_info = LoginInfo(row['Login'], row['Password'])
                auth_mgr = AuthenticatorMgr()
                user_id = auth_mgr.createIdentity(login_info, user, "Local")
                auth_mgr.add(user_id)
                AvatarHolder().add(user)
            else:
                user = None

            if not (user):
                reg = Registrant()  # new registration
                self._conf.addRegistrant(reg, user)
            else:
                if user.isRegisteredInConf(self._conf):
                    reg = self._conf.getRegistrantsByEmail(user.getEmail())
                else:  # not registered, new registration
                    reg = Registrant()
                    reg.setAvatar(user)
                    self._conf.addRegistrant(reg, user)
                    user.addRegistrant(reg)

            regData = self._mapRegistrant(row)
            regData['import'] = 'import'
            reg.setValues(regData, user)
            self._setAffiliation(reg)
            successfuls.append(reg.getFullName())
        except Exception:
            errors.append(i)
            unsuccessfuls.append(
                row["Surname"] + ", " + row["First Name"])  # exception : reg or user might not be defined yet
        finally:
            i += 1
    self.logimport(successfuls, unsuccessfuls)
    return errors
Exemplo n.º 4
0
def _import(self, file):
    # check Registration period
    import datetime
    import pytz
    utc = pytz.UTC
    startDate = self._conf.getRegistrationForm().getStartRegistrationDate()
    endDate = self._conf.getRegistrationForm().getEndRegistrationDate()
    current = datetime.datetime.now()
    current = utc.localize(current)

    if (current < startDate or current > endDate):
        raise NoReportError(
            "Import registrants not authorized, outside registration period.")

    reader = csv.DictReader(file)
    i = 1
    errors = []

    successfuls = []
    unsuccessfuls = []

    for row in reader:
        try:
            # row['Email'] = row['Email'].lower()
            self._processImportData(row)
            matchedUsers = AvatarHolder().match({"email": row['Email']},
                                                exact=1)
            if matchedUsers:
                user = matchedUsers[0]
            elif ('Account Creation' in row) and row['Account Creation'].lower(
            ) == 'yes':  # account creation
                avData = self._mapAvatar(row)
                user = Avatar(avData)
                user.activateAccount()
                login_info = LoginInfo(row['Login'], row['Password'])
                auth_mgr = AuthenticatorMgr()
                user_id = auth_mgr.createIdentity(login_info, user, "Local")
                auth_mgr.add(user_id)
                AvatarHolder().add(user)
            else:
                user = None

            if not (user):
                reg = Registrant()  # new registration
                self._conf.addRegistrant(reg, user)
            else:
                if user.isRegisteredInConf(self._conf):
                    reg = self._conf.getRegistrantsByEmail(user.getEmail())
                else:  # not registered, new registration
                    reg = Registrant()
                    reg.setAvatar(user)
                    self._conf.addRegistrant(reg, user)
                    user.addRegistrant(reg)

            regData = self._mapRegistrant(row)
            regData['import'] = 'import'
            reg.setValues(regData, user)
            self._setAffiliation(reg)
            successfuls.append(reg.getFullName())
        except Exception:
            errors.append(i)
            unsuccessfuls.append(
                row["Surname"] + ", " + row["First Name"]
            )  # exception : reg or user might not be defined yet
        finally:
            i += 1
    self.logimport(successfuls, unsuccessfuls)
    return errors