def test_del_contact_from_group(app, db, check_ui):
    if len(db.get_contact_list()) == 0:
        app.contact.add_new(Contact())
    if len(db.get_group_list()) == 0:
        app.group.create(Group())
    group_list = db.get_group_list()
    group_index = randrange(len(group_list))
    group_id = group_list[group_index].id
    if len(db.get_contact_group(group_id)) == 0:
        old_contact_group = db.get_contact_group_list()
        contact_index = randrange(len(old_contact_group))
        contact_id = old_contact_group[contact_index].id
        app.contact.add_contact_to_group_by_id(contact_id, group_id)
    old_contact_group = db.get_contact_group(group_id)
    contact_index = randrange(len(old_contact_group))
    contact_id = old_contact_group[contact_index].id
    app.contact.del_contact_from_group_by_id(contact_id, group_id)
    old_contact_group.remove(Contact(id=contact_id, group_id=group_id))
    new_contact_group = db.get_contact_group(group_id)
    assert sorted(old_contact_group,
                  key=Contact.id_or_max) == sorted(new_contact_group,
                                                   key=Contact.id_or_max)
    if check_ui:
        ui_list = app.contact.get_contacts_in_group_ui_list(group_id)
        new_contact_group = db.get_contact_group(group_id)
        assert sorted(ui_list,
                      key=Contact.id_or_max) == sorted(new_contact_group,
                                                       key=Contact.id_or_max)
Beispiel #2
0
def add_list():
    data = json.loads(request.form['params'])
    try:
        Contact.add_list(data)
        return jsonify(msg='Records saved!')
    except Exception as ex:
        return jsonify(error=str(ex))
Beispiel #3
0
def new_contact_data(firstname, lastname, non_empty_contacts_list):
    new_contact = Contact(firstname=firstname,
                          lastname=lastname,
                          middlename='qwer',
                          nickname='asd',
                          title='fsdf',
                          company='fsd',
                          address='dfsdf',
                          homephone='45345',
                          mobilephone='2312',
                          workphone='2342',
                          fax='23213',
                          email='*****@*****.**',
                          email2='*****@*****.**',
                          email3='*****@*****.**',
                          homepage='sfsdfs.sdf',
                          byear='1900',
                          ayear='2000',
                          address2='sdfsdfsd',
                          secondaryphone='233534',
                          notes='dfsdf')
    contact = random.choice(non_empty_contacts_list)
    new_contact.id = contact.id
    new_contact.index = non_empty_contacts_list.index(contact)
    return new_contact
Beispiel #4
0
def csv_import():
    data = json.loads(request.form['params'])
    dao = Dao(stateful=True)
    groups = Group.get_all_by_code(dao)
    memberships = []
    next_id = dao.get_max_id('contacts', 'id')
    for rec in data:
        rec['precinct_id'] = None
        next_id += 1
        if rec['groups']:
            for code in rec['groups'].split('/'):
                if code in groups:
                    memberships.append({
                        'group_id': groups[code]['id'],
                        'contact_id': next_id,
                        'role': '',
                        'comment': ''
                    })

    try:
        Contact.add_many(data)
        GroupMember.add_many(memberships)
        return jsonify(msg='Successful!')
    except Exception as ex:
        return jsonify(error=str(ex))
    finally:
        dao.close()
    def post(self, group_name=None):
        session = authorize(request.headers["Authorization"])
        print session

        contacts = post_parser.parse_args().get("contacts")
        if contacts is None:
            abort(403)

        if group_name is None: group_name = "default"

        new_contacts = 0
        existing_contact = 0
        for contact in contacts:
            print contact
            contact = Contact.contact_from_dict(contact)
            existing = mongo.db.contacts.find_one({"email": contact.email})

            if existing is None:
                contact._id = get_id("contacts")
                contact.creationDate = datetime.now()
                contact.createdBy = session.get("user").get("login")
                if contact.language is None:
                    contact.language = "fr"

                mongo.db.contacts.insert(contact.format())

                self.update_group(group_name, contact.createdBy, contact)

                new_contacts += 1
            else:
                existing_contact += 1
                contact = Contact.contact_from_dict(existing)
                self.update_group(group_name, contact.createdBy, contact)

        return {"inserted": new_contacts, "existing": existing_contact}, 200
