Example #1
0
 def test_detail_get_past(self):
     occ = get(Occurrence, place=F(point=F(geometry=geos.Point(y=0, x=0))))
     uri = self.resource().get_resource_uri(occ)
     resp = self.client.get(uri, data=self.auth_params)
     resp_dict = try_json_loads(resp.content)
     self.assertIsNone(resp_dict, 'Returned unexpected existing occurrence')
     self.assertResponseCode(resp, 410)
Example #2
0
    def test_detail_get_future(self):
        occ = get(Occurrence,
                  start_date=datetime.datetime.now().date() +
                  datetime.timedelta(days=30),
                  place=F(point=F(geometry=geos.Point(y=0, x=0))))
        uri = self.resource().get_resource_uri(occ)
        resp = self.client.get(uri, data=self.auth_params)
        resp_dict = try_json_loads(resp.content)
        self.assertIsNotNone(resp_dict, 'Malformed response')
        self.assertResponseCode(resp, 200)
        self.assertEqual(uri, resp_dict['resource_uri'],
                         'Unexpected resource uri in response')

        event_field = resp_dict.get('event')
        self.assertIsInstance(
            event_field, basestring,
            'Did not find expected reference to associated event URI')
        place_field = resp_dict.get('place')
        self.assertIsInstance(place_field, dict,
                              'Full occurrence does not have place dict')
        point_field = place_field.get('point')
        self.assertIsInstance(point_field, dict,
                              'Full occurrence dict does not have point dict')
        city_field = point_field.get('city')
        self.assertIsInstance(city_field, dict,
                              'Full occurrence dict does not have city dict')
Example #3
0
 def test_message_shout_attachments(self):
     """
     Result contains distinct shouts that has message attachments,
     linked to requested conversation
     """
     c2 = G(Conversation, type=CONVERSATION_TYPE_CHAT, creator=self.user1)
     m1 = G(Message, user=self.user1, conversation=self.c1)
     m2 = G(Message, user=self.user1, conversation=c2)
     shout1 = self.create_shout(user=self.user1,
                                category=F(name='velo', slug='velo'),
                                item=F(name='Marin'))
     shout2 = self.create_shout(user=self.user1,
                                category=F(name='flower', slug='flower'),
                                item=F(name='Rose'))
     shout1.message_attachments.add(
         G(MessageAttachment,
           type=MESSAGE_ATTACHMENT_TYPE_SHOUT,
           message=m1,
           conversation=self.c1),
         G(MessageAttachment,
           type=MESSAGE_ATTACHMENT_TYPE_SHOUT,
           message=m1,
           conversation=self.c1),
     )
     shout2.message_attachments.add(
         G(MessageAttachment,
           type=MESSAGE_ATTACHMENT_TYPE_SHOUT,
           message=m2,
           conversation=c2))
     self.login(self.user1)
     resp = self.client.get(self.get_url(self.c1.pk))
     self.assert200(resp)
     self.assert_ids_equal(self.decode_json(resp)['results'], [shout1])
Example #4
0
 def test_adapt_existing_valid(self):
     occurrence = G(Occurrence, place=F(point=F(geometry=geos.Point(y=0, x=0))))
     existing_prices = {G(Price, occurrence=occurrence, quantity=quantity) for quantity in self.quantities}
     prices = self.adaptor.adapt_m2o(self.event_response, occurrence=occurrence.id)
     for created, price in prices:
         self.assertFalse(created, 'Price object created despite existing match')
         self.assertIn(price, existing_prices, 'Price object returned is not the existing match')
Example #5
0
 def test_adapt_new_valid(self):
     occurrence = G(Occurrence, place=F(point=F(geometry=geos.Point(y=0, x=0))))
     prices = self.adaptor.adapt_m2o(self.event_response, occurrence=occurrence.id)
     for created, price in prices:
         self.assertTrue(created, 'Price object was not newly created')
         self.assertIsInstance(price, Price, 'Unexpected type of price object')
         self.assertIn(price.quantity, self.quantities, 'Unexpected quantity value')
         self.assertEqual(u'dollars', price.units, 'Unexpected units value')
