示例#1
0
class TestWorker(TestCase):
    def setUp(self):
        print('setUp')
        self.moshe = Worker('Moshe', 'Cohen', 2000, 2, 17,
                            '1 Yigal Alon, Tel Aviv', 'il')

    def tearDown(self):
        print('tearDown')

    def test_full_name(self):
        res = self.moshe.full_name()
        self.assertTrue(res == 'Moshe Cohen')

    def test_age(self):
        pass

    def test_days_to_birthday(self):
        pass

    def test_greet(self):
        pass

    def test_location(self):
        with patch('Worker.requests.get') as mocked_get:
            mocked_get.return_value.ok = True
            mocked_get.return_value.text = 'Success'

            res = self.moshe.location()
            self.assertEqual(res, 'Success')
示例#2
0
 def test_age(self):
     #datetime = Mock()
     #with mock.patch('datetime.datetime.now().year',return_value = 2019)
     bob = Worker('Bob', 'Marshall', 1970, 7, 5)
     print(bob.age())
     print(datetime.datetime.now().year())
     self.assertTrue(bob.age() == 49)
示例#3
0
class TestWorker(TestCase):
    def setUp(self):
        print('setup')
        self.bob = Worker('Bob', 'Marshall', 1970, 7, 30,
                          '2 Dizengof, Tel Aviv', 'il')
        self.alice = Worker('Alice', 'Smith', 1995, 12, 1,
                            '90 Yigal Alon, Tel Aviv', 'il')

    def tearDown(self):
        print('TearDown')

# Tests:

    def test_full_name1(self):
        #bob = Worker('Bob', 'Marshall', 1970, 7, 5)
        #alice = Worker('Alice', 'Smith', 1995, 12, 1, '90 Yigal Alon, Tel Aviv', 'il')
        # print(self.bob.full_name())
        self.assertTrue(self.bob.full_name() == 'Bob Marshall')
        self.assertTrue(self.alice.full_name() == 'Alice Smith')

    def test_age(self):
        # bob = Worker('Bob', 'Marshall', 1970, 7, 5)
        # print(self.bob.age())
        # print(datetime.datetime.now().year())
        michal = Worker('Michal', 'Tal', 1994, 4, 28,
                        '90 Yigal Alon, Tel Aviv', 'il')
        ruth = Worker('Ruth', 'Tal', 2025, 4, 28, '90 Yigal Alon, Tel Aviv',
                      'il')
        self.assertIn("Error", ruth.age())

        self.assertTrue(self.bob.age() == "Bob is 51 years old")
        self.assertIn("51", self.bob.age())
        self.assertTrue(self.alice.age() == "Alice is 26 years old")

    def test_days_to_birthday(self):
        # bob = Worker('Bob', 'Marshall', 1970, 7, 30)
        # print(self.bob.days_to_birthday())
        # print(self.alice.days_to_birthday())
        self.assertIn("92", self.bob.days_to_birthday())
        self.assertIn("216", self.alice.days_to_birthday())

    def test_location(self):
        # bob = Worker('Bob', 'Marshall', 1970, 7, 30, '2 Dizengof, Tel Aviv', 'il')
        # print(bob.location())
        with patch('Package1.Worker.requests.get') as mocked_get:
            mocked_get.return_value.ok = True
            mocked_get.return_value.text = 'Success'

            res = self.bob.location()
            # mocked_get.assert_called_with('https://geocode.xyz/?locate=2 Dizengof, Tel Aviv,il &json=1')
            self.assertEqual(res, 'Success')
            # self.assertEqual(self.bob.location(), 'Success')

            mocked_get.return_value.ok = False

            res = self.bob.location()
            # mocked_get.assert_called_with('https://geocode.xyz/?locate=2 Dizengof, Tel Aviv,il &json=1')
            self.assertEqual(res, 'Bad response!')