Beispiel #6
0
def drop_many():
    data = json.loads(request.form['params'])
    try:
        Contact.drop_many(data['ids'])
        return jsonify(msg='Records removed!')
    except Exception as ex:
        return jsonify(error=str(ex))
Beispiel #7
0
def contact(mid=None):
    if request.path == '/contact':
        form = ContactForm()
        if current_user.is_authenticated:
            form.email.data = current_user.email
            form.name.data = current_user.name

        if request.method == 'POST':
            if form.validate():
                Contact(email=form.email.data,
                        title=form.title.data,
                        name=form.name.data,
                        message=form.message.data).save_message()
                flash('Message Sent to Admin!')
                return redirect('/')
        return render_template('contact.html', form=form)

    if current_user.is_authenticated:
        if current_user.is_admin and mid and len(mid) == 24 and mid.isalnum():
            if Contact.get_message(mid):
                if request.method == 'POST':
                    Contact.delete_message(mid)
                    flash('Message Deleted!')
                    return redirect('/')
                return render_template('confirm_message_delete.html', mid=mid)
            return redirect('/')
    return render_template('404.html')
    def post(self):
        """ Submits a contact form """

        # Get POST data
        data = tornado.escape.json_decode(self.request.body.decode('utf-8'))
        first_name = data.get('first_name')
        last_name = data.get('last_name')
        email = data.get('email')
        content = data.get('content')
        recaptcha_response = data.get('recaptcha_response')

        x_real_ip = self.request.headers.get("X-Real-IP")
        client_ip = self.request.remote_ip if not x_real_ip else x_real_ip

        # Verify captcha
        captcha_result, error_response = self.verify_captcha(recaptcha_response, client_ip)
        if not captcha_result:
            self.write_response(error_response, status=400)
            return

        # Save user inputs
        if not first_name or not last_name or not email:
            return self.write_response('Missing required fields', status=400)

        # Create contact
        contact = Contact(first_name=first_name, last_name=last_name, email=email,
                          content=content, client_ip=client_ip)
        self.session.add(contact)

        if not self.send_email(contact):
            self.write_response("Failed to send email - please try again later", status=500)

        # Success
        self.write_response(contact.as_dict(), status=201)
Beispiel #9
0
def test_edit_some_contact(app, db, check_ui):
    if len(db.get_contact_list()) == 0:
        app.contact.add_new(Contact(firstname="First contact"))
    old_contacts = db.get_contact_list()
    index = randrange(len(old_contacts))
    contact = Contact(firstname="autotest",
                      lastname="autotest",
                      middlename=u"Отчество",
                      nickname=u"Никнейм",
                      title=u"Заголовок",
                      company=u"Компания",
                      address=u"Адрес",
                      home_phone=u"Домашний телефон",
                      mobile_phone=u"Мобильный телефон",
                      work_phone=u"Рабочий телефон",
                      fax=u"Факс",
                      email=u"электронная почта",
                      email2="email2",
                      email3="email3",
                      homepage=u"сайт",
                      address2=u"адрес2",
                      phone2=u"дом",
                      notes=u"заметка")
    contact.id_contact = old_contacts[index].id_contact
    app.contact.edit_contact_by_index(index, contact)
    assert len(old_contacts) == app.contact.count_edit()
    new_contacts = db.get_contact_list()
    old_contacts[index] = contact
    assert sorted(old_contacts,
                  key=Contact.id_or_max) == sorted(new_contacts,
                                                   key=Contact.id_or_max)
    if check_ui:
        assert sorted(new_contacts, key=Contact.id_or_max) == sorted(
            app.contact.get_group_list(), key=Contact.id_or_max)
Beispiel #10
0
 def test_get_best_voter(self):
     addr = Address({'address': '3000 Newcastle Rd'})
     pn = PersonName({'last_name': 'weinblatt', 'first_name': 'howard'})
     contact = Contact()
     contact.name = pn
     contact.address = addr
     voter = Contact.get_best_voter_rec(self.dao, contact)
     pass
Beispiel #11
0
def update_many():
    data = json.loads(request.form['params'])
    contacts = [Contact(item) for item in data['data']]
    try:
        Contact.update_many(contacts)
        return jsonify(msg='Records updated!')
    except Exception as ex:
        return jsonify(error=str(ex))
Beispiel #12
0
def prompt_add_new_contact():
    """Add a new contact for user"""
    user_id = int(input("Please enter your user id: "))
    contact_name = input("Please enter contact name: ")
    contact_phone_num = input("Please enter contact phone no: ")
    contact_email = input("Please enter contact email: ")
    new_contact = Contact(contact_name, contact_phone_num, contact_email,
                          user_id)
    new_contact.save()