Example #6
0
    def test_adapt_new_invalid(self):
        occurrence = G(Occurrence, place=F(point=F(geometry=geos.Point(y=40.7601, x=-73.9925))))

        created_prices = self.adaptor.adapt_m2o(self.invalid_response, occurrence=occurrence.id)
        self.assertTrue(all(not created for created, price in created_prices),
            'Price object created despite invalid data')
        self.assertTrue(all(price is None for created, price in created_prices),
            'Price object returned despite invalid data')
 def test_look_up_alias_with_many_parameters(self):
     self.assertEquals({'a': 1, 'b': 2}, look_up_alias(a=1, b=2))
     self.assertEquals({'a': 1, 'b_c': 2}, look_up_alias(a=1, b_c=2))
     self.assertEquals({'a': 1, 'b': F(c=2)}, look_up_alias(a=1, b__c=2))
     self.assertEquals({
         'a': F(b=1),
         'c': F(d=2)
     }, look_up_alias(a__b=1, c__d=2))
 def test_m2m_with_many_elements(self):
     instance = G(ModelWithRelationships,
                  integer=1000,
                  manytomany=[F(integer=1001),
                              F(integer=1002)])
     self.assertEquals(1000, instance.integer)
     self.assertEquals(1001, instance.manytomany.all()[0].integer)
     self.assertEquals(1002, instance.manytomany.all()[1].integer)
Example #9
0
 def test_list_get_future(self):
     get(Occurrence,
         start_date=datetime.datetime.now().date() +
         datetime.timedelta(days=10),
         place=F(point=F(geometry=geos.Point(y=0, x=0))))
     resp = self.client.get(self.uri, data=self.auth_params)
     self.assertResponseCode(resp, 200)
     self.assertResponseMetaList(resp, 1)
def slot_initial_data(db):
    G(Slot, zone=F(num=1), mon=True,
      start_time=time(8, 0), end_time=time(9, 59))
    G(Slot, zone=F(num=1), mon=True,
      start_time=time(14, 0), end_time=time(15, 59))
    good_data = {
        'zone': reverse('heating:zone-detail', args=[1]), 'mode': 'E',
        'start_time': '10:00', 'end_time': '14:00', 'mon': True
    }
    return good_data
 def test_string_representation(self):
     start = timezone.make_aware(datetime.datetime(2015, 2, 25, 17, 24),
                                 timezone.get_default_timezone())
     end = timezone.make_aware(datetime.datetime(2015, 3, 18, 18, 12),
                               timezone.get_default_timezone())
     derog = G(Derogation,
               start_dt=start,
               end_dt=end,
               mode='H',
               zones=[F(num=2), F(num=3)])
     assert str(derog) == "25/02-17:24->18/03-18:12 H Z2-Z3"
Example #12
0
 def test_look_up_alias_as_f_with_all_params_combination(self):
     assert {'a': 1} == look_up_alias(a=1)
     assert {'a': 1, 'b': 2} == look_up_alias(a=1, b=2)
     assert {'a': F(b=1)} == look_up_alias(a__b=1)
     assert {'a': F(b=1), 'c': 2} == look_up_alias(a__b=1, c=2)
     assert {'a': F(b=1), 'c': F(d=2)} == look_up_alias(a__b=1, c__d=2)
     assert {'a': F(b=1, c=2)} == look_up_alias(a__b=1, a__c=2)
     assert {'a': F(b=1, c=F(d=2))} == look_up_alias(a__b=1, a__c__d=2)
     assert {
         'a': F(b=1, c=F(d=2)),
         'e': F(f=3),
         'g': 4
     } == look_up_alias(a__b=1, a__c__d=2, e__f=3, g=4)