示例#4
0
    def test_age(self):
        # bob = Worker('Bob', 'Marshall', 1970, 7, 5)
        # print(self.bob.age())
        # print(datetime.datetime.now().year())
        michal = Worker('Michal', 'Tal', 1994, 4, 28,
                        '90 Yigal Alon, Tel Aviv', 'il')
        ruth = Worker('Ruth', 'Tal', 2025, 4, 28, '90 Yigal Alon, Tel Aviv',
                      'il')
        self.assertIn("Error", ruth.age())

        self.assertTrue(self.bob.age() == "Bob is 51 years old")
        self.assertIn("51", self.bob.age())
        self.assertTrue(self.alice.age() == "Alice is 26 years old")
示例#5
0
class TestWorker(TestCase):
    def setUp(self):
        self.bob = Worker('Bob', 'Marshall', 1970, 7, 5, "ha rav, kook 29",
                          "Il")
        self.sagi = Worker('sagi', 'bondarenko', 1999, 11, 29,
                           "ha rav, kook 29", "Il")
        print('setUP')

    def tearDown(self):
        print('tearDown')

    def test_full_name(self):
        self.assertEqual(self.bob.full_name(), "Bob Marshall")

    def test_age(self):
        age = 2020 - self.bob.birth_year
        self.assertEqual(50, age)
        if age < 0:
            self.fail()

    def test_age_past(self):  #valid, normal age
        res = self.sagi.age()
        print(self.sagi.age())
        self.assertTrue(res == "sagi is 21 years old")

    def test_age_future(self):  #not valid, negative age
        self.bob1 = Worker("bob", "mar", 2030, 11, 28, "afula", "israel")
        res = self.bob1.age()
        print(self.bob1.age())
        self.assertTrue(res == "error")

    def test_age_now(self):  #valid, infant age
        self.bob1 = Worker("bob", "mar", 2020, 11, 28, "afula", "israel")
        res = self.bob1.age()
        print(self.bob1.age())
        self.assertTrue(res == "bob is 0 years old")

    def test_days_to_birthday(self):
        self.assertIn("6", self.sagi.days_to_birthday())
        pass

    def test_greet(self):
        self.assertEqual(self.bob.greet(self.sagi), 'Bob says hello to sagi')
        print(self.bob.greet(self.sagi))

    def test_location(self):
        """bob = Worker('Bob', 'Marshall', 1999, 11, 29, "23 Ha-Rav Kook St, Hadera", "Israel")
        self.assertTrue("23 Ha-Rav Kook St, HaderaA", bob.location())"""
        pass
示例#6
0
class TestWorker(TestCase):
    def setUp(self):
        print("setup:")
        self.gilad = Worker("Gilad", "Levy", 1999, 8, 12, "135, rothschild, tel-aviv", "IL")
        self.roy = Worker("Roy", "Segal", 1998, 7, 26, "1, dvoranit, ness-ziona", "IL")

    def tearDown(self):
        print("teardown^")

    def test_full_name(self):
        self.assertTrue(self.gilad.full_name() == "Gilad Levy")

    def test_age(self):
        # self.assertEqual(self.gilad.birth_year, datetime.datetime.now().year)
        # self.assertGreater(self.gilad.birth_year, datetime.datetime.now().year)
        # self.assertLess(self.gilad.birth_year, datetime.datetime.now().year)

    def test_days_to_birthday(self):

            self.assertGreater(self.gilad.birth_month, datetime.datetime.now().month)
        # if self.assertEqual(self.gilad.birth_month, datetime.datetime.now().month):
        #     self.assertGreater(self.gilad.birth_day, datetime.datetime.now().day)




        # if self.assertEqual(self.gilad.birth_month, datetime.datetime.now().month):
        #     self.assertGreater(self.gilad.birth_day, datetime.datetime.now().day)

        # self.assertLessEqual(self.gilad.birth_month, datetime.datetime.now().month)
        # self.assertLess(self.gilad.birth_day, datetime.datetime.now().day)
        #
        # self.assertEqual(self.gilad.birth_month, datetime.datetime.now().month)
        # self.assertEqual(self.gilad.birth_day, datetime.datetime.now().day)



    def test_greet(self):
        pass

    def test_location(self):
        pass
 def test_full_name(self):
     bob = Worker('bob', 'Cohen', 1980, 1, 1, '1 Yigal Alon, Tel Aviv',
                  'il')
     self.assertTrue(bob.full_name() == 'bob Cohen')
     self.assertIn('bob', bob.full_name())
