Example #1
0
 def test_should_return_BadRequest_when_duplicate_identityFeature_is_posted(
         self):
     # Given
     client = self.set_up()
     identity, project = Helper.generate_database_models(self.identifier)
     feature = Feature(name='feature2', project=project)
     feature.save()
     # When
     initialResponse = client.post(
         self.feature_states_url %
         (identity.environment.api_key, identity.identifier),
         data=self.post_template % (feature.id, True),
         content_type='application/json')
     secondResponse = client.post(
         self.feature_states_url %
         (identity.environment.api_key, identity.identifier),
         data=self.post_template % (feature.id, True),
         content_type='application/json')
     # Then
     identityFeature = identity.identity_features
     self.assertEquals(initialResponse.status_code, status.HTTP_201_CREATED)
     self.assertEquals(secondResponse.status_code,
                       status.HTTP_400_BAD_REQUEST)
     self.assertEquals(identityFeature.count(), 1)
     Helper.clean_up()
Example #2
0
 def test_add_to_cart_when_not_logged_in(self):
     user = User.objects.create_user(username='******', password='******')
     feature = Feature(featureName='Test Feature', author=user)
     feature.save()
     page = self.client.post('/cart/add/{0}'.format(feature.id), {'contribution': 100}, follow=True)
     self.assertEqual(page.status_code, 200)
     self.assertTemplateUsed(page, 'login.html')    
Example #3
0
    def test_should_update_value_of_feature_state(self):
        # Given
        client = self.set_up()
        project = Project.objects.get(name="test project")
        feature = Feature(name="feature", project=project)
        feature.save()
        environment = Environment.objects.get(name="test env")
        feature_state = FeatureState.objects.get(feature=feature,
                                                 environment=environment)

        # When
        response = client.put(
            "/api/v1/environments/%s/featurestates/%d/" %
            (environment.api_key, feature_state.id),
            data=self.fs_put_template %
            (feature_state.id, True, "This is a value"),
            content_type='application/json')  # should change enabled to True

        # Then
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        feature_state.refresh_from_db()
        self.assertEquals(feature_state.get_feature_state_value(),
                          "This is a value")
        self.assertEquals(feature_state.enabled, True)

        Helper.clean_up()
