コード例 #1
0
 def setUp(self):
     self.__activity_1 = Activity(1, [1, 2, 3], [1, "January", 2017],
                                  [0, 0], "Default")
     self.__activity_2 = Activity(1, [4, 5, 6], [1, "January", 2017],
                                  [0, 1], "Description")
     self.__activity_3 = Activity(2, [9, 10], [3, "January", 2017], [0, 20],
                                  "Default")
     self.__dta = Dta([1, "January", 2017], self.__activity_1)
コード例 #2
0
 def setUp(self):
     self.__person_1 = Person(1, "Name", 1234, "Address")
     self.__person_2 = Person(2, "Name", 5678, "Address2")
     self.__activity_1 = Activity(1, [7, 8], [1, "January", 2017], [0, 10],
                                  "Default Description")
     self.__activity_2 = Activity(2, [9, 10], [1, "January", 2017], [0, 10],
                                  "Default")
     self.__activity_3 = Activity(3, [9, 10], [1, "January", 2017], [0, 0],
                                  "Default")
     self.__repo = Repository()
コード例 #3
0
 def test_comp(self):
     activity_1 = Activity(1, [7, 8], [3, "January", 2017], [0, 10],
                           "Default Description")
     activity_2 = Activity(2, [9, 10], [1, "January", 2017], [0, 0],
                           "Default")
     activity_3 = Activity(2, [9, 10], [1, "January", 2017], [0, 20],
                           "Default")
     self.assertTrue(self.__activity.comp(activity_1))
     self.assertTrue(self.__activity.comp(activity_2))
     self.assertFalse(self.__activity.comp(activity_3))
コード例 #4
0
 def __generate_activity(self, i):
     activity_id = i
     contacts = self.__generate_contact_list()
     date = self.__generate_date(self.__repo.get_all())
     time = self.__generate_time(self.__repo.get_all())
     desc = self.__generate_description()
     return Activity(activity_id, contacts, date, time, desc)
コード例 #5
0
 def __ui_remove_activity(self):
     """
     Removes an activity based on it's Id
     :return:
     """
     activity_id = int(input("Insert the Id of the element: "))
     self.__activity_service.remove(
         Activity(activity_id, [1], [1, "january", 0], [0, 0], "Default"))
コード例 #6
0
 def test_update(self):
     self.__repo.add(self.__activity_1)
     with self.assertRaises(RepositoryException):
         self.__repo.update(self.__activity_3)
     self.__repo.add(self.__activity_3)
     with self.assertRaises(RepositoryException):
         self.__repo.update(
             Activity(1, [9, 10], [1, "January", 2017], [0, 0], "Default"))
     self.__repo.update(self.__activity_1)
コード例 #7
0
 def test_update(self):
     self.__activity.update(
         Activity(1, [4, 5, 6], [2, "January", 2017], [0, 1],
                  "Description"))
     self.assertEqual(self.__activity.get_id(), 1)
     self.assertEqual(self.__activity.get_date(), [2, "January", 2017])
     self.assertEqual(self.__activity.get_persons(), [4, 5, 6])
     self.assertEqual(self.__activity.get_time(), [0, 1])
     self.assertEqual(self.__activity.get_description(), "Description")
コード例 #8
0
 def __input_activity():
     """
     Reads the details of an activity
     :return: returns a list containing the details of the activity
     """
     activity = [
         int(input("Activity Id: ")),
         list(map(int,
                  input("Participant's Id's: ").split()))
     ]
     date = input("Date: ").split()
     date[0] = int(date[0])
     date[1] = int(date[2])
     activity.append(date)
     activity.append(list(map(int, input("Time: ").split())))
     activity.append(input("Description: "))
     return Activity(*activity)
コード例 #9
0
 def __read_file(self):
     file = open(self.__file_name, "r")
     line = file.readline()
     while line:
         line = line.strip('\n').split(";")
         if self.__tip == Person:
             super().add(
                 Person(int(line[0]), line[1], int(line[2]), line[3]))
         elif self.__tip == Activity:
             date = line[2].split()
             date[0] = int(date[0])
             date[2] = int(date[2])
             time = line[3].split()
             super().add(
                 Activity(int(line[0]), list(map(int, line[1].split())),
                          date, list(map(int, time)), line[4]))
         line = file.readline()
     file.close()