Beispiel #13
0
    def post(self):
        data = ApiContact.parser.parse_args()
        print('you are here')
        contact = Contact(data['name'], data['email'])
        try:
            contact.save_to_db()
        except:
            return {'message' : 'Failed to save'}, 500

        return contact.json(), 201
 def test_get_block(self):
     dao = Dao(db_file='c:/bench/bluestreets/data/26161.db', stateful=True)
     contact = Contact()
     contact.address = Address({'address': '3000 Newcastle Rd'})
     contact.zipcode = '48105'
     block = Location.get_block(dao, contact)
     contact.zipcode = ''
     contact.city = 'ANN ARBOR'
     block = Location.get_block(dao, contact)
     dao.close()
Beispiel #15
0
 def test_get_best_turf(self):
     contact = Contact()
     contact.address = Address({
         'address': '3000 Newcastle Rd',
         'zipcode': '48105'
     })
     turf = Contact.get_best_turf(self.dao, contact)
     contact.address.zipcode = ''
     contact.address.city = 'ANN ARBOR'
     turf = Contact.get_best_turf(self.dao, contact)
     pass
Beispiel #16
0
def contact_matches():
    contact = Contact(json.loads(request.form['params']))
    dao = Dao(stateful=True)
    try:
        matches = contact.get_matches(dao)
        for match in matches:
            match['name'] = str(PersonName(match))
            match['address'] = str(Address(match))
        return jsonify(matches=matches)
    except Exception as ex:
        return jsonify(error=str(ex))
 def test_get_best_voter(self):
     addr = Address({'address': '3000 Newcastle Rd'})
     pn = PersonName({
         'last_name': 'weinblatt',
         'first_name': 'howard'
     })
     contact = Contact()
     contact.name = pn
     contact.address = addr
     voter = Contact.get_best_voter_rec(self.dao, contact)
     pass
 def test_get_best_turf(self):
     contact = Contact()
     contact.address = Address({
         'address': '3000 Newcastle Rd',
         'zipcode': '48105'
     })
     turf = Contact.get_best_turf(self.dao, contact)
     contact.address.zipcode = ''
     contact.address.city = 'ANN ARBOR'
     turf = Contact.get_best_turf(self.dao, contact)
     pass
Beispiel #19
0
def test_add_contact_to_group(app, db, orm):
    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact(firstname="Test", lastname="TEST"))
    if len(db.get_group_list()) == 0:
        app.group.create(Group(name_group="Test", header="Test",
                               footer="Test"))
    group = random.choice(orm.get_group_list())
    if len(orm.get_contacts_not_in_group(group)) == 0:
        app.contact.create(Contact(firstname="New"))
    contact = random.choice(orm.get_contacts_not_in_group(group))
    app.contact.add_to_group(contact.id_contact, group.id_group)
    assert contact in orm.get_contacts_in_group(group)
Beispiel #20
0
	def get(self):
		contact_user_email= self.request.get('contact_user_email')
		user = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			user = User.checkToken(self.request.cookies.get('our_token'))
		if not user:
			html = template.render("web/templates/index.html", {})
			self.response.write(html)
			return
		Contact.remove(user.key, contact_user_email)
		self.response.set_cookie('our_token', str(user.key.id()))
		self.response.write(json.dumps({'status':'OK'}))
		return
Beispiel #21
0
def assign_precinct():
    from models.precinct import Precinct

    if request.method == 'GET':
        precincts = Precinct.get_all()
        contacts = Contact.get_with_missing_precinct()
        return render_template('contacts/con_precinct.html',
                               title='Unassigned Precinct',
                               precincts=precincts,
                               contacts=contacts)

    params = json.loads(request.form['params'])
    contact = Contact(params)
    dao = Dao(stateful=True)
    if 'voter_id' in params and params['voter_id']:
        voter = Voter.get_one(dao, params['voter_id'])
        nickname = contact.name.first
        contact.name = voter.name
        contact.name.nickname = nickname
        contact.address = voter.address
        contact.reg_date = voter.reg_date
    try:
        contact.update(dao)
        return jsonify(msg="Update successful!")
    except Exception as ex:
        return jsonify(error=str(ex))
    finally:
        dao.close()
