예제 #1
0
 def get_invite(self, invite_id):
     uri = '/invites/%s' % invite_id
     try:
         result_dict = self._rq.request('get', uri)
     except error.ResourceNotFoundError:
         return None
     iv = Invite(self._rq, **result_dict)
     return iv
 def most_popular(cls):
     guest_list = [invite.guest for invite in Invite.all()]
     guest_dict = {
         guest: guest_list.count(guest)
         for guest in set(guest_list)
     }
     most_popular = max(guest_dict.values())
     return [
         key for key, value in guest_dict.items() if value == most_popular
     ][0]
예제 #3
0
 def get_once(self, token):
     uri = '/invites/get_once'
     try:
         result_dict = self._rq.request('get',
                                        uri,
                                        headers={'X-Invite-Token': token})
     except error.ResourceNotFoundError:
         return None
     iv = Invite(self._rq, **result_dict)
     return iv
예제 #4
0
    def send_invite(self, **kwargs):
        post_data = {}
        for field in INVT_CREATE_FIELDS:
            if field in kwargs:
                post_data[field] = kwargs[field]

        uri = '/invites/send'
        result_dict = self._rq.request('post', uri, post_data=post_data)
        iv = Invite(self._rq, **result_dict)
        return iv
예제 #5
0
 def accept_invite(self, user_id, token):
     uri = '/invites/accept'
     result_dict = self._rq.request('post',
                                    uri,
                                    post_data={
                                        'user_id': user_id,
                                        'token': token
                                    })
     iv = Invite(self._rq, **result_dict)
     return iv
예제 #6
0
    def get_invites(self, limit=25, next_page=None):
        uri_params = {}
        if limit:
            uri_params['limit'] = limit
        if next_page:
            uri_params['next_page'] = next_page

        uri = '/invites'
        result_list = self._rq.request('get', uri, uri_params=uri_params)

        invite_list = InviteList()
        for invite_dict in result_list.get('invites', []):
            invite_list.append(Invite(self._rq, **invite_dict))

        invite_list.next_page = result_list.get('next_page')
        return invite_list
예제 #7
0
 def number_of_attendees(self):
     attendee_list = [invite.guest for invite in Invite.all() if invite.accepted == True]
     return len(attendee_list)
