Exemple #1
0
    def test_add_rep(self):
        Representative.add_rep(single_rep2)

        testrep = Representative.query.get(2)
        self.assertIsNotNone(testrep)
        self.assertEqual(testrep.full_name, 'George Borrello')
        self.assertEqual(testrep.first_name, 'George')
        self.assertEqual(testrep.last_name, 'Borrello')
        self.assertEqual(testrep.photo_url, '')
        self.assertEqual(testrep.email, '*****@*****.**')
        self.assertEqual(testrep.serving, True)
        self.assertEqual(testrep.party, 'Republican')
        # district info
        self.assertEqual(testrep.district.state, 'ny')
        self.assertEqual(testrep.district.district_num, '57')
        self.assertEqual(testrep.district.house, 'upper')
        # website info
        self.assertEqual(testrep.websites[0]['url'], "https://www.nysenate.gov/senators/george-m-borrello")
        # office info
        self.assertEqual(testrep.offices[0].location, 'Capitol Office')
        self.assertEqual(testrep.offices[0].phone, '518-455-3563')
        self.assertEqual(testrep.offices[0].address, '188 State Street, Legislative Office Building; Room 706; Albany, NY 12247')
        self.assertEqual(testrep.offices[1].location, 'District Office')
        self.assertEqual(testrep.offices[1].phone, '716-664-4603')
        self.assertEqual(testrep.offices[1].address, '2-6 E. Second Street; Fenton Building, Suite 302; Jamestown, NY 14701')
Exemple #2
0
def signup():

    form = RegistrationForm()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data
        address = form.address.data

        user = User.register(
            username=username,
            password=password,
            email=email,
            first_name=first_name,
            last_name=last_name,
            address=address,
        )
        # latLng = Representative.find_latlng(address)
        # lat = latLng['lat']
        # lng = latLng['lng']

        reps = Representative.find_reps(address)

        for rep in reps:

            r = Representative.add_rep(rep)

            user.representatives.append(r)
            db.session.commit()

            login_user(user)
        flash("Signup successful")
        flash("Welcome")
        return redirect("/")

    if request.args:
        address = request.args["address"]
        form.address.data = address
        form.address.id = "search-input"
        form.address.type = "search"

        return render_template("signup.html", form=form, address=address)

    form.address.id = "search-input"
    form.address.type = "search"

    return render_template("signup.html", form=form)
Exemple #3
0
def build_representative(info, district=None, party_id=None):
    """
    Builds a Representative given the info for that Representative.

    info -- the dict of representative information

    Returns the Representative
    """

    if district is None:
        district = str(info['district'])
    if party_id is None:
        party_id = 2 if info['party'] == 'R' else 1

    return Representative(
        bioguide=info['id'],
        firstname=info['first_name'],
        lastname=info['last_name'],
        party_id=party_id,
        state=info['state'],
        district=district,
        twitter=info['twitter_account'],
        youtube=info['youtube_account'],
        facebook=info['facebook_account'],
        office=info['office'],
        votes_with_party_pct=info['votes_with_party_pct'],
        url=info['url'],
        image_uri=IMAGE_URL + info['id'] + '.jpg'
    )
Exemple #4
0
    def setUp(self):
        """Make sure we start with a clean slate"""

        db.drop_all()
        db.create_all()

        Office.query.delete()
        District.query.delete() 
        Representative.query.delete()
        User.query.delete()
        Interaction.query.delete()
        UserRepresentative.query.delete()

        test_office = Office(phone='123-555-1234', address='123 Test St.', location='district')
        test_district = District(state='ny', district_num='123', house='lower')

        db.session.add(test_office)
        db.session.add(test_district)
        db.session.commit()

        office = Office.query.get(1)
        district = District.query.get(1)

        test_rep = Representative(first_name='Testy', last_name='McTestface', full_name='Testy McTestface', photo_url='https://mn315.net/wp-content/uploads/2018/06/cropped-Ugandan-Knuckles.jpg', email='*****@*****.**', serving=True, district=district, websites=[
                    {
                        "url": "http://www.google.com"
                    },
                    {
                        "url": "http://tesla.com"
                    }
                ])
        test_user = User.register(username='******', password='******', first_name='Some', last_name='User', email='*****@*****.**', address='123 Any St., Anytown NY 12345')
        # login_test = User.register(username='******', password='******', first_name='test', last_name='test', email='*****@*****.**', address='82 Kent Blvd., Salamanca NY 14779')
        db.session.add(test_rep)
        db.session.add(test_user)
        # db.session.add(login_test)
        db.session.commit()

        user = User.query.get(1)
        self.user = user
        # user2 = User.query.get(2)
        rep = Representative.query.get(1)


        user.representatives.append(rep)
        rep.offices.append(office)
        # user2.representatives.append(rep)
        db.session.commit()

        # import pdb
        # pdb.set_trace()

        test_interaction = Interaction(user=user, representative=rep, district=district, interaction_date='2020-07-15 10:00:00', medium='email', topic='stuff and junk', content='all the things')
        db.session.add(test_interaction)

        db.session.commit()