def test_modify_f_name(app, db, check_ui):
    if len(db.get_contact_list()) == 0:
        app.contact.add_new(Contact(f_name="Kevin"))
    old_contacts = db.get_contact_list()
    index = randrange(len(old_contacts))
    contact = Contact(f_name="Edward", l_name="Smith")
    contact.id = old_contacts[index].id
    app.contact.modify_contact_by_id(contact.id, contact)
    new_contacts = db.get_contact_list()
    assert len(old_contacts) == len(new_contacts)
    old_contacts[index] = contact
    if check_ui:
        assert sorted(old_contacts,
                      key=Contact.id_or_max) == sorted(new_contacts,
                                                       key=Contact.id_or_max)
Beispiel #23
0
 def get(self):
     contact_user_email = self.request.get('contact_user_email')
     user = None
     if self.request.cookies.get(
             'our_token'
     ):  #the cookie that should contain the access token!
         user = User.checkToken(self.request.cookies.get('our_token'))
     if not user:
         html = template.render("web/templates/index.html", {})
         self.response.write(html)
         return
     Contact.remove(user.key, contact_user_email)
     self.response.set_cookie('our_token', str(user.key.id()))
     self.response.write(json.dumps({'status': 'OK'}))
     return
Beispiel #24
0
 def unfollow(self, from_id):
     contact = Contact.get_follow_item(from_id, self.id)
     if contact:
         contact.delete()
         self._stats = None
         return True
     return False
Beispiel #25
0
 def get_contact_list(self):
     list = []
     cursor = self.connection.cursor()
     try:
         cursor.execute("select id, firstname, lastname, address, home,"
                        " mobile, work, email, email2, email3, phone2"
                        " from addressbook"
                        " where deprecated='0000-00-00 00:00:00'")
         for row in cursor:
             (id, firstname, lastname, address, home, mobile, work, email,
              email2, email3, phone2) = row
             list.append(
                 Contact(id=str(id),
                         firstname=firstname,
                         lastname=lastname,
                         address=address,
                         home=home,
                         mobile=mobile,
                         work=work,
                         email=email,
                         email2=email2,
                         email3=email3,
                         phone2=phone2))
     finally:
         cursor.close()
     return list
    def post(self, quiz_id, contact_group=None):
        session = authorize(request.headers["Authorization"])

        if contact_group is None: contact_group = "default"

        contacts = self.get_contacts(contact_group, session.get("user").get("login"))

        if contacts is None:
            return {"message": "no contact to send"}, 400

        criteria = {"createdBy": session.get('user').get('login'), "_id": int(quiz_id)}
        quiz = Quiz.quiz_from_dict(mongo.db.quiz.find_one_or_404(criteria))

        for contact in contacts:
            c = Contact.contact_from_dict(contact)
            p = Publication()
            p._id = get_id("publication")
            p.creationDate = datetime.now()
            p.hash = hashlib.sha256("%d.%s" % (p._id, str(p.creationDate))).hexdigest()
            p.by = session.get('user').get('login')
            p.quiz = quiz
            p.to = c
            mongo.db.publications.insert(p.format())
            self.send_email(quiz.title, p.hash, c.email, c.language)

        return {"message": "quiz %s published to %d contacts" % (quiz.title, len(contacts))}, 200
Beispiel #27
0
 def get_contact_info_from_edit_page(self, index):
     wd = self.app.wd
     self.start_edit_by_index(index)
     id = wd.find_element_by_name("id").get_attribute("value")
     firstname = wd.find_element_by_name("firstname").get_attribute("value")
     lastname = wd.find_element_by_name("lastname").get_attribute("value")
     address_one = wd.find_element_by_name("address").text
     email_one = wd.find_element_by_name("email").get_attribute("value")
     email_two = wd.find_element_by_name("email2").get_attribute("value")
     email_three = wd.find_element_by_name("email3").get_attribute("value")
     home = wd.find_element_by_name("home").get_attribute("value")
     work = wd.find_element_by_name("work").get_attribute("value")
     mobile = wd.find_element_by_name("mobile").get_attribute("value")
     phone_two = wd.find_element_by_name("phone2").get_attribute("value")
     return Contact(id=id,
                    f_name=firstname,
                    l_name=lastname,
                    address_one=address_one,
                    email_one=email_one,
                    email_two=email_two,
                    email_three=email_three,
                    home=home,
                    mobile=mobile,
                    work=work,
                    phone_two=phone_two)
