Esempio n. 1
0
        def test_not_author_cant_delete_recipe(self, api_client):
            new_recipe = RecipeFactory()
            random_user = UserFactory()
            api_client.force_authenticate(random_user)
            response = api_client.delete(new_recipe.get_absolute_url())

            assert response.status_code == 403
Esempio n. 2
0
        def test_author_can_update_own_recipe(self, api_client):
            new_recipe = RecipeFactory()
            api_client.force_authenticate(new_recipe.author)
            data = {'title': 'updated title'}
            response = api_client.patch(new_recipe.get_absolute_url(), data)

            assert response.status_code == 200
Esempio n. 3
0
class BasicPushTest(TestCase):
    def test_push(self):
        self.u = UserFactory()
        self.d = DeploymentFactory()
        self.setting = SettingFactory(deployment=self.d)
        self.recipe = RecipeFactory()
        self.shell_recipe = ShellRecipeFactory()
        self.stage = StageFactory(
            deployment=self.d,
            recipe=self.recipe)
        self.stage2 = StageFactory(
            deployment=self.d,
            recipe=self.shell_recipe,
            name="test stage 2",
        )
        push = self.d.new_push(self.u, "test push")
        # haven't run anything so it should be inprogress
        self.assertEquals(push.status, "inprogress")
        for s in self.d.stage_set.all():
            push.run_stage(s.id)
        # should have completed successfully
        self.assertEquals(push.status, "ok")
        # and let's make sure a setting variable has round-tripped
        ps = push.pushstage_set.get(stage=self.stage2)
        self.assertEquals(ps.stdout(), "TEST_BAR\n")
        self.assertEquals(ps.stderr(), "")

        self.assertEquals(self.d.most_recent_push(), push)
        self.assertEquals(self.d.status(), push.status)
        self.assertEquals(self.d.last_message(), push.comment)
        self.assertEquals(self.d.last_push_date(), push.start_time)

        self.assertEquals(push.get_absolute_url(),
                          "/push/%d/" % push.id)

        push.run_stage(self.stage.id, rollback_id=self.stage.id)

        for pstage in push.reverse_pushstages():
            self.assertEquals(pstage.setting('foo'), '')

    def test_recipe_absolute_url(self):
        self.recipe = RecipeFactory()
        self.assertEquals(
            self.recipe.get_absolute_url(),
            "/cookbook/%d/" % self.recipe.id)

    def test_stage_absolute_url(self):
        self.stage = StageFactory()
        self.assertEquals(
            self.stage.get_absolute_url(),
            "/stage/%d/" % self.stage.id)

    def test_stage_all_recipes(self):
        self.shell_recipe = ShellRecipeFactory()
        self.stage = StageFactory()
        self.stage2 = StageFactory(recipe=self.shell_recipe)

        self.assertEquals(
            [r.id for r in self.stage.all_recipes()],
            [self.shell_recipe.id])
Esempio n. 4
0
        def test_not_author_cant_update_recipe(self, api_client):
            new_recipe = RecipeFactory()
            random_user = UserFactory()
            api_client.force_authenticate(random_user)
            data = {'title': 'updated title'}
            response = api_client.patch(new_recipe.get_absolute_url(), data)

            assert response.status_code == 403
Esempio n. 5
0
        def test_guest_user_cant_update_recipe(self, api_client):
            first_recipe = RecipeFactory()
            data = {'title': 'updated title'}
            response = api_client.patch(first_recipe.get_absolute_url(), data)

            assert response.status_code == 401
Esempio n. 6
0
        def test_recipe_delete(self, api_client):
            new_recipe = RecipeFactory()
            response = api_client.delete(new_recipe.get_absolute_url())

            assert response.status_code == 401
Esempio n. 7
0
        def test_author_can_delete_own_recipe(self, api_client):
            new_recipe = RecipeFactory()
            api_client.force_authenticate(new_recipe.author)
            response = api_client.delete(new_recipe.get_absolute_url())

            assert response.status_code == 204
Esempio n. 8
0
        def test_recipe_detail_page_render(self, api_client):
            new_recipe = RecipeFactory()
            response = api_client.get(new_recipe.get_absolute_url())

            assert response.status_code == 200
Esempio n. 9
0
def test_get_absolute_url():
    new_recipe = RecipeFactory()

    assert new_recipe.get_absolute_url() == reverse(
        'recipes:detail', kwargs={"pk": new_recipe.id})