def derogation_initial_data(db):
    G(Derogation, zones=[F(num=1)],
      start_dt=datetime(2016, 9, 12, 22, 0),
      end_dt=datetime(2016, 9, 13, 5, 59))
    G(Derogation, zones=[F(num=1)],
      start_dt=datetime(2016, 9, 13, 14, 0),
      end_dt=datetime(2016, 9, 13, 21, 59))
    good_data = {
        'zones': [reverse('heating:zone-detail', args=[1])], 'mode': 'E',
        'start_dt': '2016-09-13T06:00', 'end_dt': '2016-09-13T14:00',
        'start_initial': '2016-09-13T05:59'
    }
    return good_data
Example #14
0
    def test_no_cascade_if_super_entity_exists(self):
        """
        Tests that super entities arent synced again if they have already been synced.
        """
        account = G(Account, team=F(team_group=F()))
        self.assertTrue(Account.objects.exists())
        self.assertTrue(Team.objects.exists())
        self.assertTrue(TeamGroup.objects.exists())

        entity_syncer = EntitySyncer()
        entity_syncer.sync_entities_and_relationships(account)
        # Verify that only the account and team reside in the entity syncer cache. This means that
        # the syncing didnt percolate all the way to the team group
        self.assertEquals(len(entity_syncer._synced_entity_cache), 2)
Example #15
0
 def test_look_up_alias_with_just_one_parameter(self):
     assert {'a': 1} == look_up_alias(a=1)
     assert {'a': F()} == look_up_alias(a=F())
     assert {'a_b': 1} == look_up_alias(a_b=1)
     assert {'a': F(b=1)} == look_up_alias(a__b=1)
     assert {'a_b': F(c=1)} == look_up_alias(a_b__c=1)
     assert {'a': F(b=F(c=1))} == look_up_alias(a__b__c=1)
     assert {'a_b': F(c_d=F(e_f=1))} == look_up_alias(a_b__c_d__e_f=1)
Example #16
0
 def test_message_media_attachments(self):
     """
     Result contains message attachments linked to requested conversation
     """
     m = G(Message, user=self.user1, conversation=self.c1)
     G(MessageAttachment,
       type=MESSAGE_ATTACHMENT_TYPE_MEDIA,
       message=m,
       conversation=self.c1,
       images=['http://s3.com/media.png'],
       videos=[F(url='http://yout.com/abc')])
     G(MessageAttachment,
       type=MESSAGE_ATTACHMENT_TYPE_SHOUT,
       message=m,
       conversation=self.c1)
     self.login(self.user1)
     resp = self.client.get(self.get_url(self.c1.pk))
     self.assert200(resp)
     resp_results = self.decode_json(resp)['results']
     self.assertEqual(len(resp_results), 1)
     self.assertEqual(resp_results[0]['images'],
                      ['http://s3.com/media.png'])
     self.assertEqual([v['url'] for v in resp_results[0]['videos']],
                      ['http://yout.com/abc'])
     # only media fields are present
     self.assertFalse(
         set(resp_results[0].keys())
         & set(['shout', 'location', 'profile']))
Example #17
0
 def test_two_properties_same_object(self):
     instance = G(ModelWithRelationships,
                  integer=1000,
                  foreignkey=F(integer=1001, integer_b=1002))
     assert instance.integer == 1000
     assert instance.foreignkey.integer == 1001
     assert instance.foreignkey.integer_b == 1002
Example #18
0
def g_email(**kwargs):
    view_uid = kwargs.pop('view_uid', uuid.uuid4())
    context = kwargs.pop('context', None)
    if context is not None:
        return G(Email, view_uid=view_uid, event=F(context=context), **kwargs)
    else:
        return G(Email, view_uid=view_uid, **kwargs)
