Beispiel #1
0
 def setUp(self):
     self.staff = G(User, is_staff=True, username='******')
     self.commtype = CommunicationEventType.objects.create(
         name="Password reset",
         category=CommunicationEventType.USER_RELATED)
Beispiel #2
0
 def test_can_be_authorised_by_anyone_by_default(self):
     self.account.save()
     user = G(User)
     self.assertTrue(self.account.can_be_authorised_by(user))
Beispiel #3
0
def admin_site(browser, administrator):
    G(DemoModel, n=5)
    G(UserDetail, n=5)
    login(browser)
    return browser, administrator
Beispiel #4
0
 def testMommyAttended(self):
     G(Attendee, event=self.attendance_event, user=self.user, attended=True)
     self.assertEqual([], self.attendance_event.not_attended())
Beispiel #5
0
 def test_includes_only_expired_accounts(self):
     now = timezone.now()
     G(Account, start_date=None, end_date=now - datetime.timedelta(days=1))
     G(Account, start_date=None, end_date=now + datetime.timedelta(days=1))
     accounts = Account.expired.all()
     self.assertEqual(1, accounts.count())
Beispiel #6
0
 def setUp(self):
     [G(Variete) for i in range(1, 5)]
def demomodel2():
    return G(DemoModel2)
 def setUp(self):
     self.ct_1 = G(ContentType)
     self.ct_2 = G(ContentType)
     self.medium_1 = G(Medium)
     self.medium_2 = G(Medium)
     self.source_1 = G(Source)
     self.source_2 = G(Source)
     self.entity_1 = G(Entity, entity_type=self.ct_1)  # sub
     self.entity_2 = G(Entity)  # super
     self.entity_3 = G(Entity)  # super
     self.entity_4 = G(Entity, entity_type=self.ct_2)  # sub
     G(EntityRelationship,
       sub_entity=self.entity_1,
       super_entity=self.entity_2)
     G(EntityRelationship,
       sub_entity=self.entity_1,
       super_entity=self.entity_3)
     G(EntityRelationship,
       sub_entity=self.entity_4,
       super_entity=self.entity_2)
     G(EntityRelationship,
       sub_entity=self.entity_4,
       super_entity=self.entity_3)
 def setUp(self):
     self.super_ct = G(ContentType)
     self.sub_ct = G(ContentType)
     self.super_e1 = G(Entity, entity_type=self.super_ct)
     self.super_e2 = G(Entity, entity_type=self.super_ct)
     self.sub_e1 = G(Entity, entity_type=self.sub_ct)
     self.sub_e2 = G(Entity, entity_type=self.sub_ct)
     self.sub_e3 = G(Entity, entity_type=self.sub_ct)
     self.sub_e4 = G(Entity, entity_type=self.sub_ct)
     self.ind_e1 = G(Entity, entity_type=self.sub_ct)
     self.ind_e2 = G(Entity, entity_type=self.sub_ct)
     self.medium = G(Medium)
     self.source = G(Source)
     G(EntityRelationship,
       sub_entity=self.sub_e1,
       super_entity=self.super_e1)
     G(EntityRelationship,
       sub_entity=self.sub_e2,
       super_entity=self.super_e1)
     G(EntityRelationship,
       sub_entity=self.sub_e3,
       super_entity=self.super_e2)
     G(EntityRelationship,
       sub_entity=self.sub_e4,
       super_entity=self.super_e2)
Beispiel #10
0
 def setUp(self):
     self.user = User.objects.create(username="******")
     self.member = G(Member,
                     user=self.user,
                     category=Category.objects.get(id=1))
 def setUp(self):
     self.ct = G(ContentType)
     self.source_1 = G(Source)
     self.source_2 = G(Source)
     self.medium_1 = G(Medium)
     self.medium_2 = G(Medium)
 def test_no_subscriptions(self):
     G(Event, context={})
     EntityEmailerInterface.convert_events_to_emails()
     self.assertFalse(Email.objects.exists())
 def setUp(self):
     G(Medium, name='email')
    def test_basic_only_following_false_group_subscription_with_unsubscribed(
            self):
        source = G(Source)
        ek = G(EntityKind)
        e = G(Entity, entity_kind=ek)
        se = G(Entity)
        G(EntityRelationship, sub_entity=e, super_entity=se)
        other_e = G(Entity, entity_kind=ek)
        G(EntityRelationship, sub_entity=other_e, super_entity=se)

        G(Subscription,
          entity=se,
          sub_entity_kind=ek,
          source=source,
          medium=self.email_medium,
          only_following=False)
        G(Unsubscription, entity=e, source=source, medium=self.email_medium)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        self.assertEquals(set(email.recipients.all()), set([other_e]))
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
Beispiel #15
0
 def test_string(self):
     """Verify that the model's string method returns the user's full name."""
     full_name = 'Bob'
     user = G(User, full_name=full_name)
     self.assertEqual(str(user), full_name)
 def test_is_unsubscribed(self):
     entity, source, medium = G(Entity), G(Source), G(Medium)
     G(Unsubscribe, entity=entity, source=source, medium=medium)
     is_unsubscribed = Unsubscribe.objects.is_unsubscribed(
         source, medium, entity)
     self.assertTrue(is_unsubscribed)
