Exemple #1
0
 def test_save_same_record_twice(self):
     start = KennelDataModel('kennel1',
                             name=self.name,
                             acronym=self.acronym)
     start.save()
     start.save()
     self.assertTrue(KennelDataModel.record_exists(start))
Exemple #2
0
 def test_matching_record_not_filtering_self(self):
     kennel = KennelDataModel(self.kennel_id,
                              name=self.name,
                              acronym=self.acronym)
     kennel.save()
     self.assertListEqual(KennelDataModel.matching_records(kennel, False),
                          [kennel])
Exemple #3
0
 def test_is_not_ref(self):
     mdl = KennelDataModel(self.kennel_id,
                           name=self.name,
                           acronym=self.acronym)
     mdl2 = KennelDataModel('diff', name=self.name, acronym=self.acronym)
     ref = mdl2.to_ref()
     self.assertFalse(ref.is_ref(mdl))
Exemple #4
0
 def test_timestamps(self):
     time = datetime.now(timezone.utc)
     with freeze_time(time):
         kennel = KennelDataModel(self.kennel_id,
                                  name=self.name,
                                  acronym=self.acronym)
         kennel.save()
         self.assertEqual(kennel.modified_at, time)
         self.assertEqual(kennel.created_at, time)
Exemple #5
0
 def setUp(self):
     if KennelDataModel.exists():
         KennelDataModel.delete_table()
     KennelDataModel.create_table(read_capacity_units=1,
                                  write_capacity_units=1,
                                  wait=True)
     self.hasher_id = 'test_id'
     self.hash_name = 'Testy Cream'
     self.mother_kennel = KennelLogicModel.create('Test Kennel 1', 'TK1H3')
     if HasherDataModel.exists():
         HasherDataModel.delete_table()
     HasherDataModel.create_table(read_capacity_units=1,
                                  write_capacity_units=1,
                                  wait=True)
Exemple #6
0
 def test_matching_record_by_name(self):
     kennel = KennelDataModel(self.kennel_id,
                              name=self.name,
                              acronym=self.acronym)
     kennel.save()
     kennel2 = KennelDataModel('new_id', name=self.name, acronym='ABCH3')
     with self.assertRaises(AlreadyExists):
         kennel2.save()
Exemple #7
0
 def __init__(self,
              name,
              acronym,
              kennel_id=None,
              description=None,
              region=None,
              contact=None,
              webpage=None,
              founding=None,
              next_trail_number=None,
              facebook=None,
              persistence_object=None):
     super().__init__()
     self.unpersist_values(__class__)
     self.kennel_id = ulid() if kennel_id is None else kennel_id
     self.name = name
     self.acronym = acronym
     self.region = region
     self.events = None
     self.members = list()
     self.officers = None
     self.contact = contact
     self.webpage = webpage
     self.facebook = facebook
     self.founding = founding
     self.description = description
     self.next_trail_number = next_trail_number
     self.load_members()
     if persistence_object is None:
         self.persistence_object = KennelDataModel(
             **self.persistable_attributes())
     else:
         self.persistence_object = persistence_object
Exemple #8
0
 def test_on_save_searchable_name(self):
     k = KennelDataModel(self.kennel_id,
                         name=self.name,
                         acronym=self.acronym)
     new_name = 'Cheese'
     k.name = new_name
     k.save()
     k.refresh()
     self.assertEqual(k.searchable_name, k.searchable_value(new_name))
Exemple #9
0
 def test_on_save_searchable_acronym(self):
     k = KennelDataModel(self.kennel_id,
                         name=self.name,
                         acronym=self.acronym)
     new_acronym = 'CKH3'
     k.acronym = new_acronym
     k.save()
     k.refresh()
     self.assertEqual(k.searchable_acronym, k.searchable_value(new_acronym))
Exemple #10
0
 def test_to_ref(self):
     ref = KennelDataModel(self.kennel_id,
                           name=self.name,
                           acronym=self.acronym).to_ref()
     self.assertEqual(ref.acronym, self.acronym)
     self.assertEqual(ref.kennel_id, self.kennel_id)
     self.assertEqual(ref.name, self.name)
     self.assertListEqual(list(ref.attribute_values.keys()),
                          ['kennel_id', 'name', 'acronym'])
Exemple #11
0
 def setUp(self):
     self.kennel_id = 'test_id'
     self.name = 'Test_Kennel'
     self.acronym = 'TKH3'
     self.region = ['1.1', '1.2', '2.2', '2.1']
     self.contact = [{
         'name': 'test person',
         'phone': '4445556666',
         'email': '*****@*****.**'
     }]
     self.facebook = 'http://www.facebook.com/groups/test_kennel'
     self.webpage = 'http://www.testkennel.com'
     self.founding = {'founder': 'G', 'first trail': '1/1/1930'}
     self.description = 'A test kennel'
     if KennelDataModel.exists():
         KennelDataModel.delete_table()
     KennelDataModel.create_table(read_capacity_units=1,
                                  write_capacity_units=1,
                                  wait=True)
Exemple #12
0
 def test_nullable_fields(self):
     kennel = KennelDataModel(self.kennel_id,
                              name=self.name,
                              acronym=self.acronym)
     self.assertIsNone(kennel.region)
     self.assertIsNone(kennel.contact)
     self.assertIsNone(kennel.webpage)
     self.assertIsNone(kennel.facebook)
     self.assertIsNone(kennel.founding)
     self.assertIsNone(kennel.description)