Exemple #5
0
    def setUp(self):
        """start with a clean slate"""

        db.drop_all()
        db.create_all()

        rep1 = Representative.add_rep(single_rep1)

        db.session.commit()

        rep1 = Representative.query.get(rep1.id)

        self.rep1 = rep1
    def test_office_add(self):
        rep = Representative.add_rep(single_rep1)
        db.session.commit()
        o = Office.add_office(single_office)
        rep.offices.append(o)
        db.session.commit()

        testoffice = Office.query.get(1)
        # import pdb
        # pdb.set_trace()
        self.assertIsNotNone(testoffice)
        self.assertEqual(testoffice.phone, '716-664-4603')
        self.assertEqual(
            testoffice.address,
            '2-6 E. Second Street; Fenton Building, Suite 302; Jamestown, NY 14701'
        )
        self.assertEqual(testoffice.location, 'District Office')
Exemple #7
0
def your_reps():

    if not request.args["search-input"]:
        flash("Please enter an address")
        return redirect("/")

    address = request.args["search-input"]

    reps = Representative.find_reps(address=address)

    if not reps:
        flash(
            "No representatives found for the address. Please recheck your address"
        )
        flash("*NOTE: This is designed to find US state representatives only.")
        return redirect("/")
    return render_template("reps.html", reps=reps, address=address)
    def setUp(self):
        """ starts with a clean slate"""

        db.drop_all()
        db.create_all()

        user1 = User.register('user1', '11111', 'fname1', 'lname1',
                              '*****@*****.**', 'test address')
        rep1 = Representative.add_rep(single_rep1)

        db.session.commit()

        user1 = User.query.get(user1.id)
        rep1 = Representative.query.get(rep1.id)

        self.user1 = user1
        self.rep1 = rep1
Exemple #9
0
 def test_find_reps(self, mock_find_latlng, mock_find_reps):
     reps = Representative.find_reps('testaddress')
     self.assertEqual(reps, all_info)
Exemple #10
0
 def test_find_latlng(self, mock_find_latlng):
     coords = Representative.find_latlng('testaddress')
     self.assertEqual(coords, latLng)
Exemple #11
0
 def test_check_rep_wrong_status(self):
     testrep = Representative.check_rep('Joseph Giglio', 'ny', '148', 'lower', False)
     self.assertEqual(testrep, [])
Exemple #12
0
 def test_check_rep_wrong_house(self):
     testrep = Representative.check_rep('Joseph Giglio', 'ny', '148', 'upper', True)
     self.assertEqual(testrep, [])
Exemple #13
0
 def test_check_rep_wrong_state(self):
     testrep = Representative.check_rep('Joseph Giglio', 'fl', '148', 'lower', True)
     self.assertEqual(testrep, [])
Exemple #14
0
 def test_check_rep_wrong_name(self):
     testrep = Representative.check_rep('Bob Lablaw', 'ny', '148', 'lower', True)
     self.assertEqual(testrep, [])
Exemple #15
0
 def test_check_rep(self):
     testrep = Representative.check_rep('Joseph Giglio', 'ny', '148', 'lower', True)
     self.assertEqual(testrep, self.rep1)
Exemple #16
0
 def test_check_rep_wrong_distnum(self):
     testrep = Representative.check_rep('Joseph Giglio', 'ny', '147', 'lower', True)
     self.assertEqual(testrep, [])
Exemple #17
0
db.session.add(test_office)
db.session.add(test_district)
db.session.commit()

office = Office.query.get(1)
district = District.query.get(1)

test_rep = Representative(
    given_name="Testy",
    family_name="McTestface",
    name="Testy McTestface",
    image=
    "https://mn315.net/wp-content/uploads/2018/06/cropped-Ugandan-Knuckles.jpg",
    email="*****@*****.**",
    serving=True,
    district=district,
    websites=[{
        "url": "http://www.google.com"
    }, {
        "url": "http://tesla.com"
    }],
)
test_user = User.register(
    username="******",
    password="******",
    first_name="Some",
    last_name="User",
    email="*****@*****.**",
    address="123 Any St., Anytown NY 12345",
)