Пример #1
0
 def setUp(self):
     database.create_tables([Stranger, Talk])
     self.stranger_0 = Stranger.create(
         invitation='foo',
         telegram_id=31416,
         )
     self.stranger_1 = Stranger.create(
         invitation='bar',
         telegram_id=27183,
         )
     self.stranger_2 = Stranger.create(
         invitation='baz',
         telegram_id=23571,
         )
     self.stranger_3 = Stranger.create(
         invitation='zig',
         telegram_id=11317,
         )
     self.stranger_4 = Stranger.create(
         invitation='zap',
         telegram_id=19232,
         )
     self.talk_0 = Talk.create(
         partner1=self.stranger_0,
         partner1_sent=1000,
         partner2=self.stranger_1,
         partner2_sent=2000,
         searched_since=datetime.datetime(1980, 1, 1),
         begin=datetime.datetime(2000, 1, 1),
         )
     self.talk_1 = Talk.create(
         partner1=self.stranger_2,
         partner2=self.stranger_3,
         searched_since=datetime.datetime(1990, 1, 1),
         begin=datetime.datetime(2000, 1, 2)
         )
     self.talk_2 = Talk.create(
         partner1=self.stranger_2,
         partner2=self.stranger_4,
         searched_since=datetime.datetime(2000, 1, 1),
         begin=datetime.datetime(2000, 1, 3),
         end=datetime.datetime(2010, 1, 1),
         )
     self.talk_3 = Talk.create(
         partner1=self.stranger_0,
         partner2=self.stranger_2,
         searched_since=datetime.datetime(2000, 1, 1),
         begin=datetime.datetime(2000, 1, 4),
         end=datetime.datetime(2010, 1, 2),
         )
     self.talk_4 = Talk.create(
         partner1=self.stranger_0,
         partner2=self.stranger_3,
         searched_since=datetime.datetime(2000, 1, 1),
         begin=datetime.datetime(2000, 1, 5),
         end=datetime.datetime(2010, 1, 3),
         )
Пример #2
0
def setup_db(db_dict):
    for model_name, model_dicts in db_dict.items():
        if model_name == 'strangers':
            for stranger_dict in model_dicts:
                Stranger.create(**stranger_dict)
        elif model_name == 'talks':
            for talk_dict in model_dicts:
                Talk.create(**talk_dict)
        else:
            raise AssertionError(f'Unknown model name: `{model_name}`')
Пример #3
0
 def setUp(self):
     DATABASE.create_tables([Stranger, Talk])
     self.stranger_0 = Stranger.create(
         invitation='foo',
         telegram_id=31416,
     )
     self.stranger_1 = Stranger.create(
         invitation='bar',
         telegram_id=27183,
     )
     self.stranger_2 = Stranger.create(
         invitation='baz',
         telegram_id=23571,
     )
     self.stranger_3 = Stranger.create(
         invitation='zig',
         telegram_id=11317,
     )
     self.stranger_4 = Stranger.create(
         invitation='zap',
         telegram_id=19232,
     )
     self.talk_0 = Talk.create(
         partner1=self.stranger_0,
         partner1_sent=1000,
         partner2=self.stranger_1,
         partner2_sent=2000,
         searched_since=datetime.datetime(1980, 1, 1),
         begin=datetime.datetime(2000, 1, 1),
     )
     self.talk_1 = Talk.create(partner1=self.stranger_2,
                               partner2=self.stranger_3,
                               searched_since=datetime.datetime(1990, 1, 1),
                               begin=datetime.datetime(2000, 1, 2))
     self.talk_2 = Talk.create(
         partner1=self.stranger_2,
         partner2=self.stranger_4,
         searched_since=datetime.datetime(2000, 1, 1),
         begin=datetime.datetime(2000, 1, 3),
         end=datetime.datetime(2010, 1, 1),
     )
     self.talk_3 = Talk.create(
         partner1=self.stranger_0,
         partner2=self.stranger_2,
         searched_since=datetime.datetime(2000, 1, 1),
         begin=datetime.datetime(2000, 1, 4),
         end=datetime.datetime(2010, 1, 2),
     )
     self.talk_4 = Talk.create(
         partner1=self.stranger_0,
         partner2=self.stranger_3,
         searched_since=datetime.datetime(2000, 1, 1),
         begin=datetime.datetime(2000, 1, 5),
         end=datetime.datetime(2010, 1, 3),
     )
Пример #4
0
def assert_db(db_dict):
    def assert_model(model, model_dict):
        def raise_assertion_error(key, actual_value, expected_value):
            raise AssertionError(
                f'Value of `{key}` is `{actual_value}` but should be `{expected_value}`',
            )

        for key, expected_value in model_dict.items():
            actual_value = getattr(model, key)

            if isinstance(expected_value, datetime.datetime):
                if abs(actual_value - expected_value) > TIME_TOLERANCE:
                    raise_assertion_error(key, actual_value, expected_value)
            elif hasattr(expected_value,
                         'match'):  # Regular expression pattern.
                if expected_value.match(actual_value) is None:
                    raise AssertionError(
                        f'Value of `{key}` is `{actual_value}` and doesn\'t match'
                        f' `{expected_value}`', )
            elif actual_value != expected_value:
                raise_assertion_error(key, actual_value, expected_value)

    for model_name, models_dicts in db_dict.items():
        if model_name == 'strangers':
            for stranger_dict in models_dicts:
                stranger_instance = Stranger.get(id=stranger_dict['id'])
                assert_model(stranger_instance, stranger_dict)
        elif model_name == 'talks':
            for talk_dict, talk_instance in zip(models_dicts, Talk.select()):
                assert_model(talk_instance, talk_dict)
        else:
            raise AssertionError(f'Unknown model name: `{model_name}`')
 def setUp(self):
     self.stranger_service = StrangerService()
     stranger.database_proxy.initialize(self.database)
     self.database.create_tables([Stranger])
     self.stranger_0 = Stranger.create(
         invitation='foo',
         languages='["foo"]',
         telegram_id=27183,
         sex='female',
         partner_sex='male',
         )
     self.stranger_1 = Stranger.create(
         invitation='bar',
         languages='["foo"]',
         telegram_id=31416,
         sex='male',
         partner_sex='female',
         )
     self.stranger_2 = Stranger.create(
         invitation='baz',
         languages='["foo"]',
         telegram_id=23571,
         sex='male',
         partner_sex='female',
         )
     self.stranger_3 = Stranger.create(
         invitation='zen',
         languages='["foo"]',
         telegram_id=11317,
         sex='male',
         partner_sex='female',
         )
     self.stranger_4 = Stranger.create(
         invitation='zig',
         languages='["foo"]',
         telegram_id=19232,
         sex='male',
         partner_sex='female',
         )
     self.stranger_5 = Stranger.create(
         invitation='zam',
         languages='["foo"]',
         telegram_id=93137,
         sex='male',
         partner_sex='female',
         )
     self.stranger_6 = Stranger.create(
         invitation='zom',
         languages=None,
         telegram_id=0,
         sex=None,
         partner_sex=None
         )