Beispiel #28
0
def test_delete_contact_from_group(app, db):
    db = ORMFixture(host="127.0.0.1",
                    name="addressbook",
                    user="******",
                    password="")
    with allure.step('Check group and contact'):
        if len(db.get_group_list()) == 0:
            app.group.creation(Group(name="test"))
        if len(db.get_contact_list()) == 0:
            app.contact.creation(Contact(first_name="test"))
    with allure.step('Given a group list, contact list and random group'):
        old_groups = db.get_group_list()
        old_contacts = db.get_contact_list()
        group = random.choice(old_groups)
        group_id = group.id
    with allure.step('Check contact in group %s' % group):
        if len(db.get_contacts_in_group(Group(id=group_id))) == 0:
            contact = random.choice(old_contacts)
            contact_id = contact.id
            app.contact.add_contact_to_group(contact_id, group_id)
    with allure.step(
            'Given a old contacts in group list and random contact to delete'):
        old_contacts_in_group = db.get_contacts_in_group(Group(id=group_id))
        contact_to_delete = random.choice(old_contacts_in_group)
        contact_to_delete_id = contact_to_delete.id
    with allure.step('When I remove a contact %s from the group %s' %
                     (contact_to_delete, group)):
        app.contact.delete_contact_from_group(contact_to_delete_id, group_id)
    with allure.step(
            'Then the new contacts in group list is equal to the old contacts in group list withouth the deleted contact'
    ):
        new_contacts_in_group = db.get_contacts_in_group(Group(id=group_id))
        old_contacts_in_group.remove(contact_to_delete)
        assert new_contacts_in_group == old_contacts_in_group
Beispiel #29
0
def non_empty_contacts_list(db, app):
    if len(db.get_contact_list()) == 0:
        app.contact.open_contact_page()
        app.contact.creation(
            Contact(firstname='qwer',
                    middlename='qwer',
                    lastname='wert',
                    nickname='asd',
                    title='fsdf',
                    company='fsd',
                    address='dfsdf',
                    homephone='45345',
                    mobilephone='2312',
                    workphone='2342',
                    fax='23213',
                    email='*****@*****.**',
                    email2='*****@*****.**',
                    email3='*****@*****.**',
                    homepage='sfsdfs.sdf',
                    byear='1900',
                    ayear='2000',
                    address2='sdfsdfsd',
                    secondaryphone='233534',
                    notes='dfsdf'))
        app.contact.submit_contact_creation()
        app.open_homepage()
    return db.get_contact_list()
Beispiel #30
0
def render_user_page(identifier, renderer, target_cls, type='following',
                     endpoint=None):
    user = User.get(identifier)
    if not user:
        abort(404)
    page = request.args.get('page', default=1, type=int)
    if type == 'collect':
        p = CollectItem.get_paginate_by_user(user.id, page=page)
    elif type == 'like':
        p = LikeItem.get_paginate_by_user(user.id, page=page)
    elif type == 'following':
        p = Contact.get_following_paginate(user.id, page=page)
    elif type == 'followers':
        p = Contact.get_followers_paginate(user.id, page=page)
    p.items = target_cls.get_multi(p.items)
    return render_template(renderer, **locals())
Beispiel #31
0
 def get_contact_list(self):
     if self.contact_cache is None:
         wd = self.app.wd
         self.open_home_page()
         self.contact_cache = []
         for element in wd.find_elements_by_css_selector(
                 "tr[name='entry']"):
             id = element.find_element_by_name("selected[]").get_attribute(
                 "id")
             first_name_contact = element.find_elements_by_tag_name(
                 "td")[2].text
             last_name_contact = element.find_elements_by_tag_name(
                 "td")[1].text
             all_phones = element.find_elements_by_tag_name("td")[5].text
             address_contact = element.find_elements_by_tag_name(
                 "td")[3].text
             all_emails = element.find_elements_by_tag_name("td")[4].text
             self.contact_cache.append(
                 Contact(first_name_contact=first_name_contact,
                         last_name_contact=last_name_contact,
                         id=id,
                         all_phones_from_home_page=all_phones,
                         address_contact=address_contact,
                         all_emails_from_home_page=all_emails))
     return list(self.contact_cache)