示例#8
0
 def setUp(self):
     print('setUp')
     self.moshe = Worker('Moshe', 'Cohen', 2000, 2, 17,
                         '1 Yigal Alon, Tel Aviv', 'il')
 def test_days_to_birthday_past(self):
     mati = Worker('Mati', 'Levi', 1980, 1, 1, '1 Yigal Alon, Tel Aviv',
                   'il')
     print(mati.days_to_birthday())
     self.assertIn('248 days', mati.days_to_birthday())
 def test_days_to_birthday_today(self):
     mati = Worker('Mati', 'Levi', 1980, 4, 28, '1 Yigal Alon, Tel Aviv',
                   'il')
     print(mati.days_to_birthday())
     self.assertIn('0', mati.days_to_birthday())
 def test_age_current_year(self):
     mati = Worker('Mati', 'Levi', 2021, 1, 1, '1 Yigal Alon, Tel Aviv',
                   'il')
     self.assertIn('0', mati.age())
 def test_days_to_birthday_future(self):
     mati = Worker('Mati', 'Levi', 1980, 7, 30, '1 Yigal Alon, Tel Aviv',
                   'il')
     print(mati.days_to_birthday())
     self.assertIn('93 days', mati.days_to_birthday())
示例#13
0
 def test_days_to_birthday(self):
     bob = Worker('Bob', 'Marshall', 1970, 7, 5)
     self.assertTrue(bob.days_to_birthday() == 4)
示例#14
0
 def test_age_future(self):  #not valid, negative age
     self.bob1 = Worker("bob", "mar", 2030, 11, 28, "afula", "israel")
     res = self.bob1.age()
     print(self.bob1.age())
     self.assertTrue(res == "error")
示例#15
0
 def setUp(self):
     print("setup:")
     self.gilad = Worker("Gilad", "Levy", 1999, 8, 12, "135, rothschild, tel-aviv", "IL")
     self.roy = Worker("Roy", "Segal", 1998, 7, 26, "1, dvoranit, ness-ziona", "IL")
示例#16
0
 def test_age_now(self):  #valid, infant age
     self.bob1 = Worker("bob", "mar", 2020, 11, 28, "afula", "israel")
     res = self.bob1.age()
     print(self.bob1.age())
     self.assertTrue(res == "bob is 0 years old")
示例#17
0
 def setUp(self):
     self.bob = Worker('Bob', 'Marshall', 1970, 7, 5, "ha rav, kook 29",
                       "Il")
     self.sagi = Worker('sagi', 'bondarenko', 1999, 11, 29,
                        "ha rav, kook 29", "Il")
     print('setUP')
 def test_age_past(self):
     bob = Worker('bob', 'Cohen', 1980, 1, 1, '1 Yigal Alon, Tel Aviv',
                  'il')
     print(bob.age())
     self.assertIn('41', bob.age())
 def test_age_future(self):
     mati = Worker('Mati', 'Levi', 2022, 1, 1, '1 Yigal Alon, Tel Aviv',
                   'il')
     self.assertIn('Error', mati.age())
示例#20
0
 def setUp(self):
     print('setup')
     self.bob = Worker('Bob', 'Marshall', 1970, 7, 30,
                       '2 Dizengof, Tel Aviv', 'il')
     self.alice = Worker('Alice', 'Smith', 1995, 12, 1,
                         '90 Yigal Alon, Tel Aviv', 'il')
示例#21
0
 def test_full_name(self):
     bob = Worker('Bob', 'Marshall', 1970, 7, 5)
     self.assertTrue(bob.full_name() == 'Bob Marshall')