Example #4
0
 def test_should_change_enabled_state_when_put(self):
     # Given
     client = self.set_up()
     organisation = Organisation.objects.get(name="test org")
     project = Project.objects.get(name="test project",
                                   organisation=organisation)
     feature = Feature(name='feature1', project=project)
     feature.save()
     environment = Environment.objects.get(name="test env")
     identity = Identity(identifier="test_identity",
                         environment=environment)
     identity.save()
     feature_state = FeatureState(feature=feature,
                                  identity=identity,
                                  enabled=False,
                                  environment=environment)
     feature_state.save()
     # When
     response = client.put(self.feature_states_detail_url %
                           (identity.environment.api_key,
                            identity.identifier, feature_state.id),
                           data=self.put_template % True,
                           content_type='application/json')
     feature_state.refresh_from_db()
     # Then
     self.assertEquals(response.status_code, status.HTTP_200_OK)
     self.assertEquals(feature_state.enabled, True)
     Helper.clean_up()
    def test_checkout_invalidForm(self):
        user = User.objects.create_user(username='******',
                                        password='******')
        self.client.login(username='******', password='******')
        feature = Feature(featureName='Test Feature', author=user)
        feature.save()
        page = self.client.post('/cart/add/{0}'.format(feature.id),
                                {'contribution': 10},
                                follow=True)
        stripe_id = 'tok_chargeDeclined'
        page = self.client.post('/checkout/', {
            'phone_number': '1234',
            'street_address1': 'my',
            'street_address2': 'address',
            'town_or_city': 'xx',
            'province': 'ireland',
            'country': 'ireland',
            'postcode': 'testcode',
            'credit_card_number': '4000400040004000',
            'cvv': '111',
            'expiry_month': '2',
            'expiry_year': '2020',
            'stripe_id': stripe_id
        },
                                follow=True)

        messages = list(page.context['messages'])
        self.assertEqual(len(messages), 1)
        self.assertEqual(str(messages[0]),
                         'We were unable to take a payment with that card!')
        self.assertEqual(page.status_code, 200)
        self.assertTemplateUsed('checkout.html')
 def test_checkout_correct_creditcard_details(self):
     user = User.objects.create_user(username='******',
                                     password='******')
     self.client.login(username='******', password='******')
     feature = Feature(featureName='Test Feature', author=user)
     feature.save()
     page = self.client.post('/cart/add/{0}'.format(feature.id),
                             {'contribution': 10},
                             follow=True)
     stripe_id = 'tok_visa'
     page = self.client.post('/checkout/', {
         'full_name': 'name',
         'phone_number': '1234',
         'street_address1': 'my',
         'street_address2': 'address',
         'town_or_city': 'xx',
         'province': 'ireland',
         'country': 'ireland',
         'postcode': 'testcode',
         'credit_card_number': '4242424242424242',
         'cvv': '111',
         'expiry_month': '2',
         'expiry_year': '2020',
         'stripe_id': stripe_id
     },
                             follow=True)
     messages = list(page.context['messages'])
     self.assertEqual(len(messages), 1)
     self.assertEqual(str(messages[0]), 'Thank you for your contribution')
     self.assertEqual(page.status_code, 200)
     self.assertTemplateUsed('features.html')
    def test_checkout_with_login_card_declined(self):
        self.client.login(username='******', password='******')

        item = Feature(name="Test feature",
                       description="description of my test feature",
                       donations=30.00,
                       username=self.user)
        item.save()

        self.client.post("/cart/add/{0}".format(item.id),
                         data={
                             'donation_amount': '12',
                             'user': self.user
                         })

        stripe_id = 'tok_chargeDeclined'

        response = self.client.post(
            "/checkout/", {
                'user': self.user,
                'credit_card_number': '4000000000000002',
                'cvv': '123',
                'expiry_month': '04',
                'expiry_year': '2024',
                'stripe_id': stripe_id
            })

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "checkout.html")
        message = list(response.context.get('messages'))[0]
        self.assertEqual(message.tags, "error")
        self.assertEqual(
            message.message,
            "Sorry, we were unable to take a payment with that card")
    def test_checkout_with_login_post(self):
        self.client.login(username='******', password='******')

        item = Feature(name="Test feature",
                       description="description of my test feature",
                       donations=30.00,
                       username=self.user)
        item.save()
        # create shopping cart
        self.client.post("/cart/add/{0}".format(item.id),
                         data={
                             'donation_amount': '6',
                             'user': self.user
                         })

        stripe_id = 'tok_gb'

        response = self.client.post("/checkout/", {
            'user': self.user,
            'credit_card_number': '4242424242424242',
            'cvv': '123',
            'expiry_month': '10',
            'expiry_year': '2024',
            'stripe_id': stripe_id
        },
                                    follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "features.html")
        message = list(response.context.get('messages'))[0]
        self.assertEqual(message.tags, "success")
        self.assertEqual(message.message,
                         "Thank you. You have successfully donated")
    def setUp(self):

        self.user = User.objects.create_user(username='******',
                                             password='******')
        self.feature = Feature(title="Test Feature",
                               author=self.user,
                               content="Test Content")
        self.feature.save()
Example #10
0
 def test_adjust_cart_when_contribution_is_zero(self):
     user = User.objects.create_user(username='******', password='******')
     login = self.client.login(username='******', password='******')
     self.assertTrue(login)
     feature = Feature(featureName='Test Feature', author=user)
     feature.save()
     page = self.client.post('/cart/adjust/{0}'.format(feature.id), {'contribution': 100}, follow=True)
     page = self.client.post('/cart/adjust/{0}'.format(feature.id), {'contribution': 0}, follow=True)
     self.assertEqual(page.status_code, 200)
     self.assertTemplateUsed(page, 'cart.html')        
 def test_load_page(self):
     user = User.objects.create_user('username', '*****@*****.**','password')
     feature = Feature(title="Test Feature", author=user, content="Test Content")
     feature.save()
     self.client.login(username='******', password='******')
     self.client.post('/cart/add/{0}'.format(feature.id), {'contribution': '50'}, follow=True)
     stripe_id = 'tok_visa'
     page=self.client.get('/checkout/')
     self.assertTemplateUsed('checkout/checkout.html')
     
    def test_add_to_cart(self):
        """Test that we can add items to our cart"""
        user = User(username="******")
        user.save()

        feature = Feature(title="test", description="testing", creator=user)
        feature.save()
        
        page = self.client.get('/cart/add/{0}'.format(feature.id))
        self.assertEqual(page.status_code, 301)