コード例 #10
0
 def test_validate_activity(self):
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(-1, [1, 2, 3], [1, "january", 2017], [0, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [1, "default", 2017], [0, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [34, "january", 2017], [0, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [0, "january", 2017], [0, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [31, "february", 2017], [0, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [1, "january", 2016], [0, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [1, "january", 2017], [0, 0], "123"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [0, "january", 2017], [-1, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [0, "january", 2017], [25, 0], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [0, "january", 2017], [0, -1], "Default"))
     with self.assertRaises(ValidatorException):
         self.__validator.validate_activity(Activity(1, [1, 2, 3], [0, "january", 2017], [0, 60], "Default"))
コード例 #11
0
 def test_len(self):
     activity = Activity(1, [1], [3, "January", 2017], [0, 10], "Default")
     self.assertEqual(len(activity), 5)
コード例 #12
0
 def setUp(self):
     self.__activity = Activity(1, [1, 2, 3], [1, "January", 2017], [0, 0],
                                "Default")
コード例 #13
0
 def test_str(self):
     activity = Activity(1, [1], [3, "January", 2017], [0, 10], "Default")
     self.assertEqual(
         str(activity),
         "Activity Id: 1\nPersons Id's: 1 \nDate: 3 January 2017\nTime: 0:10\nDescription: Default\n"
     )
コード例 #14
0
class TestActivity(TestCase):
    def setUp(self):
        self.__activity = Activity(1, [1, 2, 3], [1, "January", 2017], [0, 0],
                                   "Default")

    def test_get_id(self):
        self.assertEqual(self.__activity.get_id(), 1)

    def test_get_date(self):
        self.assertEqual(self.__activity.get_date(), [1, "January", 2017])

    def test_get_persons(self):
        self.assertEqual(self.__activity.get_persons(), [1, 2, 3])

    def test_get_time(self):
        self.assertEqual(self.__activity.get_time(), [0, 0])

    def test_get_description(self):
        self.assertEqual(self.__activity.get_description(), "Default")

    def test_update(self):
        self.__activity.update(
            Activity(1, [4, 5, 6], [2, "January", 2017], [0, 1],
                     "Description"))
        self.assertEqual(self.__activity.get_id(), 1)
        self.assertEqual(self.__activity.get_date(), [2, "January", 2017])
        self.assertEqual(self.__activity.get_persons(), [4, 5, 6])
        self.assertEqual(self.__activity.get_time(), [0, 1])
        self.assertEqual(self.__activity.get_description(), "Description")

    def test_comp(self):
        activity_1 = Activity(1, [7, 8], [3, "January", 2017], [0, 10],
                              "Default Description")
        activity_2 = Activity(2, [9, 10], [1, "January", 2017], [0, 0],
                              "Default")
        activity_3 = Activity(2, [9, 10], [1, "January", 2017], [0, 20],
                              "Default")
        self.assertTrue(self.__activity.comp(activity_1))
        self.assertTrue(self.__activity.comp(activity_2))
        self.assertFalse(self.__activity.comp(activity_3))

    def test_equal(self):
        activity_1 = Activity(1, [7, 8], [3, "January", 2017], [0, 10],
                              "Default Description")
        activity_2 = Activity(2, [9, 10], [1, "January", 2017], [0, 0],
                              "Default")
        self.assertFalse(activity_1 == activity_2)

    def test_str(self):
        activity = Activity(1, [1], [3, "January", 2017], [0, 10], "Default")
        self.assertEqual(
            str(activity),
            "Activity Id: 1\nPersons Id's: 1 \nDate: 3 January 2017\nTime: 0:10\nDescription: Default\n"
        )

    def test_len(self):
        activity = Activity(1, [1], [3, "January", 2017], [0, 10], "Default")
        self.assertEqual(len(activity), 5)
コード例 #15
0
 def test_equal(self):
     activity_1 = Activity(1, [7, 8], [3, "January", 2017], [0, 10],
                           "Default Description")
     activity_2 = Activity(2, [9, 10], [1, "January", 2017], [0, 0],
                           "Default")
     self.assertFalse(activity_1 == activity_2)