Beispiel #32
0
 def get_contact_info_from_edit_page(self, index):
     wd = self.app.wd
     self.open_contact_to_edit_by_index(index)
     first_name_contact = wd.find_element_by_name(
         "firstname").get_attribute("value")
     last_name_contact = wd.find_element_by_name("lastname").get_attribute(
         "value")
     id = wd.find_element_by_name("id").get_attribute("value")
     home_contact = wd.find_element_by_name("home").get_attribute("value")
     work_contact = wd.find_element_by_name("work").get_attribute("value")
     mobile_contact = wd.find_element_by_name("mobile").get_attribute(
         "value")
     secondary_home = wd.find_element_by_name("phone2").get_attribute(
         "value")
     address_contact = wd.find_element_by_name("address").get_attribute(
         "value")
     e_mail_contact = wd.find_element_by_name("email").get_attribute(
         "value")
     e_mail_2_contact = wd.find_element_by_name("email2").get_attribute(
         "value")
     e_mail_3_contact = wd.find_element_by_name("email3").get_attribute(
         "value")
     return Contact(first_name_contact=first_name_contact,
                    last_name_contact=last_name_contact,
                    id=id,
                    home_contact=home_contact,
                    mobile_contact=mobile_contact,
                    work_contact=work_contact,
                    secondary_home=secondary_home,
                    address_contact=address_contact,
                    e_mail_contact=e_mail_contact,
                    e_mail_2_contact=e_mail_2_contact,
                    e_mail_3_contact=e_mail_3_contact)
Beispiel #33
0
def contactData(req):
    back = {'status':'ok'}
    if req.META.has_key('HTTP_X_FORWARDED_FOR'):
        ip =  request.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = req.META['REMOTE_ADDR']
    q = req.GET or req.POST
    if Contact.objects.filter(ip=ip,check=0):
        back['status'] = 'error'
        back['msg'] = '您已提交信息,不能重复提交,我们会尽快跟您联系'
    else:
        c = Contact(name=q.get('name') or None,sex=q.get('sex') or None,email=q.get('email') or None,phone=q.get('phone') or None,advice=q.get('advice') or None,reply=q.get('reply') or None,ip=ip)
        c.save()
        back['msg'] = '您已提交信息,我们会尽快跟您联系'
        back['id'] = c.id
    return to_json(back)
Beispiel #34
0
 def get_contact_info_from_edit_page(self, index):
     wd = self.app.wd
     self.open_contact_to_edit_by_index(index)
     first_name = wd.find_element_by_name("firstname").get_attribute(
         "value")
     last_name = wd.find_element_by_name("lastname").get_attribute("value")
     id = wd.find_element_by_name("id").get_attribute("value")
     home_phone = wd.find_element_by_name("home").get_attribute("value")
     mobile_phone = wd.find_element_by_name("mobile").get_attribute("value")
     work_phone = wd.find_element_by_name("work").get_attribute("value")
     secondary_phone = wd.find_element_by_name("phone2").get_attribute(
         "value")
     email = wd.find_element_by_name("email").get_attribute("value")
     email2 = wd.find_element_by_name("email2").get_attribute("value")
     email3 = wd.find_element_by_name("email3").get_attribute("value")
     address = wd.find_element_by_name("address").get_attribute("value")
     return Contact(first_name=first_name,
                    last_name=last_name,
                    id=id,
                    address=address,
                    email=email,
                    email2=email2,
                    email3=email3,
                    home_phone=home_phone,
                    mobile_phone=mobile_phone,
                    work_phone=work_phone,
                    secondary_phone=secondary_phone)
Beispiel #35
0
def test_delete_contact_from_group(app):
    db = ORMFixture(host="localhost",
                    name="addressbook",
                    user="******",
                    password="")

    if len(db.get_contact_list()) == 0:
        app.contact.create(Contact(firstname="Bro", lastname="Lu"))
    if len(db.get_group_list()) == 0:
        app.group.create(
            Group(name="Group1", header="header1", footer="footer1"))

    groups = db.get_group_list()
    group = random.choice(groups)
    contacts = db.get_contact_list()
    contact = random.choice(contacts)

    if len(db.get_contacts_in_group(group)) == 0:
        app.contact.add_contact_to_group(contact.id, group.id)

    contacts_in_group = db.get_contacts_in_group(group)
    contact_for_delete = random.choice(contacts_in_group)

    app.contact.delete_contact_from_group(contact_for_delete.id, group.id)

    contacts_not_in_group = db.get_contacts_not_in_group(group)
    assert contact_for_delete in contacts_not_in_group
