示例#1
0
def before_step(context, step):
    """
    These run before every step.
    """
    if step.name in [
            'I am an admin',
    ]:
        # Create an Admin account.
        admin = factories.AdminFactory()
    elif step.name in [
            'I am a staff member',
    ]:
        # Create a Staff Member account.
        staff = factories.StaffMemberFactory()
    elif step.name in [
            'I am a regular user',
    ]:
        # Create a User account.
        user = factories.UserFactory()
    elif step.name in [
            'I am an anonymous user',
    ]:
        # Create a User account.
        user = factories.UserFactory()
    elif step.name in [
            'I visit the "home" page',
    ]:
        # Create a product.
        product = factories.ProductFactory(
            option__Size=['Small', 'Medium', 'Large'],
            option__Color=['Black', 'White'])
示例#2
0
 def setUp(self):
     self.admin = factories.UserFactory(username='******',
                                        password='******',
                                        super_user=True)
     self.creator = factories.UserFactory(username='******',
                                          password='******')
     self.collab = factories.UserFactory(username='******', password='******')
     self.norm = factories.UserFactory(username='******', password='******')
     self.comp = factories.CompetitionFactory(created_by=self.creator,
                                              collaborators=[self.collab])
     self.lb = factories.LeaderboardFactory(competition=self.comp,
                                            hidden=True)
     factories.ColumnFactory(leaderboard=self.lb, index=0)
示例#3
0
    def setUp(self):
        self.creator = factories.UserFactory(username='******',
                                             password='******')
        self.other_user = factories.UserFactory(username='******',
                                                password='******')
        self.comp = factories.CompetitionFactory(created_by=self.creator)
        self.phase = factories.PhaseFactory(competition=self.comp)
        self.leaderboard = factories.LeaderboardFactory(competition=self.comp)
        factories.ColumnFactory(
            leaderboard=self.leaderboard,
            index=0)  # need to set index here otherwise it's seq

        for _ in range(10):
            factories.SubmissionFactory(phase=self.phase,
                                        leaderboard=self.leaderboard)
示例#4
0
def test_create_new_basket(admin_user):
    with override_settings(**REQUIRED_SETTINGS):
        shop = factories.get_default_shop()
        shop2 = create_shop("foobar")
        client = _get_client(admin_user)
        response = client.post("/api/E-Commerce/basket/new/", {
            "shop": shop2.pk
        })
        assert response.status_code == status.HTTP_201_CREATED
        basket_data = json.loads(response.content.decode("utf-8"))
        basket = Basket.objects.first()
        assert basket.key == basket_data['uuid'].split("-")[1]
        assert basket.shop == shop2
        admin_contact = get_person_contact(admin_user)
        assert basket.customer == admin_contact
        assert basket.orderer == admin_contact
        assert basket.creator == admin_user

        # invalid shop
        response = client.post("/api/E-Commerce/basket/new/", data={"shop": 1000})
        assert response.status_code == status.HTTP_400_BAD_REQUEST

        # no shop in multishop mode
        response = client.post("/api/E-Commerce/basket/new/")
        assert response.status_code == status.HTTP_400_BAD_REQUEST

        # no shop in single shop mode
        with override_settings(E-Commerce_ENABLE_MULTIPLE_SHOPS=False):
            response = client.post("/api/E-Commerce/basket/new/")
            assert response.status_code == status.HTTP_201_CREATED
            basket_data = json.loads(response.content.decode("utf-8"))
            basket = Basket.objects.all()[1]
            assert basket.key == basket_data['uuid'].split("-")[1]
            assert basket.shop == shop
            assert basket.customer == admin_contact
            assert basket.orderer == admin_contact
            assert basket.creator == admin_user

            person = factories.create_random_person()

            response = client.post("/api/E-Commerce/basket/new/", data={"customer": person.pk})
            assert response.status_code == status.HTTP_201_CREATED
            basket_data = json.loads(response.content.decode("utf-8"))
            basket = Basket.objects.all()[2]
            assert basket.key == basket_data['uuid'].split("-")[1]
            assert basket.shop == shop
            assert basket.creator == admin_user
            assert basket.customer.pk == person.pk
            assert basket.orderer.pk == person.pk
            assert basket.creator.pk == admin_user.pk

            # Try to fetch the basket as the customer
            user = factories.UserFactory()
            person.user = user
            person.save()
            response = client.get("/api/E-Commerce/basket/{}/".format(basket_data['uuid']))
            assert response.status_code == 200
            customer_basket_data = json.loads(response.content.decode("utf-8"))
            assert basket.key == customer_basket_data['key']  # Still same basket as before
            assert customer_basket_data['customer']['id'] == person.pk  # Still same customer as before
示例#5
0
    def create_user_and_return_id_and_token(self,
                                            roles=[],
                                            suspended=None,
                                            is_internal_user=None,
                                            enabled=None):
        # create a user to login with
        user = factories.UserFactory(password='******')
        user.roles = roles

        if suspended is not None:
            user.suspended = suspended

        if is_internal_user is not None:
            user.is_internal_user = is_internal_user

        if enabled is not None:
            user.enabled = enabled

        db_session_users.add(user)
        db_session_users.flush()
        db_session_users.refresh(user)

        # create a token to use for authorization for all api calls for the user created above
        seconds_until_expiration = 60 * 60 * 24 * 14
        expiration_datetime = dt.datetime.utcnow() + dt.timedelta(
            seconds=seconds_until_expiration)
        return user, jwt.encode(
            {
                'user_id': user.id,
                'exp': expiration_datetime
            }, SECRET_JWT)
示例#6
0
def before_scenario(context, scenario):
    if scenario.name in [
            'get a list of users as an admin',
            'get a list of users as a regular user',
            'get a list of users as an anonymous user',
    ]:
        # Create 3 users.
        users = [
            factories.UserFactory(username='******' % i) for i in range(3)
        ]
    elif scenario.name in [
            'add a variant via the change user page'  # steps/admin.py
    ]:
        product = factories.ProductFactory()
        inventory = factories.InventoryFactory()
    elif scenario.name in [
            'add a product via the admin panel'  # steps/admin.py
    ]:
        inventory = factories.InventoryFactory()
 def test_user_factory(self):
     user = factories.UserFactory()
     self.assertIsNotNone(user)
示例#8
0
 def setUp(self):
     self.user = factories.UserFactory()