Example #13
0
 def test_get_feature_detail_page(self):
     """
     Testing single feature detail view 
     """
     user = User.objects.create_user(username='******', password='******')
     user.save()
     feature = Feature(name='Feature', description='Testing', user=user, price=20, upvotes=0, status='INCOMPLETE')
     feature.save()
     page = self.client.get('/features/feature_detail/1', follow=True)
     self.assertEqual(page.status_code, 200)
     self.assertTemplateUsed(page, "feature_detail.html")
 def test_checkout_invalid_order_form(self):
     user = User.objects.create_user('username', '*****@*****.**','password')
     feature = Feature(title="Test Feature", author=user, content="Test Content")
     feature.save()
     
     self.client.login(username='******', password='******')
     self.client.post('/cart/add/{0}'.format(feature.id), {'contribution': '50'}, follow=True)
     stripe_id = 'tok_chargeDeclined'
     page = self.client.post('/checkout/', {'phone_number':'123', 'street_address1':'my', 'street_address2':'address is', 'town_or_city':'kk', 'county':'ireland', 'country':'ireland','postcode':'eircode', 'credit_card_number': '4000400040004000','cvv':'111', 'expiry_month':'2','expiry_year':'2019', 'stripe_id':stripe_id} , follow=True)
     messages = list(get_messages(page.wsgi_request))
     self.assertEqual(str(messages[0]), 'We were unable to take a payment with that card!')
Example #15
0
 def generate_database_models(identifier='user1'):
     organisation = Organisation(name='ssg')
     organisation.save()
     project = Project(name='project1', organisation=organisation)
     project.save()
     environment = Environment(name='environment1', project=project)
     environment.save()
     feature = Feature(name="feature1", project=project)
     feature.save()
     identity = Identity(identifier=identifier, environment=environment)
     identity.save()
     return identity, project
Example #16
0
 def test_should_remove_identityfeature_when_delete(self):
     # Given
     client = self.set_up()
     organisation = Organisation.objects.get(name="test org")
     project = Project.objects.get(name="test project",
                                   organisation=organisation)
     feature_one = Feature(name='feature1', project=project)
     feature_one.save()
     feature_two = Feature(name='feature2', project=project)
     feature_two.save()
     environment = Environment.objects.get(name="test env")
     identity = Identity(identifier="test_identity",
                         environment=environment)
     identity.save()
     environment = Environment.objects.get(name="test env")
     identity_feature_one = FeatureState(feature=feature_one,
                                         identity=identity,
                                         enabled=False,
                                         environment=environment)
     identity_feature_one.save()
     identity_feature_two = FeatureState(feature=feature_two,
                                         identity=identity,
                                         enabled=True,
                                         environment=environment)
     identity_feature_two.save()
     # When
     client.delete(self.feature_states_detail_url %
                   (identity.environment.api_key, identity.identifier,
                    identity_feature_one.id),
                   content_type='application/json')
     # Then
     identity_features = FeatureState.objects.filter(identity=identity)
     self.assertEquals(identity_features.count(), 1)
     Helper.clean_up()
 def test_checkout_with_correct_card_details(self):
     user = User.objects.create_user('username', '*****@*****.**','password')
     feature = Feature(title="Test Feature", author=user, content="Test Content")
     feature.save()
     self.client.login(username='******', password='******')
     self.client.post('/cart/add/{0}'.format(feature.id), {'contribution': '50'}, follow=True)
     stripe_id = 'tok_visa'
     
     page = self.client.post('/checkout/', {'full_name':'name','phone_number':'123', 'street_address1':'my', 'street_address2':'address is', 'town_or_city':'kk', 'county':'ireland', 'country':'ireland','postcode':'eircode', 'credit_card_number': '4242424242424242','cvv':'111', 'expiry_month':'2','expiry_year':'2019', 'stripe_id':stripe_id}, follow=True)
     self.assertEqual(page.status_code, 200)
     messages = list(page.context['messages'])
     self.assertEqual(len(messages), 1)
     self.assertTemplateUsed('features/feature_detail.html')
     self.assertEqual(str(messages[0]), 'You have successfully contributed')
