Пример #1
0
    def test_get_persons_born_between(self):
        database = Database(':memory:')
        session = database.get_session()

        dob_1 = DayOfBirth(date=datetime(year=1963, month=7, day=15))
        dob_2 = DayOfBirth(date=datetime(year=1975, month=1, day=3))
        dob_3 = DayOfBirth(date=datetime(year=2020, month=3, day=20))

        person_1 = Person(email='to early')
        person_1.day_of_birth = [dob_1]
        person_2 = Person(email='should be returned')
        person_2.day_of_birth = [dob_2]
        person_3 = Person(email='to late')
        person_3.day_of_birth = [dob_3]

        min_date = datetime(year=1970, month=1, day=1)
        max_date = datetime(year=1999, month=12, day=30)

        session.add_all([person_1, person_2, person_3])
        session.commit()

        data_fetcher = DataFetcher(database)

        values, columns = data_fetcher.get_persons_born_between(
            min_date=min_date, max_date=max_date)

        assert len(values) == 1
        assert values[0][0].email == 'should be returned'
    def test_load_person_data_add_tables(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)

        assert len(session.query(Location).all()) == 1
        assert len(session.query(TimeZone).all()) == 1
        assert len(session.query(Coordinates).all()) == 1
        assert len(session.query(Street).all()) == 1
    def test_load_person_data_set_id_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)
        result = session.query(ID).first()
        expected = self.data['id']

        assert result.name == expected['name']
        assert result.value == expected['value']
    def test_load_person_data_set_registered_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)
        result = session.query(Registered).first()
        expected = self.data['registered']

        assert result.date == datetime.datetime(year=2016, month=8, day=11, hour=6, minute=51, second=52,
                                                microsecond=86000)
        assert result.age == expected['age']
    def test_load_person_data_set_name_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)
        result = session.query(Name).first()
        expected = self.data['name']

        assert result.title == expected['title']
        assert result.first == expected['first']
        assert result.last == expected['last']
    def test_load_person_data_set_day_of_birth_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)
        result = session.query(DayOfBirth).first()
        expected = self.data['dob']

        assert result.date == datetime.datetime(year=1966, month=6, day=26, hour=11, minute=50, second=25,
                                                microsecond=558000)
        assert result.age == expected['age']
    def test_load_person_data_set_person_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)
        result = session.query(Person).first()

        assert result.gender == self.data['gender']
        assert result.email == self.data['email']
        assert result.phone == "0262351898"
        assert result.cell == self.data['cell']
        assert result.nat == self.data['nat']
    def test_load_person_data_set_coordinates_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()

        expected = self.data['location']['coordinates']

        database_loader.load_person_data(person)
        result = session.query(Coordinates).first()

        assert result.latitude == expected['latitude']
        assert result.longitude == expected['longitude']
    def test_load_person_data_set_timezone_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()

        expected = self.data['location']['timezone']

        database_loader.load_person_data(person)
        result = session.query(TimeZone).first()

        assert result.offset == expected['offset']
        assert result.description == expected['description']
Пример #10
0
    def test_load_person_data_add_all_tables(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)

        assert len(session.query(Location).all()) == 1
        assert len(session.query(Name).all()) == 1
        assert len(session.query(Login).all()) == 1
        assert len(session.query(DayOfBirth).all()) == 1
        assert len(session.query(Registered).all()) == 1
        assert len(session.query(ID).all()) == 1
        assert len(session.query(Person).all()) == 1
Пример #11
0
    def test_get_gender_percentage_female(self):
        database = Database(':memory:')
        session = database.get_session()

        person_1 = Person(gender='female')
        person_2 = Person(gender='female')
        person_3 = Person(gender='female')
        session.bulk_save_objects([person_1, person_2, person_3])
        session.commit()

        data_fetcher = DataFetcher(database)

        values, columns = data_fetcher.get_gender_percentage()
        expected = [('female', 100)]

        assert set(values) == set(expected)
Пример #12
0
    def test_load_person_data_set_location_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()

        expected = self.data['location']

        database_loader.load_person_data(person)
        result = session.query(Location).first()

        assert result.city == expected['city']
        assert result.state == expected['state']
        assert result.country == expected['country']
        assert result.postcode == expected['postcode']
Пример #13
0
    def test_get_strongest_password(self, passwords, expected):
        database = Database(':memory:')
        session = database.get_session()

        logins = []
        for password in passwords:
            logins.append(Login(password=password))

        session.add_all(logins)
        session.commit()

        data_fetcher = DataFetcher(database)

        values, columns = data_fetcher.get_strongest_password()

        assert set(values) == set([(expected, )])
Пример #14
0
    def test_load_person_data_set_login_table_row(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        person = self.get_person_data()
        database_loader.load_person_data(person)
        result = session.query(Login).first()
        expected = self.data['login']

        assert result.uuid == expected['uuid']
        assert result.username == expected['username']
        assert result.password == expected['password']
        assert result.salt == expected['salt']
        assert result.md5 == expected['md5']
        assert result.sha1 == expected['sha1']
        assert result.sha256 == expected['sha256']
Пример #15
0
    def test_get_most_popular_passwords_fetch_one(self):
        database = Database(':memory:')
        session = database.get_session()

        logins = []
        logins.append(Login(password='******'))
        logins.append(Login(password='******'))
        logins.append(Login(password='******'))

        session.add_all(logins)
        session.commit()

        data_fetcher = DataFetcher(database)

        values, columns = data_fetcher.get_most_popular_passwords(1)
        expected = [('tricky', 2)]

        assert set(values) == set(expected)
Пример #16
0
    def test_get_most_popular_cities_fetch_many_city_when_there_is_one(self):
        database = Database(':memory:')
        session = database.get_session()

        locations = []
        locations.append(Location(city='Sejny'))
        locations.append(Location(city='Sejny'))
        locations.append(Location(city='Sejny'))

        session.add_all(locations)
        session.commit()

        data_fetcher = DataFetcher(database)

        values, columns = data_fetcher.get_most_popular_cities(4)
        expected = [('Sejny', 3)]

        assert set(values) == set(expected)
Пример #17
0
    def test_load_many_persons_data(self):
        database = Database(':memory:')
        session = database.get_session()
        database_loader = DatabaseLoader(database)

        persons = [self.get_person_data(), self.get_person_data()]
        database_loader.load_many_persons_data(persons)

        session.query()

        assert len(session.query(Location).all()) == 2
        assert len(session.query(Name).all()) == 2
        assert len(session.query(Login).all()) == 2
        assert len(session.query(DayOfBirth).all()) == 2
        assert len(session.query(Registered).all()) == 2
        assert len(session.query(ID).all()) == 2
        assert len(session.query(Person).all()) == 2
        assert len(session.query(TimeZone).all()) == 2
        assert len(session.query(Coordinates).all()) == 2
        assert len(session.query(Street).all()) == 2
Пример #18
0
    def test_get_average_age_botch(self, gender, expected):
        database = Database(':memory:')
        session = database.get_session()

        person_1 = Person(gender='female')
        dbo_1 = DayOfBirth(age=10)
        person_1.day_of_birth = [dbo_1]
        person_2 = Person(gender='male')
        dbo_2 = DayOfBirth(age=20)
        person_2.day_of_birth = [dbo_2]
        person_3 = Person(gender='male')
        dbo_3 = DayOfBirth(age=39)
        person_3.day_of_birth = [dbo_3]

        session.add_all([person_1, person_2, person_3])
        session.commit()

        data_fetcher = DataFetcher(database)

        values, columns = data_fetcher.get_average_age(gender)

        assert set(values) == set(expected)