Beispiel #17
0
 def test_create_message(self):
     api.create_message(G(get_user_model()), INFO, 'message')
 def test_is_not_unsubscribed(self):
     entity, source, medium = G(Entity), G(Source), G(Medium)
     is_unsubscribed = Unsubscribe.objects.is_unsubscribed(
         source, medium, entity)
     self.assertFalse(is_unsubscribed)
    def setUp(self):
        self.study_admin = G(User,
                             is_active=True,
                             is_researcher=True,
                             given_name="Researcher 1")
        self.study_designer = G(User,
                                is_active=True,
                                is_researcher=True,
                                given_name="Researcher 2")
        self.main_lab = G(Lab, name="MIT", approved_to_test=True)
        self.main_lab.researchers.add(self.study_designer)
        self.main_lab.researchers.add(self.study_admin)
        self.main_lab.member_group.user_set.add(self.study_designer)
        self.main_lab.member_group.user_set.add(self.study_admin)
        self.main_lab.save()

        # Researchers have same roles in second lab
        self.second_lab = G(Lab, name="Harvard", approved_to_test=True)
        self.second_lab.researchers.add(self.study_designer)
        self.second_lab.researchers.add(self.study_admin)
        self.second_lab.member_group.user_set.add(self.study_designer)
        self.second_lab.member_group.user_set.add(self.study_admin)
        self.second_lab.save()

        # Study admin does not have permissiont to move study to this lab
        self.other_lab = G(Lab, name="Caltech", approved_to_test=True)
        self.other_lab.researchers.add(self.study_admin)
        self.other_lab.readonly_group.user_set.add(self.study_admin)
        self.other_lab.save()

        self.study_type = G(StudyType, name="default", id=1)
        self.other_study_type = G(StudyType, name="other", id=2)
        self.nonexistent_study_type_id = 999

        self.generator_function_string = (
            "function(child, pastSessions) {return {frames: {}, sequence: []};}"
        )
        self.structure_string = (
            "some exact text that should be displayed in place of the loaded structure"
        )
        self.study = G(
            Study,
            image=SimpleUploadedFile(
                "fake_image.png", b"fake-stuff", content_type="image/png"
            ),  # we could also pass fill_nullable_fields=True
            # See: https://django-dynamic-fixture.readthedocs.io/en/latest/data.html#fill-nullable-fields
            creator=self.study_admin,
            shared_preview=False,
            study_type=self.study_type,
            name="Test Study",
            lab=self.main_lab,
            exit_url="https://lookit.mit.edu/studies/history",
            criteria_expression="",
            structure={
                "frames": {
                    "frame-a": {},
                    "frame-b": {}
                },
                "sequence": ["frame-a", "frame-b"],
                "exact_text": self.structure_string,
            },
            use_generator=False,
            generator=self.generator_function_string,
            metadata={
                "player_repo_url":
                "https://github.com/lookit/ember-lookit-frameplayer",
                "last_known_player_sha": "fakecommitsha",
            },
            built=True,
        )
        self.study.admin_group.user_set.add(self.study_admin)
        self.study.design_group.user_set.add(self.study_designer)
        self.study.save()
        self.age_error_message = "The maximum age must be greater than the minimum age."
    def test_query_count(self):
        ct = G(ContentType)
        e0 = G(Entity, entity_type=ct)  # sub
        e1 = G(Entity, entity_type=ct)  # sub
        e2 = G(Entity)  # super
        e3 = G(Entity)  # super
        e4 = G(Entity)  # super
        e5 = G(Entity)  # super
        e6 = G(Entity)  # super
        m1, m2, m3, m4, m5 = G(Medium), G(Medium), G(Medium), G(Medium), G(
            Medium)
        s1, s2 = G(Source), G(Source)
        G(EntityRelationship,
          sub_entity=e1,
          super_entity=e2,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e1,
          super_entity=e3,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e1,
          super_entity=e4,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e1,
          super_entity=e5,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e1,
          super_entity=e6,
          subentity_type=ct)

        G(EntityRelationship,
          sub_entity=e0,
          super_entity=e2,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e0,
          super_entity=e3,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e0,
          super_entity=e4,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e0,
          super_entity=e5,
          subentity_type=ct)
        G(EntityRelationship,
          sub_entity=e0,
          super_entity=e6,
          subentity_type=ct)

        G(Subscription, entity=e2, subentity_type=ct, source=s1, medium=m1)
        G(Subscription, entity=e3, subentity_type=ct, source=s1, medium=m2)
        G(Subscription, entity=e4, subentity_type=ct, source=s1, medium=m3)
        G(Subscription, entity=e5, subentity_type=ct, source=s1, medium=m4)
        G(Subscription, entity=e6, subentity_type=ct, source=s1, medium=m5)

        G(Subscription, entity=e2, subentity_type=ct, source=s2, medium=m1)
        G(Subscription, entity=e3, subentity_type=ct, source=s2, medium=m2)
        G(Subscription, entity=e4, subentity_type=ct, source=s2, medium=m3)
        G(Subscription, entity=e5, subentity_type=ct, source=s2, medium=m4)
        G(Subscription, entity=e6, subentity_type=ct, source=s2, medium=m5)

        with self.assertNumQueries(1):
            mediums = Subscription.objects._mediums_subscribed_individual(
                source=s1, entity=e1)
            list(mediums)

        with self.assertNumQueries(1):
            mediums = Subscription.objects._mediums_subscribed_group(
                source=s1, entity=e6, subentity_type=ct)
            list(mediums)

        with self.assertNumQueries(2):
            Subscription.objects._is_subscribed_individual(source=s1,
                                                           medium=m1,
                                                           entity=e1)

        with self.assertNumQueries(1):
            Subscription.objects._is_subscribed_group(source=s1,
                                                      medium=m1,
                                                      entity=e6,
                                                      subentity_type=ct)

        with self.assertNumQueries(1):
            entities = [e0, e1]
            list(
                Subscription.objects.filter_not_subscribed(source=s1,
                                                           medium=m1,
                                                           entities=entities))
