def test_archived_geokret_must_not_be_shown_in_cache_details(self): geokret_1 = self.blend_geokret( owner=self.user_1, created_on_datetime='2018-12-29T16:43:28') MovePayload(MOVE_TYPE_DROPPED, geokret=geokret_1)\ .set_moved_on_datetime('2018-12-29T16:44:57')\ .set_coordinates()\ .set_waypoint('ABC123')\ .post(user=self.user_1) geokret_2 = self.blend_geokret( owner=self.user_1, created_on_datetime='2018-12-29T16:43:28') MovePayload(MOVE_TYPE_DROPPED, geokret=geokret_2)\ .set_moved_on_datetime('2018-12-29T16:44:57')\ .set_coordinates()\ .set_waypoint('ABC123')\ .post(user=self.user_1) GeokretPayload()\ .get_collection(args={'filter': '[{"name":"last_position","op":"has","val":{"name":"waypoint","op":"eq","val":"ABC123"}}]'})\ .assertCount(2) MovePayload(MOVE_TYPE_ARCHIVED, geokret=geokret_1)\ .set_moved_on_datetime('2018-12-29T16:45:03')\ .post(user=self.user_1) GeokretPayload()\ .get_collection(args={'filter': '[{"name":"last_position__waypoint","op":"has","val":"ABC123"}]'})\ .assertCount(1)
def test_geokret_may_be_born_at_home_with_home_coordinates(self): user = self.blend_user(latitude=48.8566, longitude=2.3522) response = GeokretPayload("Name")\ .set_born_at_home(True)\ .post(user=user) MovePayload()\ .get(response._get_relationships('last_move')['data']['id'])\ .assertHasRelationshipMoveTypeData(MOVE_TYPE_DIPPED)\ .assertHasAttribute('latitude', float(user.latitude))\ .assertHasAttribute('longitude', float(user.longitude))\ .assertHasAttributeDateTime('moved-on-datetime', response.created_on_datetime)\ .assertHasRelationshipAuthorData(user)\ .assertHasRelationshipGeokretData(response.id)\ .assertHasAttribute('comment', "Born here")
def test_relationships_holder_override_is_ignored_as(self, username): user = getattr(self, username) if username else None geokret = self.blend_geokret(owner=self.user_1, holder=self.user_1) GeokretPayload()\ .set_holder(self.user_2)\ .patch(geokret.id, user=user)\ .assertHasRelationshipOwnerData(self.user_1.id)
def test_field_updated_on_datetime_automatically_changed(self): geokret = self.blend_geokret(owner=self.user_1, created_on_datetime="2018-09-22T20:27:08") updated_on_datetime = geokret.updated_on_datetime GeokretPayload()\ .patch(geokret.id, user=self.user_1)\ .assertNotHasAttribute('updated-on-datetime', updated_on_datetime.strftime("%Y-%m-%dT%H:%M:%S"))\ .assertHasAttributeDateTime('updated-on-datetime', geokret.updated_on_datetime)
def test_some_fields_are_not_overridable(self): geokret = self.blend_geokret( owner=self.user_1, missing=False, distance=12, caches_count=12, pictures_count=12, created_on_datetime="2018-09-22T19:34:41", updated_on_datetime="2018-09-22T19:34:42", ) GeokretPayload()\ ._set_attribute('missing', True)\ ._set_attribute('distance', 1000)\ ._set_attribute('caches-count', 1000)\ ._set_attribute('pictures-count', 1000)\ ._set_attribute('average-rating', 1000)\ ._set_attribute('created-on-datetime', "2018-09-22T19:38:28")\ ._set_attribute('updated-on-datetime', "2018-09-22T19:38:29")\ .patch(geokret.id, user=self.user_1)\ .assertHasAttribute('missing', False)\ .assertHasAttribute('distance', 12)\ .assertHasAttribute('caches-count', 12)\ .assertHasAttribute('pictures-count', 12)\ .assertHasAttribute('average-rating', 0.0)\ .assertHasAttributeDateTime('created-on-datetime', "2018-09-22T19:34:41")\ .assertHasAttributeDateTime('updated-on-datetime', geokret.updated_on_datetime)
def test_geokret_may_be_born_at_home_but_user_has_no_home_coordinates( self): self.assertIsNone(self.user_1.latitude) self.assertIsNone(self.user_1.longitude) response = GeokretPayload("Name")\ .post(user=self.user_1) with self.assertRaises(ObjectNotFound): safe_query(self, Move, 'geokret_id', response.id, 'geokret_id')
def test_as_authenticated(self): geokrety = self.blend_geokret(owner=self.user_1, count=5) response = GeokretPayload()\ .get_collection(user=self.user_2)\ .assertCount(5) i = 0 for geokret_response in response.data: geokret_response.assertHasPublicAttributes(geokrety[i]) geokret_response.assertHasTrackingCode(None) i = i + 1
def test_as_administrator(self): geokrety = self.blend_geokret(owner=self.user_1, count=5) response = GeokretPayload()\ .get_collection(user=self.admin)\ .assertCount(5) i = 0 for geokret_response in response.data: geokret_response.assertHasPublicAttributes(geokrety[i]) geokret_response.assertHasTrackingCode(geokrety[i].tracking_code) i = i + 1
def test_cannot_edit_even_when_user_has_touched(self, move_type): geokret = self.blend_geokret(created_on_datetime="2018-09-22T18:18:55") self.blend_move(geokret=geokret, author=self.user_1, type=move_type, moved_on_datetime="2018-09-22T18:18:56") self.blend_move(geokret=geokret, author=self.user_2, type=MOVE_TYPE_GRABBED, moved_on_datetime="2018-09-22T18:18:57") GeokretPayload("New name")\ .patch(geokret.id, user=self.user_1, code=403)
def test_as_owner(self): geokret = self.blend_geokret(owner=self.user_2) geokrety = self.blend_geokret(owner=self.user_1, count=4) response = GeokretPayload()\ .get_collection(user=self.user_2)\ .assertCount(5) response.data[0].assertHasPublicAttributes(geokret) response.data[0].assertHasTrackingCode(geokret.tracking_code) for i in range(1, 5): response.data[i].assertHasPublicAttributes(geokrety[i - 1]) response.data[i].assertHasTrackingCode(None)
def test_relationships_moves_cannot_be_forced_as(self, username): user = getattr(self, username) if username else None geokret_1 = self.blend_geokret(owner=self.user_1, holder=self.user_1) geokret_2 = self.blend_geokret() moves = self.blend_move(geokret=geokret_2, count=2) moves_ids = [move.id for move in moves] GeokretPayload()\ ._set_relationships_many('moves', 'move', moves_ids)\ .patch(geokret_1.id, user=user, args={'include': 'moves'})\ .assertHasRelationshipMovesDatas([])
def test_filter_by_tracking_code_as(self, username, expected): user = getattr(self, username) if username else None geokret = self.blend_geokret(owner=self.user_1) response = GeokretPayload()\ .get_collection(user=user, args={'filter': '[{"name":"tracking_code","op":"eq","val":"%s"}]' % ( geokret.tracking_code)})\ .assertCount(1) if expected: response.data[0].assertHasTrackingCode(geokret.tracking_code) else: response.data[0].assertHasTrackingCode(None)
def test_field_type_can_be_changed(self, username, geokret_type, expected): user = getattr(self, username) if username else None geokret = self.blend_geokret(owner=self.user_1, type=GEOKRET_TYPE_TRADITIONAL) payload = GeokretPayload().set_geokret_type(geokret_type) if expected: payload.patch(geokret.id, user=user)\ .assertHasRelationshipGeokretyTypeData(geokret_type) else: payload.patch(geokret.id, user=user, code=422)\ .assertRaiseJsonApiError('/data/relationships/type')
def test_has_tracking_code_when_user_has_touched(self, move_type, expected): geokret = self.blend_geokret(created_on_datetime="2018-09-20T23:15:30") self.blend_move(geokret=geokret, author=self.user_1, type=move_type, moved_on_datetime="2018-09-20T23:15:31") self.blend_move(geokret=geokret, author=self.user_2, type=MOVE_TYPE_GRABBED, moved_on_datetime="2018-09-20T23:15:32") response = GeokretPayload()\ .get_collection(user=self.user_1)\ .assertCount(1) if expected: response.data[0].assertHasTrackingCode(geokret.tracking_code) else: response.data[0].assertHasTrackingCode(None)
def test_filter_by_tracking_code_when_user_has_touched( self, move_type, expected): geokret = self.blend_geokret(author=self.user_2, created_on_datetime="2018-09-21T23:55:20") self.blend_move(geokret=geokret, author=self.user_1, type=move_type, moved_on_datetime="2018-09-21T23:55:21") self.blend_move(geokret=geokret, author=self.user_2, type=MOVE_TYPE_GRABBED, moved_on_datetime="2018-09-21T23:55:22") response = GeokretPayload()\ .get_collection(user=self.user_1, args={'filter': '[{"name":"tracking_code","op":"eq","val":"%s"}]' % ( geokret.tracking_code)})\ .assertCount(1) if expected: response.data[0].assertHasTrackingCode(geokret.tracking_code) else: response.data[0].assertHasTrackingCode(None)
def test_field_update_datetime_is_auto_managed(self): GeokretPayload("Name")\ .post(user=self.user_1)\ .assertUpdatedDateTime()
def test_field_creation_datetime_is_auto_managed(self): GeokretPayload("Name")\ .post(user=self.user_1)\ .assertCreationDateTime()
def test_as_authenticated_user(self): GeokretPayload("Name").post(user=self.user_1)
def test_as_anonymous_user(self): GeokretPayload().post(user=None, code=401)
def test_bulk_operation_is_not_yet_supported(self): payload = GeokretPayload("Name") payload['data'] = [payload['data']] payload.post(user=self.user_1, code=422)\ .assertRaiseJsonApiError('/data')
def test_holder_may_be_overrided_by_admin(self): GeokretPayload("Name")\ .set_owner(self.user_1)\ .post(user=self.admin)\ .assertHasRelationshipHolderData(self.user_1.id)
def test_owner_enforced_by_admin(self): GeokretPayload("Name")\ .set_owner(self.user_1)\ .post(user=self.admin)\ .assertHasRelationshipOwnerData(self.user_1.id)
def test_owner_is_the_connected_user_if_undefined_even_for_admin(self): GeokretPayload("Name")\ .post(user=self.admin)\ .assertHasRelationshipOwnerData(self.admin.id)
def test_field_creation_datetime_is_equal_to_update_datetime(self): GeokretPayload("Name")\ .post(user=self.user_1)\ .assertDateTimeAlmostEqual('created_on_datetime', 'updated_on_datetime')
def test_owner_is_the_connected_user_if_undefined(self): GeokretPayload("Name")\ .post(user=self.user_1)\ .assertHasRelationshipOwnerData(self.user_1.id)
def test_field_description_may_be_absent(self): GeokretPayload("Name")\ ._del_attribute('description')\ .post(user=self.user_1)\ .assertHasAttribute('description', '')
def test_owner_enforced_to_current_user(self): GeokretPayload("Name")\ .set_owner(self.user_2)\ .post(user=self.user_1)\ .assertHasRelationshipOwnerData(self.user_1.id)
def test_field_description_accept_html_subset(self, description, result): GeokretPayload("Name")\ .set_description(description)\ .post(user=self.user_1)\ .assertHasAttribute('description', result)
def test_geokrety_type_relationships_exists(self, geokret_type): GeokretPayload("Name")\ .set_geokret_type(geokret_type)\ .post(user=self.user_1)\ .assertHasRelationshipGeokretyType()
def test_holder_defaults_to_current_user(self, username): user = getattr(self, username) if username else None GeokretPayload("Name")\ .post(user=user)\ .assertHasRelationshipHolderData(user.id)