Beispiel #36
0
 def get_contact_data_editpage(self, index):
     wd = self.app.wd
     self.open_homepage()
     wd.find_elements_by_xpath("//img[@alt='Edit']")[index].click()
     first_name = wd.find_element_by_name("firstname").get_attribute(
         "value")
     last_name = wd.find_element_by_name("lastname").get_attribute("value")
     email_1 = wd.find_element_by_name("email").get_attribute("value")
     email_2 = wd.find_element_by_name("email2").get_attribute("value")
     email_3 = wd.find_element_by_name("email3").get_attribute("value")
     address = wd.find_element_by_name("address").get_attribute("value")
     home_phone = wd.find_element_by_name("home").get_attribute("value")
     mobile_phone = wd.find_element_by_name("mobile").get_attribute("value")
     work_phone = wd.find_element_by_name("work").get_attribute("value")
     fax = wd.find_element_by_name("fax").get_attribute("value")
     id = wd.find_element_by_name("id").get_attribute("value")
     return Contact(first_name=first_name,
                    last_name=last_name,
                    email_1=email_1,
                    email_2=email_2,
                    email_3=email_3,
                    address=address,
                    home_phone=home_phone,
                    mobile_phone=mobile_phone,
                    work_phone=work_phone,
                    fax=fax,
                    id=id)
Beispiel #37
0
	def get(self):
		template_params={}
		user = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			user = User.checkToken(self.request.cookies.get('our_token'))
		if not user:
			html = template.render("web/templates/index.html", {})
			self.response.write(html)
			return
		#newlinks
		linkslist=Link.getAllLinksPerUser(user)	
		newurls = []
		template_params = {}
		if linkslist:
			for link in linkslist:
				url = link.url_link
				des = link.description
				fromlink=link.from_link
				if fromlink is not None:
					urlandlink =[url,des,fromlink]
					newurls.append(urlandlink)
			template_params['newurls'] = newurls
		#newlinks
		template_params['useremail'] = user.email
		contactlist= Contact.getAllContactsPerUser(user)
		contacts= []
		if contactlist:
			for contact in contactlist:
				contact_email= contact.contact_user_email
				contact_nickname= contact.nick_name
				email_and_nickname= [contact_email, contact_nickname]
				contacts.append(email_and_nickname)
			template_params['contacts']=contacts
		html = template.render("web/templates/contactspage.html", template_params)
		self.response.write(html)
Beispiel #38
0
def test_add_contact_in_group(app, db):
    db = ORMFixture(host="127.0.0.1",
                    name="addressbook",
                    user="******",
                    password="")
    with allure.step('Check group and contact'):
        if len(db.get_group_list()) == 0:
            app.group.creation(Group(name="test"))
        if len(db.get_contact_list()) == 0:
            app.contact.creation(Contact(first_name="test"))
    with allure.step('Given a group list'):
        old_groups = db.get_group_list()
    with allure.step(
            'Given a group, contact not in group and contact in group'):
        group = random.choice(old_groups)
        group_id = group.id
        contacts_without_group = db.get_contacts_not_in_group(
            Group(id=group_id))
        contact = random.choice(contacts_without_group)
        contact_id = contact.id
        old_contacts_in_group = db.get_contacts_in_group(Group(id=group_id))
    with allure.step('When I add a contact %s to the group %s' %
                     (contact, group)):
        app.contact.add_contact_to_group(contact_id, group_id)
    with allure.step(
            'Then the new contacts in group list is equal to the old contacts in group list with the added contact'
    ):
        new_contacts_in_group = db.get_contacts_in_group(Group(id=group_id))
        old_contacts_in_group.append(contact)
        assert sorted(new_contacts_in_group,
                      key=Contact.id_or_max) == sorted(old_contacts_in_group,
                                                       key=Contact.id_or_max)
Beispiel #39
0
def post_contact():
    """
    Adds contact.

    request body must specify as json:
        name - name of contact.
        email_address - email address of contact.
        message - a message.

    returns:
        json success or failure plus corresponding http status.
    """
    contact_request = request.get_json()
    contact = Contact(**contact_request)
    success = contact.save()

    return jsonify({"contact": contact.id})