Example #18
0
def save_changes(feature_detail, form, priority=None):
    if form:
        #saving the data into the database
        feature_detail.title = form.title.data
        feature_detail.description = form.description.data
        feature_detail.client = form.client.data
        feature_detail.client_priority = form.client_priority.data
        feature_detail.target_date = form.target_date.data
        feature_detail.product_area = form.product_area.data
    if priority:
        new_feature = Feature.query.filter(Feature.client==feature_detail.client).first()
        feature_2 = Feature()
        feature_2.title = new_feature.title
        feature_2.description = new_feature.description
        feature_2.client = new_feature.client
        feature_2.client_priority = priority
        feature_2.target_date = new_feature.target_date
        feature_2.product_area = new_feature.product_area
        db.session.remove()
        db_session.delete(new_feature)
    
        db_session.add(feature_2)
        db_session.commit()
        db.session.remove()
        
    else:
        db_session.add(feature_detail)
        db_session.commit()
        db.session.remove()
    def test_checkout_payment_with_valid_credentials(self):
        feature = Feature(title="Test Feature", description="desc")
        feature.save()

        feature = Feature.objects.get(id=1)
        page = self.client.post(
            '/checkout/', {
                'credit_card_number': '4242424242424242',
                'cvv': '123',
                'expiry_month': '8',
                'expiry_year': '2025',
                'stripe_id': 'tok_visa',
            })

        self.assertTrue(page.status_code, 200)
Example #20
0
    def test_checkout_with_login_card_declined(self):
        client = Client()
        self.user = User.objects.create_user('john10', '*****@*****.**',
                                             'john10')
        self.user.save()
        self.client.login(username="******", password="******")

        item = Feature(name="Create a Test feature",
                       description="test description",
                       price=30.00,
                       author=self.user)
        item.save()

        self.client.post("/cart/add/{0}".format(item.id),
                         data={
                             'quantity': '6',
                             'author': self.user
                         },
                         follow=True)

        # assign the stripe publishable key to stripe_id
        #tok_chargeDeclined is from stripe website, will give a card declined error
        stripe_id = 'tok_chargeDeclined'

        page = self.client.post("/checkout/", {
            'full_name': 'john',
            'phone_number': '123456789111',
            'street_address1': 'home',
            'street_address2': 'and dry',
            'town_or_city': 'bay',
            'county': 'dublin',
            'country': 'ireland',
            'postcode': 'eircode',
            'credit_card_number': '4000000000000002',
            'cvv': '111',
            'expiry_month': '6',
            'expiry_year': '2020',
            'stripe_id': stripe_id
        },
                                follow=True)

        #check after post, that redirect was call '302'
        self.assertEqual(page.status_code, 200)
        self.assertTemplateUsed(page, "checkout.html")
        #check error message
        message = list(page.context.get('messages'))[0]
        self.assertEqual(message.tags, "error")
        self.assertEqual(message.message, "Your card was declined!")
Example #21
0
    def test_cannot_create_feature_with_same_case_insensitive_name(self):
        # unit test to validate validate_unique() method

        # Given
        feature_name = "Test Feature"
        Feature.objects.create(name=feature_name,
                               initial_value="test",
                               project=self.project)

        # When
        with self.assertRaises(ValidationError):
            feature_two = Feature(
                name=feature_name.lower(),
                initial_value="test",
                project=self.project,
            )
            feature_two.full_clean()
    def handle(self, *args, **options):
        with open(FILE_NAME, 'r') as features:
            features.next() # skip header
            reader = csv.reader(features, delimiter='\t')

            for row in reader:
                try:
                    teams = self.get_team_objects(filter(None, row[TEAMS].split(';')))

                    if row[FEATURE]:
                        feature = Feature(name=row[FEATURE], theme=row[THEME],
                                                    clarity_or_jira_id=row[ID], url=row[URL])
                    feature.save()
                    feature.teams.add(*teams)
                    feature.save()
                except Exception as e:
                    print('Error importing {} - {}'.format(row, e))
 def test_OrderLineItem_as_a_string(self):
     user = User.objects.create_user(username='******',
                                     password='******')
     feature = Feature(featureName="Test Feature", price=500, author=user)
     orderlineitem = OrderLineItem(user=user,
                                   product=feature,
                                   contribution='50')
     self.assertEqual("50 Test Feature @ 500", str(orderlineitem))
    def test_checkout_payment_with_invalid_credentials(self):
        feature = Feature(title="Test Feature", description="desc")
        feature.save()

        feature = Feature.objects.get(id=1)
        page = self.client.post(
            '/checkout/', {
                'credit_card_number': '4242424242424242',
                'cvv': '123',
                'expiry_month': '8',
                'expiry_year': '2025',
                'stripe_id': 'tok_chargeDeclined',
            })

        # https://stackoverflow.com/questions/2897609/how-can-i-unit-test-django-messages
        messages = list(get_messages(page.wsgi_request))
        self.assertEqual(str(messages[0]),
                         'We were unable to take a payment with that card!')
    def test_add_to_cart(self):
        """
        Test to see if an item is added to cart
        """
        admin = User(username="******")
        admin.save()
        feature = Feature(name="test",
                          description="test",
                          status="done",
                          upvotes=0,
                          views=0,
                          author=admin)
        feature.save()

        page = self.client.get("/cart/add{0}".format(feature.id))
        session = self.client.session
        cart = session['cart']

        self.assertEqual(cart, {'1': 1})