Exemple #13
0
    def test_all_fields(self):
        KennelDataModel(self.kennel_id,
                        name=self.name,
                        acronym=self.acronym,
                        region=self.region,
                        contact=self.contact,
                        webpage=self.webpage,
                        facebook=self.facebook,
                        founding=self.founding,
                        description=self.description).save()

        kennel = KennelDataModel.get(self.kennel_id)
        self.assertEqual(kennel.region, self.region)
        self.assertEqual(kennel.contact, self.contact)
        self.assertEqual(kennel.webpage, self.webpage)
        self.assertEqual(kennel.facebook, self.facebook)
        self.assertEqual(kennel.founding, self.founding)
        self.assertEqual(kennel.description, self.description)
        self.assertEqual(kennel.searchable_name,
                         kennel.searchable_value(kennel.name))
        self.assertEqual(kennel.searchable_acronym,
                         kennel.searchable_value(kennel.acronym))
Exemple #14
0
 def test_matching_records_multiple_close_matches(self):
     KennelDataModel(self.kennel_id, name=self.name,
                     acronym=self.acronym).save()
     kennel = KennelDataModel('different_id',
                              name='Thinking Kennel',
                              acronym=self.acronym)
     kennel.save()
     KennelDataModel('different_id_2',
                     name='Throwing Kennel',
                     acronym=self.acronym).save()
     match = KennelDataModel('match_kennel',
                             name='Thinking Kennel',
                             acronym=self.acronym)
     x = KennelDataModel.matching_records(match)
     self.assertListEqual(x, [kennel])
Exemple #15
0
 def test_on_init_searchable_acronym(self):
     k = KennelDataModel(self.kennel_id,
                         name=self.name,
                         acronym=self.acronym)
     self.assertEqual(k.searchable_acronym, k.searchable_value(k.acronym))
Exemple #16
0
 def lookup_by_id(kennel_id):
     result = KennelDataModel.get(kennel_id)
     attribute_dict = result.attributes()
     attribute_dict['persistence_object'] = result
     attribute_dict['kennel_id'] = kennel_id
     return KennelLogicModel(**attribute_dict)
Exemple #17
0
 def test_acronym_required(self):
     with self.assertRaises(ValueError):
         KennelDataModel(self.kennel_id, name=self.name)
Exemple #18
0
 def test_id_required(self):
     kennel = KennelDataModel(name=self.name, acronym=self.acronym)
     with self.assertRaises(ValueError):
         kennel.save()
Exemple #19
0
 def tearDown(self):
     if KennelDataModel.exists():
         KennelDataModel.delete_table()
Exemple #20
0
 def test_update_searchable_acronym(self):
     k = KennelDataModel(self.kennel_id,
                         name=self.name,
                         acronym=self.acronym)
     k.save()
     new_acronym = 'CHEH3'
     k.add_update_action('acronym', 'set', new_acronym)
     k.update()
     k.refresh()
     self.assertEqual(k.searchable_acronym, k.searchable_value(new_acronym))
Exemple #21
0
 def test_update_searchable_name(self):
     k = KennelDataModel(self.kennel_id,
                         name=self.name,
                         acronym=self.acronym)
     k.save()
     new_name = 'Cheese'
     k.add_update_action('name', 'set', new_name)
     k.update()
     k.refresh()
     self.assertEqual(k.searchable_name, k.searchable_value(new_name))
Exemple #22
0
 def test_matching_records_does_not_exist(self):
     kennel = KennelDataModel(self.kennel_id,
                              name=self.name,
                              acronym=self.acronym)
     self.assertListEqual(KennelDataModel.matching_records(kennel), list())
Exemple #23
0
 def test_save_with_existing_record(self):
     KennelDataModel('kennel1', name=self.name, acronym=self.acronym).save()
     with self.assertRaises(AlreadyExists):
         KennelDataModel('kennel2', name=self.name,
                         acronym=self.acronym).save()
Exemple #24
0
 def test_record_exists(self):
     kennel = KennelDataModel(self.kennel_id,
                              name=self.name,
                              acronym=self.acronym)
     kennel.save()
     self.assertTrue(KennelDataModel.record_exists(kennel))
Exemple #25
0
 def test_is_ref(self):
     mdl = KennelDataModel(self.kennel_id,
                           name=self.name,
                           acronym=self.acronym)
     ref = mdl.to_ref()
     self.assertTrue(ref.is_ref(mdl))
Exemple #26
0
 def test_record_does_not_exist(self):
     kennel = KennelDataModel(self.kennel_id,
                              name=self.name,
                              acronym=self.acronym)
     self.assertFalse(KennelDataModel.record_exists(kennel))
Exemple #27
0
 def test_init_from_lookup(self):
     KennelDataModel(self.kennel_id, name=self.name, acronym=self.acronym).save()
     x = KennelLogicModel.lookup_by_id(self.kennel_id)
     self.assertEqual(self.kennel_id, x.kennel_id)
     self.assertEqual(self.name, x.name)
     self.assertEqual(self.acronym, x.acronym)