Beispiel #40
0
    def publication_from_dict(pubDict):
        p = Publication()
        p.by = pubDict.get('by')
        p.to = Contact.contact_from_dict(pubDict.get('to'))
        p.creationDate = pubDict.get('creationDate')
        p.hash = pubDict.get('hash')
        p._id = pubDict.get('_id')

        return p
Beispiel #41
0
 def setUp(self):
     self.app = app
     self.app.register_blueprint(admin, url_prefix='/admin')
     self.test_client = self.app.test_client()
     self.db = db
     self.db.create_all()
     contact = Contact(name="Irene",
                       email_address="*****@*****.**",
                       message="Hi")
     contact.save()
     self.admin = User(email_address="*****@*****.**",
                       password="******",
                       admin=True)
     self.admin.save()
     self.not_admin = User(email_address="*****@*****.**",
                           password="******",
                           admin=False)
     self.not_admin.save()
Beispiel #42
0
def crewboard():
    if request.method == 'GET':
        dao = Dao(stateful=True)
        contacts = Contact.get_activists(dao)
        precincts = Precinct.get_all(dao)
        return render_template(
            'con_crewboard.html',
            title='Battle Stations',
            contacts=[contact.serialize() for contact in contacts],
            precincts=[precinct.serialize() for precinct in precincts]
        )
Beispiel #43
0
	def get(self):
		template_params={}
		contact_user_email= self.request.get('contact_user_email')
		nick_name= self.request.get('nick_name')
		user = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			user = User.checkToken(self.request.cookies.get('our_token'))
		if not user:
			html = template.render("web/templates/index.html", {})
			self.response.write(html)
			return
		userCon= User.checkIfUesr(contact_user_email)
		if userCon is None:
			return
#		contactlist= Contact.getAllContactsPerUser(user)
#		for c in contactlist:
#			if c..contact_user_email is contact_user_email:
#				return
		contact=Contact()
		contact.contact_user_email=contact_user_email
		contact.nick_name=nick_name
		contact.user=user.key
		contact.put()
		self.response.set_cookie('our_token', str(user.key.id()))
		self.response.write(json.dumps({'status':'OK'}))
		return
Beispiel #44
0
    def participation_from_dict(pDict):
        p = Participation()
        p.quiz_id = pDict.get('quiz_id')
        p.pub_hash = pDict.get('pub_hash')
        p.pub_date = pDict.get('pub_date')
        p.creationDate = pDict.get('creationDate')
        p.contact = Contact.contact_from_dict(pDict.get('contact'))
        p._id = pDict.get('_id')

        if not (pDict.get('answers') is None):
            for a in pDict.get('answers'):
                p.answers.append(Answer.answer_from_dict(a))

        return p
    def post(self, group_name=None):
        session = authorize(request.headers["Authorization"])
        print session

        contacts = post_parser.parse_args().get("contacts")
        if contacts is None:
            abort(403)

        if group_name is None: group_name = "default"

        new_contacts = 0
        existing_contact = 0
        for contact in contacts:
            print contact
            contact = Contact.contact_from_dict(contact)
            existing = mongo.db.contacts.find_one({"email": contact.email})

            if existing is None:
                contact._id = get_id("contacts")
                contact.creationDate = datetime.now()
                contact.createdBy = session.get("user").get("login")
                if contact.language is None:
                    contact.language = "fr"

                mongo.db.contacts.insert(contact.format())

                self.update_group(group_name, contact.createdBy, contact)

                new_contacts += 1
            else:
                existing_contact += 1
                contact = Contact.contact_from_dict(existing)
                self.update_group(group_name, contact.createdBy, contact)



        return {"inserted": new_contacts, "existing": existing_contact}, 200
Beispiel #46
0
 def test_contact_save(self):
     contact = Contact(name="Irene",
                       email_address="*****@*****.**",
                       message="Hey.")
     contact.save()
     self.assertIsNotNone(contact.id)
Beispiel #47
0
 def test_contact_invalid_null_field(self):
     contact = Contact(name="Irene",message="Hey.")
     with self.assertRaises(IntegrityError):
         contact.save()
     self.assertIsNone(contact.id)
    def get_all_contacts(self):
        contacts = []
        for c in mongo.db.contacts.find():
            contacts.append(Contact.contact_from_dict(c).format())

        return contacts, 200
 def test_clean_turf(self):
     num, unresolved = Contact.assign_precinct(self.dao)
     pass
 def test_get_activists(self):
     rex = Contact.get_activists(self.dao)
     pass