Esempio n. 1
0
 def test_delete_join_3(self) -> None:
     """
     test delete_join: user doesn’t exist, event exists
     """
     Join.create_join(Join(self.user, self.event))
     self.assertTrue(Join.user_is_attend(self.user, self.event))
     Join.delete_join(Join('1', self.event))
     self.assertTrue(Join.user_is_attend(self.user, self.event))
Esempio n. 2
0
 def test_delete_join_4(self) -> None:
     """
     test delete_join: user and event don’t exist
     """
     Join.create_join(Join(self.user, self.event))
     self.assertTrue(Join.user_is_attend(self.user, self.event))
     Join.delete_join(Join('1', '1'))
     self.assertTrue(Join.user_is_attend(self.user, self.event))
Esempio n. 3
0
 def get_all_ongoing_events(user: str):
     """
    :return: An ongoing event list
    """
     cnx = db_connector.get_connection()
     cursor = cnx.cursor()
     query = ("SELECT * FROM event " "where `time` >= now()")
     cursor.execute(query)
     events = []
     for (eid, name, host, address, longi, lati, zipcode, event_time,
          description, image, num_likes, category) in cursor:
         new_event = Event(user=host,
                           name=name,
                           address=address,
                           longitude=longi,
                           latitude=lati,
                           zipcode=zipcode,
                           event_time=datetime.datetime.strptime(
                               str(event_time), "%Y-%m-%d %H:%M:%S"))
         new_event.event_id = eid
         new_event.description = description
         new_event.image = image
         new_event.num_likes = num_likes
         new_event.category = category
         if user:
             new_event.liked = Like.exist(user, eid)
             new_event.attended = Join.user_is_attend(user=user, event=eid)
         else:
             new_event.liked = False
             new_event.attended = False
         new_event.comments = Comment.get_comment_by_event(eid)
         events.append(new_event)
     cursor.close()
     cnx.close()
     return events
Esempio n. 4
0
    def get_event_by_id(event_id: str, user=None):
        """

        :param event_id: Id of the event
        :param user: user email
        :return: An event object whose id is the given event_id,
        and also indicates whether the user is attending the event
        """
        cnx = db_connector.get_connection()
        cursor = cnx.cursor()
        query = ("SELECT * FROM `event` WHERE id='" + event_id + "'")
        cursor.execute(query)
        new_event = None
        for (eid, name, host, address, longitude, latitude, zipcode,
             event_time, description, image, num_likes, category) in cursor:
            new_event = Event(user=host,
                              name=name,
                              address=address,
                              longitude=longitude,
                              latitude=latitude,
                              zipcode=zipcode,
                              event_time=datetime.datetime.strptime(
                                  str(event_time), "%Y-%m-%d %H:%M:%S"))
            new_event.event_id = eid
            new_event.description = description
            new_event.image = image
            new_event.num_likes = num_likes
            new_event.category = category
            if user:
                new_event.liked = Like.exist(user, event_id)
                new_event.attended = Join.user_is_attend(user=user,
                                                         event=event_id)
            else:
                new_event.liked = False
                new_event.attended = False
            new_event.comments = Comment.get_comment_by_event(event_id)
        cursor.close()
        cnx.close()
        return new_event
Esempio n. 5
0
 def test_user_is_attend_1(self) -> None:
     """
     test user_is_attend: user and event exist
     """
     Join.create_join(Join(self.user, self.event))
     self.assertTrue(Join.user_is_attend(self.user, self.event))
Esempio n. 6
0
 def test_user_is_attend_4(self) -> None:
     """
     test user_is_attend: user and event don’t exist
     """
     Join.create_join(Join(self.user, self.event))
     self.assertFalse(Join.user_is_attend('1', '1'))
Esempio n. 7
0
 def test_user_is_attend_3(self) -> None:
     """
     test user_is_attend: user doesn’t exist, event exists
     """
     Join.create_join(Join(self.user, self.event))
     self.assertFalse(Join.user_is_attend('1', self.event))
Esempio n. 8
0
 def test_user_is_attend_2(self) -> None:
     """
     test user_is_attend: user exists, event doesn’t exist
     """
     Join.create_join(Join(self.user, self.event))
     self.assertFalse(Join.user_is_attend(self.user, '1'))