class TestHasManyThroughMiniProj(unittest.TestCase):

    global guest_1
    guest_1 = Guest("Dwight Schrute")
    global guest_2
    guest_2 = Guest("Michael Scott")
    global guest_3
    guest_3 = Guest("Pam Beasley")
    global dinner_party_1
    dinner_party_1 = DinnerParty("Office Christmas Party")
    global dinner_party_2
    dinner_party_2 = DinnerParty("Your parent's friend's")
    global dinner_party_3
    dinner_party_3 = DinnerParty("Friend's House Warming")
    global invite_1
    invite_1 = Invite(dinner_party_1, guest_1)
    global invite_2
    invite_2 = Invite(dinner_party_1, guest_2)
    global invite_3
    invite_3 = Invite(dinner_party_1, guest_3)
    global invite_4
    invite_4 = Invite(dinner_party_2, guest_1)
    global invite_5
    invite_5 = Invite(dinner_party_3, guest_1)
    global recipe_1
    recipe_1 = Recipe("Disaster")
    global recipe_2
    recipe_2 = Recipe("Punch")
    global recipe_3
    recipe_3 = Recipe("Cookies")
    global recipe_4
    recipe_4 = Recipe("Punch")
    global recipe_5
    recipe_5 = Recipe("Cookies")
    global recipe_6
    recipe_6 = Recipe("Punch")
    global course_1
    course_1 = Course(dinner_party_1, recipe_1)
    global course_2
    course_2 = Course(dinner_party_1, recipe_2)
    global course_3
    course_3 = Course(dinner_party_1, recipe_3)
    global course_4
    course_4 = Course(dinner_party_1, recipe_4)
    global course_5
    course_5 = Course(dinner_party_2, recipe_5)
    global course_6
    course_6 = Course(dinner_party_2, recipe_6)
    global course_7
    course_7 = Course(dinner_party_2, recipe_2)
    global review_1
    review_1 = Review(guest_1, recipe_1, 3,
                      "the Disaster wasn't as bad as I would've liked")
    global review_2
    review_2 = Review(guest_2, recipe_1, 5,
                      "It was total chaos, exceeded expectations")
    global review_3
    review_3 = Review(guest_3, recipe_1, 4, "Just disastrous, nothing more")
    global review_4
    review_4 = Review(guest_1, recipe_2, 2, "way too much pineapple juice!")
    global review_5
    review_5 = Review(guest_2, recipe_2, 2, "not enough pineapple juice!")
    global review_6
    review_6 = Review(
        guest_3, recipe_2, 3,
        "right amount of pineapple juice, but wasn't anything to write home about"
    )
    global review_7
    review_7 = Review(guest_1, recipe_3, 2,
                      "I don't like cookies, that's all.")
    global review_8
    review_8 = Review(guest_2, recipe_1, 4, "Pretty disastrous, nothing more")
    global review_9
    review_9 = Review(guest_3, recipe_1, 4, "Meh, I've seen more bedlam")
    global review_10
    review_10 = Review(guest_1, recipe_4, 1,
                       "It was more of a slap in the face")

    def test_guest_class_methods(self):
        self.assertItemsEqual(Guest.all(), [guest_1, guest_2, guest_3])
        self.assertEqual(Guest.most_popular(), guest_1)
        self.assertEqual(Guest.toughest_critic(), guest_1)
        self.assertEqual(Guest.most_active_critic(), guest_1)

    def test_guest_instance_methods(self):
        self.assertEqual(guest_1.rsvp(invite_1, True), True)
        self.assertEqual(guest_1.number_of_invites(), 3)
        self.assertEqual(
            len(
                guest_1.review_recipe(
                    recipe_1, 3,
                    "The disaster just wasn't disastrous enough!")), 6)
        Review._all.pop()
        self.assertEqual(guest_1.favorite_recipe(), recipe_1)

    def test_invite_class_methods(self):
        self.assertItemsEqual(
            Invite._all, [invite_1, invite_2, invite_3, invite_4, invite_5])
        self.assertItemsEqual(
            Invite.all(), [invite_1, invite_2, invite_3, invite_4, invite_5])

    def test_invite_instance_methods(self):
        self.assertEqual(guest_1.rsvp(invite_1, True), True)
        self.assertEqual(invite_1.accepted, True)
        self.assertEqual(invite_1.dinner_party, dinner_party_1)

    def test_dinner_party_class_methods(self):
        self.assertItemsEqual(DinnerParty.all(),
                              [dinner_party_1, dinner_party_2, dinner_party_3])

    def test_dinner_party_instance_methods(self):
        self.assertItemsEqual(dinner_party_1.reviews(), [
            review_1, review_2, review_3, review_4, review_5, review_6,
            review_7, review_8, review_9, review_10
        ])
        self.assertItemsEqual(dinner_party_1.recipes(),
                              [recipe_1, recipe_2, recipe_3, recipe_4])
        self.assertEqual(dinner_party_1.recipe_count(), 4)
        self.assertEqual(dinner_party_1.highest_rated_recipe(), recipe_1)
        invite_1.accepted = True
        invite_2.accepted = True
        invite_3.accepted = True
        self.assertEqual(dinner_party_1.number_of_attendees(), 3)

    def test_review_class_methods(self):
        self.assertItemsEqual(Review._all, [
            review_1, review_2, review_3, review_4, review_5, review_6,
            review_7, review_8, review_9, review_10
        ])
        self.assertItemsEqual(Review.all(), [
            review_1, review_2, review_3, review_4, review_5, review_6,
            review_7, review_8, review_9, review_10
        ])

    def test_review_instance_methods(self):
        self.assertEqual(review_1.rating, 3)
        self.assertEqual(review_1.reviewer, guest_1)
        self.assertEqual(review_1.recipe, recipe_1)
        self.assertEqual(review_1.comment,
                         "the Disaster wasn't as bad as I would've liked")

    def test_recipe_class_methods(self):
        self.assertItemsEqual(
            Recipe.all(),
            [recipe_1, recipe_2, recipe_3, recipe_4, recipe_5, recipe_6])
        self.assertItemsEqual(Recipe.top_three(),
                              [recipe_1, recipe_2, recipe_3])
        self.assertItemsEqual(Recipe.bottom_three(),
                              [recipe_4, recipe_2, recipe_3])

    def test_recipe_instance_methods(self):
        self.assertItemsEqual(
            recipe_1.top_five_reviews(),
            [review_1, review_2, review_8, review_3, review_9])
 def test_invite_class_methods(self):
     self.assertItemsEqual(
         Invite._all, [invite_1, invite_2, invite_3, invite_4, invite_5])
     self.assertItemsEqual(
         Invite.all(), [invite_1, invite_2, invite_3, invite_4, invite_5])
 def number_of_invites(self):
     return len([invite for invite in Invite.all() if invite.guest == self])
예제 #11
0
 def setUp(self):
     self.invite = Invite()
     parser = PeopleParser()
     self.people = parser.parse('people.txt')
 def guests(self):
     return [
         invite.guest for invite in Invite.all()
         if invite.dinner_party == self
     ]
예제 #13
0
 def setUp(self):
     self.invite = Invite()
     parser = PeopleParser()
     self.people = parser.parse('people.txt')