Example #19
0
    def setUp(self):
        self.data_auth = {
            'password': '******',
            'username': '******',
        }
        self.client = APIClient()
        self.user = User.objects.create_user(
            email='*****@*****.**',
            first_name='test',
            last_name='edw',
            **self.data_auth,
        )

        self.token = self.client.post(
            reverse('login'),
            data=self.data_auth,
        ).json()['token']

        self.task_description = 'test_description'
        self.task_other_description = 't-rf-rx'
        self.task = G(Task, user=self.user, description=self.task_description)
        self.task_other = G(Task, user=F(), description=self.task_other_description)

        self.url_task_list = reverse('api:task-list')
        self.url_detail_task = reverse('api:task-detail', args=[self.task.id])
        self.url_detail_task2 = reverse('api:task-detail', args=[self.task_other.id])
Example #20
0
    def test_place_filters(self):
        datetimes = (datetime.datetime(*d)
                     for d in ((2100, 1, 2, 0, 0), (2100, 1, 1, 12, 00),
                               (2100, 1, 1, 23, 00)))
        place = get(Place, point=F(geometry=geos.Point(x=0, y=0)))
        matched_events = {
            self.make_event_fixture(start_date=dt.date(),
                                    start_time=dt.time(),
                                    place=place)
            for dt in datetimes
        }
        self.make_event_fixture()  # throw in a non-match

        query_params = dict(**self.auth_params)
        query_params.update(
            **{'place': PlaceFilterOptions()._uri_from_obj(place)})
        resp = self.client.get(self.uri, data=query_params)

        self.assertResponseCode(resp, 200)
        self.assertResponseMetaList(resp, len(matched_events))

        json_resp = try_json_loads(resp.content)
        resource = api_v1._registry['eventsummary']

        matched_events_sorted = sorted(
            matched_events,
            key=lambda e: e.occurrences.all()[0].start_datetime)
        for matched_event, event_summary_json in zip(matched_events_sorted,
                                                     json_resp['objects']):
            event_summary = resource.get_via_uri(
                event_summary_json['resource_uri'])
            self.assertIn(event_summary.event, matched_events,
                          'Should not be part of search results')
            self.assertEqual(matched_event, event_summary.event,
                             'Unexpected order')
 def test_look_up_alias_with_just_one_parameter(self):
     self.assertEquals({'a': 1}, look_up_alias(a=1))
     self.assertEquals({'a': F()}, look_up_alias(a=F()))
     self.assertEquals({'a_b': 1}, look_up_alias(a_b=1))
     self.assertEquals({'a': F(b=1)}, look_up_alias(a__b=1))
     self.assertEquals({'a_b': F(c=1)}, look_up_alias(a_b__c=1))
     self.assertEquals({'a': F(b=F(c=1))}, look_up_alias(a__b__c=1))
     self.assertEquals({'a_b': F(c_d=F(e_f=1))},
                       look_up_alias(a_b__c_d__e_f=1))
 def test_user_guide_info_admin(self):
     guide_info_admin = GuideInfoAdmin(GuideInfo, self.site)
     guide_info_obj = G(GuideInfo, guide=F(guide_name='test_name'))
     self.assertEqual(
         guide_info_admin.list_display,
         ('user', 'guide_name', 'is_finished', 'finished_time'))
     self.assertEqual(guide_info_admin.guide_name(guide_info_obj),
                      'test_name')
Example #23
0
 def setUpTestData(cls):
     cls.user1 = cls.create_user(username='******', email='*****@*****.**')
     cls.page1 = G(Page,
                   user=cls.user1,
                   creator=cls.user1,
                   name='page1',
                   slug='page1',
                   category=F(name='pagecat', slug='pagecat'))
Example #24
0
 def test_adapt_existing_valid(self):
     # place uniqueness: title, point
     existing_place = G(Place, title='Swing 46 Jazz and Supper Club', point=F(geometry=geos.Point(0, 0),
         address=self.point_address, city=City.objects.create(city='New York', state='NY')
     ))
     created, place = self.adaptor.adapt(self.event_response)
     self.assertFalse(created, 'Place object created despite existing match')
     self.assertEqual(existing_place, place, 'Place object returned is not the existing match')