Example #26
0
    def test_creation(self):
        self.assertEqual(Feature.objects.count(), 0)
        
        f = Feature(
            title='Test title',
            description='Test description.',
            site=self.site,
        )
        f.save()

        self.assertEqual(Feature.objects.count(), 1)

        f2 = Feature.objects.create(
            title='Another feature',
            description='Test description again.',
            site=self.site,
        )
        
        self.assertEqual(Feature.objects.count(), 2)
Example #27
0
 def test_should_create_identityFeature_when_post(self):
     # Given
     client = self.set_up()
     environment = Environment.objects.get(name="test env")
     identity = Identity.objects.create(environment=environment,
                                        identifier="testidentity")
     project = Project.objects.get(name="test project")
     feature = Feature(name='feature1', project=project)
     feature.save()
     # When
     response = client.post(
         self.feature_states_url %
         (identity.environment.api_key, identity.identifier),
         data=self.post_template % (feature.id, True),
         content_type='application/json')
     # Then
     identityFeature = identity.identity_features
     self.assertEquals(response.status_code, status.HTTP_201_CREATED)
     self.assertEquals(identityFeature.count(), 1)
     Helper.clean_up()
    def test_cannot_create_feature_with_same_case_insensitive_name(self):
        # Given
        feature_name = 'Test Feature'

        feature_one = Feature(project=self.project, name=feature_name)
        feature_two = Feature(project=self.project, name=feature_name.lower())

        # When
        feature_one.save()

        # Then
        with pytest.raises(IntegrityError):
            feature_two.save()
    def test_adjust_cart(self):
        """
        This tests if when a feature is in a cart than when the adjust view method is run, it deletes the so called feature from the cart
        """
        admin = User(username="******")
        admin.save()
        feature = Feature(name="test",
                          description="test",
                          status="done",
                          upvotes=0,
                          views=0,
                          author=admin)
        feature.save()
        session = self.client.session
        page1 = self.client.get("/cart/add{0}".format(feature.id))

        page2 = self.client.get("/cart/adjust{0}".format(feature.id))
        session = self.client.session
        cart = session['cart']

        self.assertEqual(cart, {})
Example #30
0
 def test_add_to_cart(self):
     client = Client()
     self.user = User.objects.create_user('john10', '*****@*****.**',
                                          'john10')
     self.user.save()
     self.client.login(username="******", password="******")
     #create feature
     item = Feature(name="Create a Test featture",
                    description="test description",
                    price=30.00,
                    author=self.user)
     item.save()
     #add detials to cart
     response = self.client.post("/cart/add/{0}".format(item.id), {
         'quantity': 2,
         'author': self.user
     })
     #check after post, that redirect was call '302'
     self.assertEqual(response.status_code, 302)
     #redirect goes to /features/
     self.assertEqual(response.url, '/features/')
Example #31
0
def feature():
    form = FeatureForm(request.form)
    if request.method == 'POST' and form.validate():
        # save the New Feature
        feature = Feature()
        feature.title = form.title.data
        feature.description = form.description.data
        feature.client = form.client.data
        feature.client_priority = form.client_priority.data
        feature.target_date = form.target_date.data
        feature.product_area = form.product_area.data

        priority=form.client_priority.data
        #right here I call the save_duplicates function
        save_duplicates(feature, form, priority, True)
        flash('Feature Request Submitted successfully!')
        return redirect(url_for('feature'))
    return render_template('feature.html', title='Feature Request', form=form)
Example #32
0
    def handle(self, *args, **options):
        with open(FILE_NAME, 'r') as features:
            features.next()  # skip header
            reader = csv.reader(features, delimiter='\t')

            for row in reader:
                try:
                    teams = self.get_team_objects(
                        filter(None, row[TEAMS].split(';')))

                    if row[FEATURE]:
                        feature = Feature(name=row[FEATURE],
                                          theme=row[THEME],
                                          clarity_or_jira_id=row[ID],
                                          url=row[URL])
                    feature.save()
                    feature.teams.add(*teams)
                    feature.save()
                except Exception as e:
                    print('Error importing {} - {}'.format(row, e))