예제 #14
0
class TestInvite(unittest.TestCase):
    def setUp(self):
        self.invite = Invite()
        parser = PeopleParser()
        self.people = parser.parse('people.txt')

    def test_absolute_delta_returns_same_delta(self):
        lat1 = 53.3381985
        lat2 = 52.986375

        delta1 = self.invite.get_delta(lat1, lat2)
        delta2 = self.invite.get_delta(lat2, lat1)

        self.assertEqual(delta1, delta2)

    def test_get_central_angle_on_same_point(self):
        someone = self.people[0]
        someone['latitude'] = self.invite.intercom_lat
        someone['longitude'] = self.invite.intercom_lon
        someone['latitude_rad'] = self.invite.intercom_lat_rad
        someone['longitude_rad'] = self.invite.intercom_lon_rad

        central_angle = self.invite.get_central_angle(someone)

        self.assertAlmostEqual(central_angle, 0.00, places=2)

    def test_get_central_angle_on_different_points(self):
        someone = self.people[0]
        central_angle = self.invite.get_central_angle(someone)
        self.assertGreater(central_angle, 0.0)

    def test_get_distance_same_point(self):
        someone = self.people[0]
        someone['latitude'] = self.invite.intercom_lat
        someone['longitude'] = self.invite.intercom_lon
        someone['latitude_rad'] = self.invite.intercom_lat_rad
        someone['longitude_rad'] = self.invite.intercom_lon_rad

        distance = self.invite.get_distance(someone)

        self.assertAlmostEqual(distance, 0.00, places=2)

    def test_get_distance_different_points(self):
        someone = self.people[0]
        distance = self.invite.get_distance(someone)
        self.assertGreater(distance, 0.0)

    def test_filter_cool_people(self):
        cool_people = self.invite.filter_cool_people(self.people, 100)
        for cool_guy in cool_people:
            self.assertLessEqual(cool_guy['distance'], 100)

    def test_sort_people(self):
        people = self.invite.sort_people_by_id(self.people)
        current_id = 0
        for cool_guy in people:
            self.assertGreaterEqual(cool_guy['user_id'], current_id)
            current_id = cool_guy['user_id']

    def test_invite_test_people(self):
        cool_people = self.invite.these_within('people.txt', 100)
        pprint(cool_people)
예제 #15
0
 def invites(self):
     return [invite for invite in Invite.all() if invite.guest == self]
 def invites(self):
     return [
         invite for invite in Invite.all() if invite.dinner_party == self
     ]
from review import Review
from invite import Invite
from dinnerparty import DinnerParty
from recipe import Recipe
from guest import Guest
from course import Course

#Create guests
stacy = Guest('Stacy')
bob = Guest('Bob')

#Create Parties
party1 = DinnerParty('party1')

#Create Invites
invite1 = Invite(party1, stacy)
invite2 = Invite('party2', stacy)
invite3 = Invite('party3', bob)

#Create Recipes
recipe1 = Recipe('Borscht')
recipe2 = Recipe('Burgers')
recipe3 = Recipe('Sushi')
recipe4 = Recipe('Pizza')
recipe5 = Recipe('Oysters')

#Create Reviews
review1 = Review(stacy, recipe1, 5, 'Soup is too cold')
review2 = Review(stacy, recipe2, 4, 'My kids dont respect me')
review3 = Review(bob, recipe3, 3, 'I am happy')
review4 = Review(bob, recipe4, 1, 'YUM')
 def number_of_attendees(self):
     dinner_guest_list = [
         invite for invite in Invite.all()
         if invite.dinner_party == self and invite.accepted == True
     ]
     return len(dinner_guest_list)
예제 #19
0
class TestInvite(unittest.TestCase):
    def setUp(self):
        self.invite = Invite()
        parser = PeopleParser()
        self.people = parser.parse('people.txt')

    def test_absolute_delta_returns_same_delta(self):
        lat1 = 53.3381985
        lat2 = 52.986375

        delta1 = self.invite.get_delta(lat1, lat2)
        delta2 = self.invite.get_delta(lat2, lat1)

        self.assertEqual(delta1, delta2)

    def test_get_central_angle_on_same_point(self):
        someone = self.people[0]
        someone['latitude'] = self.invite.intercom_lat
        someone['longitude'] = self.invite.intercom_lon
        someone['latitude_rad'] = self.invite.intercom_lat_rad
        someone['longitude_rad'] = self.invite.intercom_lon_rad

        central_angle = self.invite.get_central_angle(someone)

        self.assertAlmostEqual(central_angle, 0.00, places=2)

    def test_get_central_angle_on_different_points(self):
        someone = self.people[0]
        central_angle = self.invite.get_central_angle(someone)
        self.assertGreater(central_angle, 0.0)

    def test_get_distance_same_point(self):
        someone = self.people[0]
        someone['latitude'] = self.invite.intercom_lat
        someone['longitude'] = self.invite.intercom_lon
        someone['latitude_rad'] = self.invite.intercom_lat_rad
        someone['longitude_rad'] = self.invite.intercom_lon_rad

        distance = self.invite.get_distance(someone)

        self.assertAlmostEqual(distance, 0.00, places=2)

    def test_get_distance_different_points(self):
        someone = self.people[0]
        distance = self.invite.get_distance(someone)
        self.assertGreater(distance, 0.0)

    def test_filter_cool_people(self):
        cool_people = self.invite.filter_cool_people(self.people, 100)
        for cool_guy in cool_people:
            self.assertLessEqual(cool_guy['distance'], 100)

    def test_sort_people(self):
        people = self.invite.sort_people_by_id(self.people)
        current_id = 0
        for cool_guy in people:
            self.assertGreaterEqual(cool_guy['user_id'], current_id)
            current_id = cool_guy['user_id']

    def test_invite_test_people(self):
        cool_people = self.invite.these_within('people.txt', 100)
        pprint(cool_people)