Example #25
0
 def make_event_fixture(
         concrete_category=Category.objects.get(slug='music'),
         start_date=datetime.date(2063, 1, 1),
         start_time=datetime.time(),
         place=None):
     event = get(Event,
                 concrete_category=concrete_category,
                 secret_key='f' * 10)
     place = place or F(point=F(geometry=geos.Point(x=0, y=0)))
     occurrence = get(Occurrence,
                      event=event,
                      place=place,
                      start_date=start_date,
                      start_time=start_time)
     get(Price, occurrence=occurrence)
     event.save()
     return event
Example #26
0
 def test_message_shout_attachmet_is_saved(self):
     """
     Shout attachment is saved in message
     """
     shout = self.create_shout(
         user=self.user1, category=F(name='velo', slug='velo'), item=F(name='Marin'))
     self.login(self.user1)
     resp = self.client.post(self.get_url(self.c1.pk), {
         'text': 'm1',
         'attachments': [
             {
                 'shout': {'id': shout.pk}
             },
         ]
     })
     attachment = self.assert_one_attachment(
         resp, 'm1', MESSAGE_ATTACHMENT_TYPE_SHOUT)
     self.assertEqual(attachment.attached_object.pk, shout.pk)
Example #27
0
 def test_using_look_up_alias(self):
     instance = G(ModelWithRelationships,
                  integer=1000,
                  foreignkey__integer=1001,
                  selfforeignkey__integer=1002,
                  onetoone__integer=1003,
                  manytomany=[
                      F(integer=1004),
                      F(integer=1005),
                      F(selfforeignkey__integer=1006)
                  ])
     assert instance.integer == 1000
     assert instance.foreignkey.integer == 1001
     assert instance.selfforeignkey.integer == 1002
     assert instance.onetoone.integer == 1003
     assert instance.manytomany.all()[0].integer == 1004
     assert instance.manytomany.all()[1].integer == 1005
     assert instance.manytomany.all()[2].selfforeignkey.integer == 1006
Example #28
0
 def create_shout(cls, **kwargs):
     if 'post_ptr' not in kwargs:
         kwargs['post_ptr'] = G(
             Post, user=cls.create_user(username=cls.get_random_string(10)))
     if 'category' not in kwargs:
         kwargs['category'] = F()
     if 'user' not in kwargs:
         kwargs['user'] = cls.create_user(
             username=cls.get_random_string(10))
     return G(Shout, **kwargs)
 def test_using_look_up_alias(self):
     instance = G(ModelWithRelationships,
                  integer=1000,
                  foreignkey__integer=1001,
                  selfforeignkey__integer=1002,
                  onetoone__integer=1003,
                  manytomany=[
                      F(integer=1004),
                      F(integer=1005),
                      F(selfforeignkey__integer=1006)
                  ])
     self.assertEquals(1000, instance.integer)
     self.assertEquals(1001, instance.foreignkey.integer)
     self.assertEquals(1002, instance.selfforeignkey.integer)
     self.assertEquals(1003, instance.onetoone.integer)
     self.assertEquals(1004, instance.manytomany.all()[0].integer)
     self.assertEquals(1005, instance.manytomany.all()[1].integer)
     self.assertEquals(1006,
                       instance.manytomany.all()[2].selfforeignkey.integer)
Example #30
0
 def test_adapt_existing_valid(self):
     event, place = G(Event), G(Place, point=F(geometry=geos.Point(y=0, x=0)))
     existing_occurrences = {G(Occurrence, event=event, start_date=start_date,
         start_time=self.expected_start_time, place=place) for start_date in self.expected_start_dates
     }
     occurrences = self.adaptor.adapt_m2o(self.event_response, event=event.id, place=place.id)
     for created, occurrence in occurrences:
         self.assertFalse(created, 'Occurrence created despite existing match')
         self.assertIsInstance(occurrence, Occurrence, 'Occurrence type expected')
         self.assertIn(occurrence, existing_occurrences, 'Occurrence object returned is not the existing match')