Beispiel #21
0
 def testMommyNotAttended(self):
     G(Attendee,
       event=self.attendance_event,
       user=self.user,
       attended=False)
     self.assertEqual([self.user], self.attendance_event.not_attended())
 def setUp(self):
     self.medium_1 = G(Medium)
     self.medium_2 = G(Medium)
     self.source_1 = G(Source)
     self.source_2 = G(Source)
Beispiel #23
0
 def setUp(self):
     self.account = G(Account,
                      credit_limit=None,
                      start_date=None,
                      end_date=None)
 def setUp(self):
     super(TestAStaffUser, self).setUp()
     self.partner = G(Partner)
Beispiel #25
0
 def test_cannot_be_deleted(self):
     txn = G(Transaction)
     with self.assertRaises(RuntimeError):
         txn.delete()
Beispiel #26
0
 def setUp(self):
     self.logger = logging.getLogger(__name__)
     self.company = G(Company, name="testname")
Beispiel #27
0
 def setUp(self):
     self.user = G(User, idx=1, id='testuser')
     self.valid_client = G(Application, skip_authorization=True, user=None)
     self.invalid_client = G(Application, skip_authorization=True, user=None, jwt_alg=JwtAlg.RS256)
Beispiel #28
0
    def test_allow_relation_with_two_normal_objects(self):
        normal_object1 = G(NormalModel)
        normal_object2 = G(NormalModel)

        self.assertIsNone(
            self.router.allow_relation(normal_object1, normal_object2))
Beispiel #29
0
 def test_one_input(self):
     user = G(User)
     profile = G(UserProfile, user=user)
     field = UsernamesField()
     self.assertEquals(field.clean(profile.screenname)[0].pk, user.pk)
 def setUp(self):
     super().setUp()
     self.admin = G(Admin, is_active=True)
     self.apikey = self.admin.key
     self.client.defaults['HTTP_X_API_KEY'] = self.apikey